[med-svn] [gnumed-server] 01/07: Imported Upstream version 21.0

Andreas Tille tille at debian.org
Sat Mar 19 14:22:15 UTC 2016


This is an automated email from the git hooks/post-receive script.

tille pushed a commit to branch master
in repository gnumed-server.

commit e63f6d16da519e3500371f923652a898907015f7
Author: Andreas Tille <tille at debian.org>
Date:   Sat Mar 19 13:42:22 2016 +0100

    Imported Upstream version 21.0
---
 server/bootstrap/bootstrap-latest.bat              |     6 +-
 server/bootstrap/bootstrap-latest.conf             |     1 +
 server/bootstrap/bootstrap-latest.sh               |     6 +-
 server/bootstrap/bootstrap_gm_db_system.py         |    54 +-
 server/bootstrap/fixup_db-v20.conf                 |     1 +
 .../{fixup_db-v20.conf => fixup_db-v21.conf}       |    28 +-
 server/bootstrap/gmAuditSchemaGenerator.py         |   331 +-
 server/bootstrap/gmDBPruningDMLGenerator.py        |     8 +-
 server/bootstrap/update_db-v19_v20.conf            |     1 +
 server/bootstrap/update_db-v20_v21.conf            |   326 +
 server/doc/gm-backup.8                             |    30 +
 server/doc/gm-restore_database_from_archive.8      |    35 +
 .../doc/schema/gnumed-entire_schema-no_audit.dot   |   285 +-
 server/doc/schema/gnumed-entire_schema.html        | 68329 ++++++++++++-------
 server/etc/gnumed/gnumed-backup.conf.example       |     2 +-
 ...ed-restore.conf.example => gnumed-restore.conf} |    11 +-
 server/gm-adjust_db_settings.sh                    |    25 +-
 server/{gm-backup_database.sh => gm-backup.sh}     |    32 +-
 server/gm-backup_data.sh                           |     2 +-
 server/gm-backup_database.sh                       |     4 +-
 server/gm-fingerprint_db.py                        |    27 +-
 server/gm-restore_database.sh                      |     2 +
 ...base.sh => gm-restore_database_from_archive.sh} |   130 +-
 server/pycommon/gmBackendListener.py               |    79 +-
 server/pycommon/gmBorg.py                          |    27 +-
 server/pycommon/gmBusinessDBObject.py              |    94 +-
 server/pycommon/gmCfg.py                           |    12 +-
 server/pycommon/gmCfg2.py                          |    66 +-
 server/pycommon/gmConfigCommon.py                  |   872 -
 server/pycommon/gmDateTime.py                      |   191 +-
 server/pycommon/gmDispatcher.py                    |    67 +-
 server/pycommon/gmExceptions.py                    |    53 +-
 server/pycommon/gmGuiBroker.py                     |   146 +-
 server/pycommon/gmHooks.py                         |    15 +-
 server/pycommon/gmI18N.py                          |    43 +-
 server/pycommon/gmLog2.py                          |     9 +-
 server/pycommon/gmLoginInfo.py                     |    11 +-
 server/pycommon/gmMatchProvider.py                 |    12 +-
 server/pycommon/gmMimeLib.py                       |   115 +-
 server/pycommon/gmMimeMagic.py                     |    35 +-
 server/pycommon/gmNetworkTools.py                  |    21 +-
 server/pycommon/gmNull.py                          |    15 +-
 server/pycommon/gmPG2.py                           |   344 +-
 server/pycommon/gmPrinting.py                      |    36 +-
 server/pycommon/gmPsql.py                          |    78 +-
 server/pycommon/gmScanBackend.py                   |    19 +-
 server/pycommon/gmScriptingListener.py             |     2 +-
 server/pycommon/gmShellAPI.py                      |    23 +-
 server/pycommon/gmTools.py                         |   751 +-
 .../sql/country.specific/au/gmDemographics.au.sql  |    65 -
 .../country.specific/ca/gmDemographics-Data.ca.sql |    33 +-
 server/sql/country.specific/de/Impfplan-FSME.sql   |    27 +-
 .../sql/country.specific/de/Impfplan-Influenza.sql |    45 -
 .../sql/country.specific/de/Impfplan-Prevenar.sql  |    44 +-
 server/sql/country.specific/de/Impfplan-Typhus.sql |    12 -
 server/sql/country.specific/de/Impfstoffe.sql      |   105 +-
 server/sql/country.specific/de/PLZ.sql             |    84 +-
 .../sql/country.specific/de/STIKO-Impfkalender.sql |    88 +-
 .../de/amis-import_data_template.sql               |    26 -
 server/sql/country.specific/de/gmATC.sql           |    69 +-
 .../sql/country.specific/de/gmDemographics.de.sql  |    56 +-
 server/sql/country.specific/de/gmDiagnosen.sql     |    44 +-
 server/sql/country.specific/de/gmUebersetzung.sql  |    83 +-
 server/sql/country.specific/de/gmVornamen.sql      |   126 +-
 .../country.specific/es/gmDemographics-Data.es.sql |    62 +-
 server/sql/gmClinicalData.sql                      |   160 +-
 server/sql/gmCountryZones.sql                      |    33 +-
 server/sql/test-data/test_data-James_Kirk.sql      |   287 -
 .../test_data-Kirk_hospital_stay-dynamic.sql       |    21 -
 server/sql/v14-v15/python/v15-import-atc.py        |     5 +-
 .../v19-v20/dynamic/v20-release_notes-dynamic.sql  |    14 +-
 .../v19-v20/fixups/v20-clin-procedure-fixup.sql    |    23 +
 server/sql/v20-v21/data/v21-Begleitbrief.tex       |   176 +
 .../v21-Medikationsplan_AMTS-2.0-nicht_konform.tex |   383 +
 .../v20-v21/data/v21-Medikationsplan_AMTS-2.0.tex  |   381 +
 .../v20-v21/data/v21-aktuelle-Medikationsliste.tex |   102 +
 .../sql/v20-v21/data/v21-gm2gpl-plot_one_test.gpl  |    59 +
 .../sql/v20-v21/data/v21-gm2gpl-plot_two_tests.gpl |    73 +
 server/sql/v20-v21/dynamic/v21-HIT_risk.sql        |    65 +
 .../sql/v20-v21/dynamic/v21-audit-constraints.sql  |   117 +
 .../v20-v21/dynamic/v21-blobs-doc_med-dynamic.sql  |    92 +
 .../sql/v20-v21/dynamic/v21-blobs-v_doc_desc.sql   |    32 +
 .../dynamic/v21-blobs-v_doc_med_journal.sql        |    93 +
 .../v20-v21/dynamic/v21-blobs-v_latest_mugshot.sql |    52 +
 .../dynamic/v21-blobs-v_obj4doc_no_data.sql        |    77 +
 .../dynamic/v21-blobs-v_reviewed_doc_objects.sql   |    45 +
 .../dynamic/v21-cfg-cfg_str_array-dynamic.sql      |    52 +
 .../v20-v21/dynamic/v21-clin-procedure-dynamic.sql |    54 +
 .../sql/v20-v21/dynamic/v21-clin-sanity_checks.sql |   122 +
 .../dynamic/v21-clin-substance_intake-dynamic.sql  |   337 +
 .../sql/v20-v21/dynamic/v21-clin-v_edc_journal.sql |    90 +
 .../sql/v20-v21/dynamic/v21-clin-v_emr_journal.sql |    94 +
 .../v20-v21/dynamic/v21-clin-v_export_items.sql    |    75 +
 .../dynamic/v21-clin-v_external_care_journal.sql   |    90 +
 .../dynamic/v21-clin-v_family_history_journal.sql  |   117 +
 .../dynamic/v21-clin-v_health_issues_journal.sql   |   123 +
 .../dynamic/v21-clin-v_hospital_stays_journal.sql  |   352 +
 .../dynamic/v21-clin-v_narrative4search.sql        |   424 +
 .../dynamic/v21-clin-v_pat_allergies_journal.sql   |    90 +
 .../v21-clin-v_pat_allergy_state_journal.sql       |   191 +
 .../dynamic/v21-clin-v_pat_encounters_journal.sql  |   122 +
 .../dynamic/v21-clin-v_pat_episodes_journal.sql    |   107 +
 .../dynamic/v21-clin-v_pat_narrative_journal.sql   |    87 +
 .../dynamic/v21-clin-v_procedures_journal.sql      |   232 +
 .../dynamic/v21-clin-v_reminders_journal.sql       |   323 +
 ...21-clin-v_substance_intake4narrative_search.sql |    46 +
 .../v21-clin-v_substance_intake_journal.sql        |   258 +
 .../dynamic/v21-clin-v_substance_intakes.sql       |   419 +
 .../dynamic/v21-clin-v_suppressed_hints.sql        |    50 +
 .../v21-clin-v_suppressed_hints_journal.sql        |    98 +
 .../dynamic/v21-clin-v_test_results_journal.sql    |   112 +
 .../dynamic/v21-clin-v_vaccinations_journal.sql    |   116 +
 .../v20-v21/dynamic/v21-clin-v_waiting_list.sql    |    72 +
 .../dynamic/v21-clin-vaccination-dynamic.sql       |   196 +
 .../dynamic/v21-dem-external_id-dynamic.sql        |    15 +
 .../v20-v21/dynamic/v21-dem-identity-dynamic.sql   |   146 +
 .../sql/v20-v21/dynamic/v21-dem-org-trgm_idx.sql   |    20 +
 .../sql/v20-v21/dynamic/v21-dem-person_views.sql   |   135 +
 .../sql/v20-v21/dynamic/v21-dem-region-dynamic.sql |   634 +
 .../sql/v20-v21/dynamic/v21-dem-staff-dynamic.sql  |   141 +
 .../sql/v20-v21/dynamic/v21-dem-v_basic_person.sql |    27 +
 .../v20-v21/dynamic/v21-dem-v_pat_addresses.sql    |    76 +
 .../dynamic/v21-gm-db-translations-de_DE.sql       |   434 +
 server/sql/v20-v21/dynamic/v21-gm-md5.sql          |    57 +
 .../dynamic/v21-ref-paperwork_templates.sql        |   138 +
 .../sql/v20-v21/dynamic/v21-ref-v_auto_hints.sql   |   405 +
 .../v20-v21/dynamic/v21-release_notes-dynamic.sql  |   114 +
 .../sql/v20-v21/gm_db-gnumed_v21-fingerprint.txt   |  1789 +
 .../v20-v21/python/v21-import-form-templates.py    |    64 +
 .../sql/v20-v21/python/v21-import-plot-scripts.py  |    44 +
 .../v20-v21/static/v21-blobs-doc_med-static.sql    |    19 +
 .../static/v21-clin-substance_intake-static.sql    |    21 +
 .../sql/v20-v21/static/v21-dem-identity-static.sql |    30 +
 .../sql/v20-v21/static/v21-dem-region-static.sql   |    25 +
 .../v20-v21/static/v21-ref-auto_hint-static.sql    |    19 +
 .../v20-v21/superuser/v21-reinstall-pg_trgm.sql    |    20 +
 136 files changed, 57636 insertions(+), 27257 deletions(-)

diff --git a/server/bootstrap/bootstrap-latest.bat b/server/bootstrap/bootstrap-latest.bat
index bc0655f..d2e0d50 100644
--- a/server/bootstrap/bootstrap-latest.bat
+++ b/server/bootstrap/bootstrap-latest.bat
@@ -5,9 +5,9 @@ cd /d %~dp0
 REM command line options:
 REM quiet
 
-SET VER=20
-SET PREV_VER=19
-SET LASTVERSIONSTODROP=18
+SET VER=21
+SET PREV_VER=20
+SET LASTVERSIONSTODROP=19
 SET QUIET=%1
 
 SET PYTHONPATH="%PYTHONPATH%;../../"
diff --git a/server/bootstrap/bootstrap-latest.conf b/server/bootstrap/bootstrap-latest.conf
index 799bdb7..bb67fd8 100644
--- a/server/bootstrap/bootstrap-latest.conf
+++ b/server/bootstrap/bootstrap-latest.conf
@@ -37,4 +37,5 @@ update_db-v16_v17.conf
 update_db-v17_v18.conf
 update_db-v18_v19.conf
 update_db-v19_v20.conf
+update_db-v20_v21.conf
 $config files$
diff --git a/server/bootstrap/bootstrap-latest.sh b/server/bootstrap/bootstrap-latest.sh
index 3c621b0..17dead7 100755
--- a/server/bootstrap/bootstrap-latest.sh
+++ b/server/bootstrap/bootstrap-latest.sh
@@ -4,9 +4,9 @@
 # - command line options:
 #   - "quiet"
 
-VERSIONS_TO_DROP="2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18"
-PREV_VER="19"
-VER="20"
+VERSIONS_TO_DROP="2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19"
+PREV_VER="20"
+VER="21"
 QUIET="$1"
 
 
diff --git a/server/bootstrap/bootstrap_gm_db_system.py b/server/bootstrap/bootstrap_gm_db_system.py
index 263165c..339e4ed 100755
--- a/server/bootstrap/bootstrap_gm_db_system.py
+++ b/server/bootstrap/bootstrap_gm_db_system.py
@@ -36,7 +36,9 @@ __author__ = "Karsten.Hilbert at gmx.net"
 __license__ = "GPL v2 or later"
 
 # standard library
-import sys, string, os.path, fileinput, os, time, getpass, glob, re as regex, tempfile, logging
+import sys, string, os.path, fileinput, os, time, getpass, glob, re as regex, tempfile
+import io
+import logging
 
 
 # adjust Python path
@@ -711,6 +713,16 @@ class database:
 		except:
 			_log.exception('PostgreSQL version < 9.3 does not support <ignore_checksum_failure>')
 		curs.close()
+
+		# we want to track commit timestamps if available
+		# remove exception handler when 9.5 is default
+		curs = self.conn.cursor()
+		try:
+			curs.execute("alter database %s set track_commit_timestamp to on" % self.name)
+		except:
+			_log.exception('PostgreSQL version < 9.5 does not support <track_commit_timestamp> OR <track_commit_timestamp> cannot be set at runtime')
+		curs.close()
+
 		self.conn.commit()
 
 		curs = self.conn.cursor()
@@ -941,9 +953,8 @@ class database:
 		_log.info('hba file: %s', hba_file)
 
 		try:
-			f = open(hba_file, 'r')
-			f.close()
-		except StandardError:
+			f = io.open(hba_file, mode = 'rt').close()
+		except Exception:
 			_log.exception('cannot check pg_hba.conf for authentication information - not readable')
 			return
 
@@ -1058,22 +1069,36 @@ class database:
 
 	#--------------------------------------------------------------
 	def reindex_all(self):
-		print_msg("==> reindexing target database ...")
-		_log.info('REINDEXing cloned target database so upgrade does not fail because of a broken index')
+
+		print_msg("==> reindexing target database (can take a while) ...")
+		_log.info('REINDEXing cloned target database so upgrade does not fail in case of a broken index')
+		_log.info('this may potentially take "quite a long time" depending on how much data there is in the database')
+		_log.info('you may want to monitor the PostgreSQL log for signs of progress')
+
 		old_iso = self.conn.isolation_level
 		self.conn.set_isolation_level(0)
 		curs = self.conn.cursor()
-		cmd = 'REINDEX DATABASE %s' % self.name
+		cmd = 'REINDEX (VERBOSE) DATABASE %s' % self.name
 		try:
 			curs.execute(cmd)
 		except:
 			_log.exception(">>>[%s]<<< failed" % cmd)
 			curs.close()
-			self.conn.set_isolation_level(old_iso)
-			return False
+			# re-attempt w/o VERBOSE
+			_log.info('attempting REINDEXing without VERBOSE')
+			curs = self.conn.cursor()
+			cmd = 'REINDEX DATABASE %s' % self.name
+			try:
+				curs.execute(cmd)
+			except:
+				_log.exception(">>>[%s]<<< failed" % cmd)
+				curs.close()
+				self.conn.set_isolation_level(old_iso)
+				return False
 		curs.close()
 		self.conn.set_isolation_level(old_iso)
 		return True
+
 	#--------------------------------------------------------------
 	def transfer_users(self):
 		print_msg("==> transferring users ...")
@@ -1103,6 +1128,7 @@ class database:
 		_log.error('error transferring user from [%s] to [%s]' % (self.template_db, self.name))
 		print_msg("    ... failed")
 		return False
+
 	#--------------------------------------------------------------
 	def bootstrap_auditing(self):
 		print_msg("==> setting up auditing ...")
@@ -1139,10 +1165,10 @@ class database:
 			return None
 		# write schema to file
 		tmpfile = os.path.join(tempfile.gettempdir(), 'audit-trail-schema.sql')
-		file = open(tmpfile, 'wb')
+		f = io.open(tmpfile, mode = 'wt', encoding = 'utf8')
 		for line in audit_schema:
-			file.write("%s;\n" % line)
-		file.close()
+			f.write(u'%s;\n' % line)
+		f.close()
 
 		# import auditing schema
 		psql = gmPsql.Psql(self.conn)
@@ -1155,7 +1181,7 @@ class database:
 
 		try:
 			os.remove(tmpfile)
-		except StandardError:
+		except Exception:
 			_log.exception('cannot remove audit trail schema file [%s]' % tmpfile)
 		return True
 
@@ -1669,7 +1695,7 @@ if __name__ == "__main__":
 
 	try:
 		main()
-	except StandardError:
+	except Exception:
 		for c in conn_ref_count:
 			if c.closed == 0:
 				print 'closing open connection from:', c.cookie
diff --git a/server/bootstrap/fixup_db-v20.conf b/server/bootstrap/fixup_db-v20.conf
index 4092da3..c03380f 100644
--- a/server/bootstrap/fixup_db-v20.conf
+++ b/server/bootstrap/fixup_db-v20.conf
@@ -30,6 +30,7 @@ schema = $schema$
 ../dynamic/v20-release_notes-dynamic.sql
 v20-clin-substance_intake-fixup.sql
 v20-dem-org-idx-fixup.sql
+v20-clin-procedure-fixup.sql
 $schema$
 
 #----------------------------------
diff --git a/server/bootstrap/fixup_db-v20.conf b/server/bootstrap/fixup_db-v21.conf
similarity index 76%
copy from server/bootstrap/fixup_db-v20.conf
copy to server/bootstrap/fixup_db-v21.conf
index 4092da3..443e2fb 100644
--- a/server/bootstrap/fixup_db-v20.conf
+++ b/server/bootstrap/fixup_db-v21.conf
@@ -18,27 +18,25 @@ appropriate to the version of the database.
 $description$
 
 bundles = $bundles$
-v20-fixups
+v21-fixups
 $bundles$
 
 #----------------------------------
-[bundle v20-fixups]
-database alias = gnumed_v20
-minimum postgresql version = 9.1
-schema base directory = ../sql/v19-v20/fixups/
+[bundle v21-fixups]
+database alias = gnumed_v21
+minimum postgresql version = 9.2
+schema base directory = ../sql/v20-v21/fixups/
 schema = $schema$
-../dynamic/v20-release_notes-dynamic.sql
-v20-clin-substance_intake-fixup.sql
-v20-dem-org-idx-fixup.sql
+../dynamic/v21-release_notes-dynamic.sql
 $schema$
 
 #----------------------------------
-[database gnumed_v20]
-name = gnumed_v20
+[database gnumed_v21]
+name = gnumed_v21
 override name by = GM_CORE_DB
 drop target database = 0
 use existing target database = 1
-target version = v20
+target version = v21
 transfer users = 0
 
 template database = template1
@@ -47,20 +45,18 @@ audit disable = 1
 audit trail parent table = audit.audit_trail
 audit trail table prefix = log_
 audit fields table = audit.audit_fields
-schema base directory = ../sql/v19-v20/
+schema base directory = ../sql/v20-v21/
 schema = $schema$
 $schema$
 
 superuser schema = $superuser schema$
-superuser/v20-install-pg_trgm.sql
 $superuser schema$
 
 upgrade plausibility checks = $upgrade plausibility checks$
 $upgrade plausibility checks$
 
-script base directory = ../sql/v19-v20/python/
+script base directory = ../sql/v20-v21/python/
 data import scripts = $data import scripts$
-v20-import-form-templates.py
 $data import scripts$
 
 #----------------------------------
@@ -69,7 +65,7 @@ name =
 port = 5432
 template database = template1
 super user alias = postgres
-schema base directory = ../sql/v19-v20/
+schema base directory = ../sql/v20-v21/
 schema = $schema$
 $schema$
 
diff --git a/server/bootstrap/gmAuditSchemaGenerator.py b/server/bootstrap/gmAuditSchemaGenerator.py
index 9902b19..36eb3d0 100644
--- a/server/bootstrap/gmAuditSchemaGenerator.py
+++ b/server/bootstrap/gmAuditSchemaGenerator.py
@@ -20,7 +20,7 @@ audited table.
 __author__ = "Horst Herb, Karsten.Hilbert at gmx.net"
 __license__ = "GPL v2 or later"		# (details at http://www.gnu.org)
 
-import sys, os.path, string, logging
+import sys, os.path, string, logging, io
 
 
 from Gnumed.pycommon import gmPG2
@@ -28,14 +28,11 @@ from Gnumed.pycommon import gmPG2
 
 _log = logging.getLogger('gm.bootstrapper')
 
-# the audit trail tables start with this prefix
-audit_trail_table_prefix = u'log_'
-# and inherit from this table
-audit_trail_parent_table = u'audit_trail'
-# audited tables inherit these fields
-audit_fields_table = u'audit_fields'
-# audit stuff lives in this schema
-audit_schema = u'audit'
+
+LOG_TABLE_PREFIX = u'log_'						# the audit trail tables start with this prefix
+AUDIT_TRAIL_PARENT_TABLE = u'audit_trail'		# and inherit from this table
+AUDIT_FIELDS_TABLE = u'audit_fields'			# audited tables inherit these fields
+AUDIT_SCHEMA = u'audit'							# audit stuff lives in this schema
 
 #==================================================================
 # SQL statements for auditing setup script
@@ -44,16 +41,40 @@ audit_schema = u'audit'
 # reasonably sure they are executed last
 
 # insert
-tmpl_insert_trigger = """CREATE TRIGGER zt_ins_%s
-	BEFORE INSERT ON %s.%s
-	FOR EACH ROW EXECUTE PROCEDURE audit.ft_ins_%s()"""
+SQL_TEMPLATE_INSERT = u"""DROP FUNCTION IF EXISTS audit.ft_ins_%(src_tbl)s() cascade;
+
+CREATE FUNCTION audit.ft_ins_%(src_tbl)s()
+	RETURNS trigger
+	LANGUAGE 'plpgsql'
+	SECURITY DEFINER
+	AS '
+DECLARE
+	_is_allowed_inserter boolean;
+BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			''INSERT: gm.account_is_dbowner_or_staff(NAME): <%%> is neither database owner, nor <postgres>, nor on staff'', SESSION_USER
+			USING ERRCODE = ''integrity_constraint_violation''
+		;
+		return NEW;
+	END IF;
+
+	NEW.row_version := 0;
+	NEW.modified_when := CURRENT_TIMESTAMP;
+	NEW.modified_by := SESSION_USER;
+	return NEW;
+END;';
 
-tmpl_insert_function = """
-\unset ON_ERROR_STOP
-drop function audit.ft_ins_%s() cascade;
-\set ON_ERROR_STOP 1
+CREATE TRIGGER zt_ins_%(src_tbl)s
+	BEFORE INSERT ON %(src_schema)s.%(src_tbl)s
+	FOR EACH ROW EXECUTE PROCEDURE audit.ft_ins_%(src_tbl)s();
+"""
+
+SQL_TEMPLATE_INSERT_NO_INSERTER_CHECK = u"""DROP FUNCTION IF EXISTS audit.ft_ins_%(src_tbl)s() cascade;
 
-create FUNCTION audit.ft_ins_%s()
+CREATE FUNCTION audit.ft_ins_%(src_tbl)s()
 	RETURNS trigger
 	LANGUAGE 'plpgsql'
 	SECURITY DEFINER
@@ -63,19 +84,55 @@ BEGIN
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	return NEW;
-END;'"""
+END;';
+
+CREATE TRIGGER zt_ins_%(src_tbl)s
+	BEFORE INSERT ON %(src_schema)s.%(src_tbl)s
+	FOR EACH ROW EXECUTE PROCEDURE audit.ft_ins_%(src_tbl)s();
+"""
 
 # update
-tmpl_update_trigger = """CREATE TRIGGER zt_upd_%s
-	BEFORE UPDATE ON %s.%s
-	FOR EACH ROW EXECUTE PROCEDURE audit.ft_upd_%s()"""
+SQL_TEMPLATE_UPDATE = u"""DROP FUNCTION IF EXISTS audit.ft_upd_%(src_tbl)s() cascade;
 
-tmpl_update_function = """
-\unset ON_ERROR_STOP
-drop function audit.ft_upd_%s() cascade;
-\set ON_ERROR_STOP 1
+CREATE FUNCTION audit.ft_upd_%(src_tbl)s()
+	RETURNS trigger
+	LANGUAGE 'plpgsql'
+	SECURITY DEFINER
+	AS '
+DECLARE
+	_is_allowed_updater boolean;
+BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			''UPDATE: gm.account_is_dbowner_or_staff(NAME): <%%> is neither database owner, nor <postgres>, nor on staff'', SESSION_USER
+			USING ERRCODE = ''integrity_constraint_violation''
+		;
+		return NEW;
+	END IF;
 
-create FUNCTION audit.ft_upd_%s()
+	NEW.row_version := OLD.row_version + 1;
+	NEW.modified_when := CURRENT_TIMESTAMP;
+	NEW.modified_by := SESSION_USER;
+	INSERT INTO audit.%(log_tbl)s (
+		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
+		%(cols_clause)s
+	) VALUES (
+		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
+		%(vals_clause)s
+	);
+	return NEW;
+END;';
+
+CREATE TRIGGER zt_upd_%(src_tbl)s
+	BEFORE UPDATE ON %(src_schema)s.%(src_tbl)s
+	FOR EACH ROW EXECUTE PROCEDURE audit.ft_upd_%(src_tbl)s();
+"""
+
+SQL_TEMPLATE_UPDATE_NO_UPDATER_CHECK = u"""DROP FUNCTION IF EXISTS audit.ft_upd_%(src_tbl)s() cascade;
+
+CREATE FUNCTION audit.ft_upd_%(src_tbl)s()
 	RETURNS trigger
 	LANGUAGE 'plpgsql'
 	SECURITY DEFINER
@@ -84,58 +141,117 @@ BEGIN
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
-	INSERT INTO audit.%s (
+	INSERT INTO audit.%(log_tbl)s (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		%s
+		%(cols_clause)s
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		%s
+		%(vals_clause)s
 	);
 	return NEW;
-END;'"""
+END;';
+
+CREATE TRIGGER zt_upd_%(src_tbl)s
+	BEFORE UPDATE ON %(src_schema)s.%(src_tbl)s
+	FOR EACH ROW EXECUTE PROCEDURE audit.ft_upd_%(src_tbl)s();
+"""
 
 # delete
-tmpl_delete_trigger = """
-CREATE TRIGGER zt_del_%s
-	BEFORE DELETE ON %s.%s
-	FOR EACH ROW EXECUTE PROCEDURE audit.ft_del_%s()"""
+SQL_TEMPLATE_DELETE = u"""DROP FUNCTION IF EXISTS audit.ft_del_%(src_tbl)s() cascade;
+
+CREATE FUNCTION audit.ft_del_%(src_tbl)s()
+	RETURNS trigger
+	LANGUAGE 'plpgsql'
+	SECURITY DEFINER
+	AS '
+DECLARE
+	_is_allowed_deleter boolean;
+BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			''DELETE: gm.account_is_dbowner_or_staff(NAME): <%%> is neither database owner, nor <postgres>, nor on staff'', SESSION_USER
+			USING ERRCODE = ''integrity_constraint_violation''
+		;
+		return OLD;
+	END IF;
+
+	INSERT INTO audit.%(log_tbl)s (
+		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
+		%(cols_clause)s
+	) VALUES (
+		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
+		%(vals_clause)s
+	);
+	return OLD;
+END;';
 
-tmpl_delete_function = """
-\unset ON_ERROR_STOP
-drop function audit.ft_del_%s() cascade;
-\set ON_ERROR_STOP 1
+CREATE TRIGGER zt_del_%(src_tbl)s
+	BEFORE DELETE ON %(src_schema)s.%(src_tbl)s
+	FOR EACH ROW EXECUTE PROCEDURE audit.ft_del_%(src_tbl)s();
+"""
+
+SQL_TEMPLATE_DELETE_NO_DELETER_CHECK = u"""DROP FUNCTION IF EXISTS audit.ft_del_%(src_tbl)s() cascade;
 
-create FUNCTION audit.ft_del_%s()
+CREATE FUNCTION audit.ft_del_%(src_tbl)s()
 	RETURNS trigger
 	LANGUAGE 'plpgsql'
 	SECURITY DEFINER
 	AS '
 BEGIN
-	INSERT INTO audit.%s (
+	INSERT INTO audit.%(log_tbl)s (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		%s
+		%(cols_clause)s
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		%s
+		%(vals_clause)s
 	);
 	return OLD;
-END;'"""
+END;';
 
-tmpl_create_audit_trail_table = """
-create table audit.%s (
-%s
-) inherits (%s);
+CREATE TRIGGER zt_del_%(src_tbl)s
+	BEFORE DELETE ON %(src_schema)s.%(src_tbl)s
+	FOR EACH ROW EXECUTE PROCEDURE audit.ft_del_%(src_tbl)s();
+"""
 
-comment on column audit.%s.orig_version is
+# we cannot do this because NOT VALID only applies to the time when
+# we add the constraint, the FK would still be enforced during later
+# INSERTs/UPDATEs
+#SQL_TEMPLATE_FK_MODIFIED_BY = u"""ALTER TABLE %(src_schema)s.%(src_tbl)s
+#	DROP CONSTRAINT IF EXISTS fk_%(src_schema)s_%(src_tbl)s_fk_modified_by CASCADE;
+#
+#-- this is set NOT VALID because it only serves to tell pg_dump
+#-- to dump dem.staff before other tables such that we do not run
+#-- into trouble with checking gm.is_dbowner_or_staff(SESSION_USER)
+#ALTER TABLE %(src_schema)s.%(src_tbl)s
+#	ADD CONSTRAINT fk_%(src_schema)s_%(src_tbl)s_fk_modified_by
+#		FOREIGN KEY (modified_by)
+#		REFERENCES dem.staff(db_user)
+#		ON UPDATE RESTRICT
+#		ON DELETE RESTRICT
+#	NOT VALID;"""
+#
+#SQL_TEMPLATE_DEM_STAFF_FK = u"""
+#ALTER TABLE dem.staff
+#	DROP CONSTRAINT IF EXISTS fk_dem_staff_fk_modified_by CASCADE;
+#"""
+
+SQL_TEMPLATE_CREATE_AUDIT_TRAIL_TABLE = u"""
+create table %(log_schema)s.%(log_tbl)s (
+	%(log_cols)s
+) inherits (%(log_schema)s.%(log_base_tbl)s);
+
+COMMENT ON COLUMN %(log_schema)s.%(log_tbl)s.orig_version is
 	'the .row_version in the original row before the audited action took place, should be equal to .row_version';
 
-comment on column audit.%s.orig_when is
+COMMENT ON COLUMN %(log_schema)s.%(log_tbl)s.orig_when is
 	'the .modified_when in the original row before the audited action took place, should be equal to .modified_when';
 
-comment on column audit.%s.orig_by is
+COMMENT ON COLUMN %(log_schema)s.%(log_tbl)s.orig_by is
 	'the .modified_by in the original row before the audited action took place, should be equal to .modified_by';
 
-comment on column audit.%s.orig_tableoid is
+COMMENT ON COLUMN %(log_schema)s.%(log_tbl)s.orig_tableoid is
 	'the TG_RELID when the audit trigger was run';
 """
 
@@ -143,15 +259,15 @@ comment on column audit.%s.orig_tableoid is
 
 #------------------------------------------------------------------
 #------------------------------------------------------------------
-def audit_trail_table_ddl(aCursor=None, schema='audit', table2audit=None):
+def audit_trail_table_ddl(aCursor=None, schema=None, table2audit=None):
 
-	audit_trail_table = '%s%s' % (audit_trail_table_prefix, table2audit)
+	audit_trail_table = '%s%s' % (LOG_TABLE_PREFIX, table2audit)
 
 	# which columns to potentially audit
 	cols2potentially_audit = gmPG2.get_col_defs(link_obj = aCursor, schema = schema, table = table2audit)
 
 	# which to skip
-	cols2skip = gmPG2.get_col_names(link_obj = aCursor, schema = audit_schema, table = audit_fields_table)
+	cols2skip = gmPG2.get_col_names(link_obj = aCursor, schema = AUDIT_SCHEMA, table = AUDIT_FIELDS_TABLE)
 
 	# which ones to really audit
 	cols2really_audit = []
@@ -161,7 +277,7 @@ def audit_trail_table_ddl(aCursor=None, schema='audit', table2audit=None):
 		cols2really_audit.append("\t%s %s" % (col, cols2potentially_audit[1][col]))
 
 	# does the audit trail target table exist ?
-	exists = gmPG2.table_exists(aCursor, 'audit', audit_trail_table)
+	exists = gmPG2.table_exists(aCursor, AUDIT_SCHEMA, audit_trail_table)
 	if exists is None:
 		_log.error('cannot check existence of table [audit.%s]' % audit_trail_table)
 		return None
@@ -169,7 +285,7 @@ def audit_trail_table_ddl(aCursor=None, schema='audit', table2audit=None):
 	if exists:
 		_log.info('audit trail table [audit.%s] already exists' % audit_trail_table)
 		# sanity check table structure
-		currently_audited_cols = gmPG2.get_col_defs(link_obj = aCursor, schema = u'audit', table = audit_trail_table)
+		currently_audited_cols = gmPG2.get_col_defs(link_obj = aCursor, schema = AUDIT_SCHEMA, table = audit_trail_table)
 		currently_audited_cols = [ '\t%s %s' % (c, currently_audited_cols[1][c]) for c in currently_audited_cols[0] ]
 		for col in cols2really_audit:
 			try:
@@ -178,7 +294,7 @@ def audit_trail_table_ddl(aCursor=None, schema='audit', table2audit=None):
 				_log.error('table structure incompatible: column ".%s" not found in audit table' % col.strip())
 				_log.error('%s.%s:' % (schema, table2audit))
 				_log.error('%s' % ','.join(cols2really_audit))
-				_log.error('%s.%s:' % (audit_schema, audit_trail_table))
+				_log.error('%s.%s:' % (AUDIT_SCHEMA, audit_trail_table))
 				_log.error('%s' % ','.join(currently_audited_cols))
 				return None
 		return []
@@ -187,82 +303,84 @@ def audit_trail_table_ddl(aCursor=None, schema='audit', table2audit=None):
 	_log.info('no audit trail table found for [%s.%s]' % (schema, table2audit))
 	_log.info('creating audit trail table [audit.%s]' % audit_trail_table)
 
-	# create audit table DDL
-	attributes = ',\n'.join(cols2really_audit)
-	table_def = tmpl_create_audit_trail_table % (
-		audit_trail_table,
-		attributes,
-		audit_trail_parent_table,			# FIXME: use audit_schema
-		audit_trail_table,
-		audit_trail_table,
-		audit_trail_table,
-		audit_trail_table
-	)
-	return [table_def, '']
+	args = {
+		'log_schema': AUDIT_SCHEMA,
+		'log_base_tbl': AUDIT_TRAIL_PARENT_TABLE,
+		'log_tbl': audit_trail_table,
+		'log_cols': u',\n	'.join(cols2really_audit)
+	}
+	return [SQL_TEMPLATE_CREATE_AUDIT_TRAIL_TABLE % args, '']
+
 #------------------------------------------------------------------
-def trigger_ddl(aCursor='default', schema='audit', audited_table=None):
-	audit_trail_table = '%s%s' % (audit_trail_table_prefix, audited_table)
+def trigger_ddl(aCursor='default', schema=AUDIT_SCHEMA, audited_table=None):
 
 	target_columns = gmPG2.get_col_names(link_obj = aCursor, schema = schema, table = audited_table)
-	columns2skip = gmPG2.get_col_names(link_obj = aCursor, schema = audit_schema, table =  audit_fields_table)
+	columns2skip = gmPG2.get_col_names(link_obj = aCursor, schema = AUDIT_SCHEMA, table =  AUDIT_FIELDS_TABLE)
 	columns = []
 	values = []
 	for column in target_columns:
 		if column not in columns2skip:
 			columns.append(column)
-			values.append('OLD.%s' % column)
-	columns_clause = string.join(columns, ', ')
-	values_clause = string.join(values, ', ')
+			values.append(u'OLD.%s' % column)
 
-	ddl = []
-
-	# insert
-	ddl.append(tmpl_insert_function % (audited_table, audited_table))
-	ddl.append('')
-	ddl.append(tmpl_insert_trigger % (audited_table, schema, audited_table, audited_table))
-	ddl.append('')
+	args = {
+		'src_tbl': audited_table,
+		'src_schema': schema,
+		'log_tbl': u'%s%s' % (LOG_TABLE_PREFIX, audited_table),
+		'cols_clause': u', '.join(columns),
+		'vals_clause': u', '.join(values)
+	}
 
-	# update
-	ddl.append(tmpl_update_function % (audited_table, audited_table, audit_trail_table, columns_clause, values_clause))
-	ddl.append('')
-	ddl.append(tmpl_update_trigger % (audited_table, schema, audited_table, audited_table))
-	ddl.append('')
+	modified_by_func_exists = gmPG2.function_exists(link_obj = aCursor, schema = u'gm', function = u'account_is_dbowner_or_staff')
 
-	# delete
-	ddl.append(tmpl_delete_function % (audited_table, audited_table, audit_trail_table, columns_clause, values_clause))
-	ddl.append('')
-	ddl.append(tmpl_delete_trigger % (audited_table, schema, audited_table, audited_table))
-	ddl.append('')
-
-	# disallow delete/update on auditing table
+	ddl = []
+	if modified_by_func_exists:
+		ddl.append(SQL_TEMPLATE_INSERT % args)
+		ddl.append(u'')
+		ddl.append(SQL_TEMPLATE_UPDATE % args)
+		ddl.append(u'')
+		ddl.append(SQL_TEMPLATE_DELETE % args)
+		#ddl.append(u'')
+		#ddl.append(SQL_TEMPLATE_FK_MODIFIED_BY % args)
+	else:
+		# the *_NO_*_CHECK variants are needed for pre-v21 databases
+		# where gm.account_is_dbowner_or_staff() doesn't exist yet
+		ddl.append(SQL_TEMPLATE_INSERT_NO_INSERTER_CHECK % args)
+		ddl.append(u'')
+		ddl.append(SQL_TEMPLATE_UPDATE_NO_UPDATER_CHECK % args)
+		ddl.append(u'')
+		ddl.append(SQL_TEMPLATE_DELETE_NO_DELETER_CHECK % args)
+	ddl.append(u'')
 
 	return ddl
+
 #------------------------------------------------------------------
 def create_audit_ddl(aCursor):
 	# get list of all marked tables
 	# we could also get the child tables for audit.audit_fields
 	# but we would have to potentially parse down several levels
 	# of interitance (such as with clin.clin_root_item) to find
-	# the actual leaf tables to audit
+	# the actual leaf table to audit
 	cmd = u"select schema, table_name from audit.audited_tables"
-	rows, idx = gmPG2.run_ro_queries(link_obj=aCursor, queries = [{'cmd': cmd}])
+	rows, idx = gmPG2.run_ro_queries(link_obj = aCursor, queries = [{'cmd': cmd}])
 	if len(rows) == 0:
 		_log.info('no tables to audit')
 		return None
 	_log.debug('the following tables will be audited:')
 	_log.debug(rows)
-	# for each marked table
 	ddl = []
 	ddl.append('\set check_function_bodies 1\n')
 	ddl.append('set check_function_bodies to on;\n\n')
+
+	# for each marked table
 	for row in rows:
 
-		# sanity check: does table exist ?
 		if not gmPG2.table_exists(link_obj = aCursor, schema = row['schema'], table = row['table_name']):
 			_log.error('table to audit (%s) does not exist', row)
 			return None
 
-		audit_trail_ddl = audit_trail_table_ddl(aCursor=aCursor, schema=row['schema'], table2audit=row['table_name'])
+		# create log table if necessary
+		audit_trail_ddl = audit_trail_table_ddl(aCursor = aCursor, schema = row['schema'], table2audit = row['table_name'])
 		if audit_trail_ddl is None:
 			_log.error('cannot generate audit trail DDL for audited table [%s]' % row['table_name'])
 			return None
@@ -270,21 +388,25 @@ def create_audit_ddl(aCursor):
 		if len(audit_trail_ddl) != 0:
 			ddl.append('-- ----------------------------------------------')
 
+		# create functions and triggers on log table
 		ddl.extend(trigger_ddl(aCursor = aCursor, schema = row['schema'], audited_table = row['table_name']))
 		ddl.append('-- ----------------------------------------------')
 
+	#ddl.append(SQL_TEMPLATE_DEM_STAFF_FK)
+
 	return ddl
+
 #==================================================================
 # main
 #------------------------------------------------------------------
 if __name__ == "__main__" :
 	tmp = ''
 	try:
-		tmp = raw_input("audit trail parent table [%s]: " % audit_trail_parent_table)
+		tmp = raw_input("audit trail parent table [%s]: " % AUDIT_TRAIL_PARENT_TABLE)
 	except KeyboardError:
 		pass
 	if tmp != '':
-		audit_trail_parent_table = tmp
+		AUDIT_TRAIL_PARENT_TABLE = tmp
 
 	conn = gmPG2.get_connection(readonly=False, pooled=False)
 	curs = conn.cursor()
@@ -298,8 +420,7 @@ if __name__ == "__main__" :
 		print "error creating schema"
 		sys.exit(-1)
 
-	file = open ('audit-trail-schema.sql', 'wb')
+	f = io.open('audit-trail-schema.sql', mode = 'wb', encoding = 'utf8')
 	for line in schema:
-		file.write("%s;\n" % line)
-	file.close()
-#==================================================================
+		f.write("%s;\n" % line)
+	f.close()
diff --git a/server/bootstrap/gmDBPruningDMLGenerator.py b/server/bootstrap/gmDBPruningDMLGenerator.py
index 3254089..5656202 100644
--- a/server/bootstrap/gmDBPruningDMLGenerator.py
+++ b/server/bootstrap/gmDBPruningDMLGenerator.py
@@ -17,12 +17,10 @@ It is useful to pre-process the dump with:
 to weed out superfluous cruft.
 """
 #==================================================================
-# $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/bootstrap/gmDBPruningDMLGenerator.py,v $
-__version__ = "$Revision: 1.3 $"
 __author__ = "Karsten.Hilbert at gmx.net"
 __license__ = "GPL v2 or later (details at http://www.gnu.org)"
 
-import sys, os.path, codecs, logging
+import sys, os.path, io, logging
 
 
 _log = logging.getLogger('gm.bootstrapper')
@@ -32,11 +30,11 @@ _log.info(__version__)
 def generate_pruning_dml(filename=None):
 
 	# FIXME: encoding may need configuration
-	backup_file = codecs.open(filename = filename, mode = 'rU', encoding = 'utf8')
+	backup_file = io.open(filename, mode = 'rt', encoding = 'utf8')
 	backup_path, name = os.path.split(filename)
 	name, ext = os.path.splitext(name)
 	dml_name = os.path.join(backup_path, '%s-prune_tables.sql' % name)
-	dml_file = codecs.open(filename = dml_name, mode = 'w', encoding = 'utf8')
+	dml_file = io.open(dml_name, mode = 'wt', encoding = 'utf8')
 
 	prev_table = None
 	idx = 1
diff --git a/server/bootstrap/update_db-v19_v20.conf b/server/bootstrap/update_db-v19_v20.conf
index 5238746..09585bd 100644
--- a/server/bootstrap/update_db-v19_v20.conf
+++ b/server/bootstrap/update_db-v19_v20.conf
@@ -121,6 +121,7 @@ schema base directory = ../sql/v19-v20/fixups/
 schema = $schema$
 v20-clin-substance_intake-fixup.sql
 v20-dem-org-idx-fixup.sql
+v20-clin-procedure-fixup.sql
 $schema$
 
 #----------------------------------
diff --git a/server/bootstrap/update_db-v20_v21.conf b/server/bootstrap/update_db-v20_v21.conf
new file mode 100644
index 0000000..eabb6d6
--- /dev/null
+++ b/server/bootstrap/update_db-v20_v21.conf
@@ -0,0 +1,326 @@
+# GNUmed database system bootstrapping config file
+#-------------------------------------------------
+# license: GPL v2 or later
+# author: Karsten Hilbert at gmx.net
+
+#----------------------------------
+[revision control]
+file = /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/bootstrap/update_db-v20_v21.conf
+version = 1.0
+
+#----------------------------------
+[installation]
+interactive = yes
+
+keep temp files = no
+
+description = $description$
+This will update an existing GNUmed version 20
+database to the version 21 schema. It does not do
+any harm to the data contained within.
+
+The existing database will be cloned first. The copy is
+then modified. The original database remains unchanged.
+$description$
+
+
+bundles = $bundles$
+v20_fixups-pre_v21
+v20-v21-static
+v20-v21-dynamic
+$bundles$
+
+
+#----------------------------------
+[bundle v20_fixups-pre_v21]
+database alias = gnumed_v21
+minimum postgresql version = 9.2
+schema base directory = ../sql/v19-v20/fixups/
+schema = $schema$
+../dynamic/v20-release_notes-dynamic.sql
+v20-clin-substance_intake-fixup.sql
+v20-dem-org-idx-fixup.sql
+v20-clin-procedure-fixup.sql
+$schema$
+
+#----------------------------------
+[bundle v20-v21-static]
+database alias = gnumed_v21
+minimum postgresql version = 9.2
+schema base directory = ../sql/v20-v21/static/
+schema = $schema$
+v21-dem-identity-static.sql
+v21-dem-region-static.sql
+v21-ref-auto_hint-static.sql
+v21-clin-substance_intake-static.sql
+v21-blobs-doc_med-static.sql
+$schema$
+
+#----------------------------------
+[bundle v20-v21-dynamic]
+database alias = gnumed_v21
+minimum postgresql version = 9.2
+schema base directory = ../sql/v20-v21/dynamic/
+schema = $schema$
+v21-audit-constraints.sql
+v21-gm-md5.sql
+v21-cfg-cfg_str_array-dynamic.sql
+v21-dem-identity-dynamic.sql
+v21-dem-region-dynamic.sql
+v21-dem-person_views.sql
+v21-dem-v_pat_addresses.sql
+v21-dem-staff-dynamic.sql
+v21-dem-external_id-dynamic.sql
+v21-dem-org-trgm_idx.sql
+v21-blobs-doc_med-dynamic.sql
+v21-blobs-v_doc_desc.sql
+v21-blobs-v_obj4doc_no_data.sql
+v21-blobs-v_reviewed_doc_objects.sql
+v21-blobs-v_latest_mugshot.sql
+v21-ref-v_auto_hints.sql
+v21-clin-procedure-dynamic.sql
+v21-clin-v_waiting_list.sql
+v21-clin-v_suppressed_hints.sql
+v21-clin-sanity_checks.sql
+v21-clin-substance_intake-dynamic.sql
+v21-clin-v_substance_intakes.sql
+v21-clin-v_pat_narrative_journal.sql
+v21-clin-v_health_issues_journal.sql
+v21-clin-v_pat_encounters_journal.sql
+v21-clin-v_pat_episodes_journal.sql
+v21-clin-v_family_history_journal.sql
+v21-clin-v_pat_allergies_journal.sql
+v21-clin-v_pat_allergy_state_journal.sql
+v21-clin-v_test_results_journal.sql
+v21-clin-v_hospital_stays_journal.sql
+v21-blobs-v_doc_med_journal.sql
+v21-clin-v_substance_intake_journal.sql
+v21-clin-v_procedures_journal.sql
+v21-clin-v_vaccinations_journal.sql
+v21-clin-v_suppressed_hints_journal.sql
+v21-clin-v_external_care_journal.sql
+v21-clin-v_edc_journal.sql
+v21-clin-v_reminders_journal.sql
+v21-clin-v_emr_journal.sql
+v21-clin-v_substance_intake4narrative_search.sql
+v21-clin-v_export_items.sql
+v21-clin-v_narrative4search.sql
+v21-clin-vaccination-dynamic.sql
+v21-ref-paperwork_templates.sql
+v21-HIT_risk.sql
+v21-gm-db-translations-de_DE.sql
+v21-release_notes-dynamic.sql
+$schema$
+
+#----------------------------------
+[bundle v21-fixups]
+database alias = gnumed_v21
+minimum postgresql version = 9.2
+schema base directory = ../sql/v20-v21/fixups/
+schema = $schema$
+$schema$
+
+#----------------------------------
+[bundle v21-test_data]
+database alias = gnumed_v21
+minimum postgresql version = 9.2
+schema base directory = ../sql/test-data/
+schema = $schema$
+$schema$
+
+#----------------------------------
+[database gnumed_v21]
+name = gnumed_v21
+override name by = GM_CORE_DB
+drop target database = 1
+target version = v21
+transfer users = 1
+template database = gnumed_v20
+template version = v20
+server alias = local host
+audit disable = 0
+audit trail parent table = audit.audit_trail
+audit trail table prefix = log_
+audit fields table = audit.audit_fields
+schema base directory = ../sql/v20-v21/
+schema = $schema$
+$schema$
+
+superuser schema = $superuser schema$
+superuser/v21-reinstall-pg_trgm.sql
+$superuser schema$
+
+script base directory = ../sql/v20-v21/python/
+data import scripts = $data import scripts$
+v21-import-plot-scripts.py
+v21-import-form-templates.py
+$data import scripts$
+
+
+
+
+# line 1: old database
+# line 2: new database
+upgrade plausibility checks = $upgrade plausibility checks$
+identities::::select count(1) from dem.identity
+	select count(1) from dem.identity
+names::::select count(1) from dem.names
+	select count(1) from dem.names
+v_all_persons::::select count(1) from dem.v_persons
+	select count(1) from dem.v_all_persons
+v_active_persons::::select count(1) from dem.v_basic_person
+	select count(1) from dem.v_active_persons
+staff::::select count(1) from dem.staff
+	select count(1) from dem.staff
+v_staff::::select count(1) from dem.v_staff
+	select count(1) from dem.v_staff
+addresses::::select count(1) from dem.address
+	select count(1) from dem.address
+episodes::::select count(1) from clin.episode where not summary ilike '%[substance use]%'
+	select count(1) from clin.episode where not summary ilike '%[substance use]%'
+denormalized episodes::::select count(1) from clin.v_pat_episodes where not summary ilike '%[substance use]%'
+	select count(1) from clin.v_pat_episodes where not summary ilike '%[substance use]%'
+encounters::::select count(1) from clin.encounter
+	select count(1) from clin.v_pat_encounters
+issues::::select count(1) from clin.health_issue
+	select count(1) from clin.health_issue
+issues view::::select count(1) from clin.v_health_issues
+	select count(1) from clin.v_health_issues
+procedures::::select count(1) from clin.procedure
+	select count(1) from clin.procedure
+documents::::select count(1) from blobs.doc_med
+	select count(1) from blobs.doc_med
+document pages::::select count(1) from blobs.doc_obj
+	select count(1) from blobs.doc_obj
+allergies::::select count(1) from clin.allergy
+	select count(1) from clin.allergy
+communication channels::::select count(1) from dem.lnk_identity2comm
+	select count(1) from dem.lnk_identity2comm
+test results::::select count(1) from clin.test_result
+	select count(1) from clin.test_result
+unmatched test results::::select count(1) from clin.incoming_data_unmatched
+	select count(1) from clin.incoming_data_unmatched
+unmatchable test results::::select count(1) from clin.incoming_data_unmatchable
+	select count(1) from clin.incoming_data_unmatchable
+denormalized test results::::select count(1) from clin.v_test_results
+	select count(1) from clin.v_test_results
+allergy states::::select count(1) from clin.allergy_state
+	select count(1) from clin.allergy_state
+waiting list entries::::select count(1) from clin.waiting_list
+	select count(1) from clin.waiting_list
+waiting list view entries::::select count(1) from clin.v_waiting_list
+	select count(1) from clin.v_waiting_list
+waiting list integrity::::select((select count(1) from clin.v_waiting_list) = (select count(1) from clin.waiting_list))
+	select((select count(1) from clin.v_waiting_list) = (select count(1) from clin.waiting_list))
+messages::::select count(1) + 2 from dem.message_inbox
+	select count(1) from dem.message_inbox
+test orgs::::select count(1) from clin.test_org
+	select count(1) from clin.test_org
+branded drug component intakes::::select count(1) from clin.substance_intake where fk_drug_component is not null
+	select count(1) from clin.substance_intake where fk_drug_component is not null
+substance intakes::::select count(1) + 3 from clin.substance_intake where fk_drug_component is null
+	select count(1) from clin.substance_intake where fk_drug_component is null
+vaccines::::select count(1) from clin.vaccine
+	select count(1) from clin.vaccine
+vaccines (must have indications)::::select 0
+	select count(1) from clin.v_vaccines where indications is NULL
+vaccinations::::select count(1) from clin.vaccination
+	select count(1) from clin.vaccination
+vaccinations per indication::::select count(1) from clin.v_pat_vaccs4indication
+	select count(1) from clin.v_pat_vaccs4indication
+latest vaccinations::::select count(1) from clin.v_pat_last_vacc4indication
+	select count(1) from clin.v_pat_last_vacc4indication
+latest vaccinations - patients::::select count(1) from clin.v_pat_last_vacc4indication group by pk_patient
+	select count(1) from clin.v_pat_last_vacc4indication group by pk_patient
+latest vaccinations - shots::::select count(1) from clin.v_pat_last_vacc4indication group by pk_vaccination
+	select count(1) from clin.v_pat_last_vacc4indication group by pk_vaccination
+latest vaccinations - indications::::select count(1) from clin.v_pat_last_vacc4indication group by pk_indication
+	select count(1) from clin.v_pat_last_vacc4indication group by pk_indication
+requests on results::::select count(1) from clin.test_result where fk_request is not NULL
+	select count(1) from clin.test_result where fk_request is not NULL
+clinical code links (total) - internal consistency::::select True
+	select ((select count(1) from clin.lnk_code2item_root) = (select ((select count(1) from clin.lnk_code2procedure) + (select count(1) from clin.lnk_code2rfe) + (select count(1) from clin.lnk_code2aoe) + (select count(1) from clin.lnk_code2episode) + (select count(1) from clin.lnk_code2h_issue) + (select count(1) from clin.lnk_code2narrative))))
+paperwork templates::::select count(1) from ref.paperwork_templates
+	select count(1) - 3 from ref.paperwork_templates
+automatic hints::::select count(1) + 4 from ref.auto_hint
+	select count(1) from ref.auto_hint
+suppressed hints::::select count(1) from clin.suppressed_hint
+	select count(1) from clin.suppressed_hint
+raw keyword expansions::::select count(1) + 1 from ref.keyword_expansion
+	select count(1) from ref.keyword_expansion
+mapped keyword expansions::::select count(1) + 1 from ref.v_keyword_expansions
+	select count(1) from ref.v_keyword_expansions
+organisations::::select count(1) from dem.org
+	select count(1) from dem.org
+organisational units::::select count(1) from dem.org_unit
+	select count(1) from dem.org_unit
+data sources::::select count(1) from ref.data_source
+	select count(1) from ref.data_source
+bills with invoices but without VAT status::::select 0
+	select count(1) from bill.bill where (apply_vat is null) and (fk_doc is not null)
+clinical items::::select count(1) + 3 from clin.clin_root_item
+	select count(1) from clin.clin_root_item
+export items::::select count(1) from clin.export_item
+	select count(1) from clin.export_item
+export items view::::select count(1) from clin.v_export_items
+	select count(1) from clin.v_export_items
+export items integrity::::select ((select count(1) from clin.export_item) = (select count(1) from clin.v_export_items))
+	select ((select count(1) from clin.export_item) = (select count(1) from clin.v_export_items))
+$upgrade plausibility checks$
+
+
+#latest vaccinations - vaccine::::select count(1) from clin.v_pat_last_vacc4indication group by pk_vaccine
+#	select count(1) from clin.v_pat_last_vacc4indication group by pk_vaccine
+
+#v_pat_addresses::::select ((select count(1) from dem.v_pat_addresses) - (select count(1) from dem.lnk_person_org_address l join dem.identity i on (i.pk = l.id_identity) where i.deleted is true))
+#	select count(1) from dem.v_pat_addresses
+
+#unique URBs with ZIP::::select count(1) from dem.v_uniq_zipped_urbs
+#	select count(1) from dem.v_uniq_zipped_urbs
+
+#ATC codes::::select count(1) from (select distinct on (code, term, fk_data_source) 1 from ref.atc) as uniq_atc
+#	select count(1) from ref.atc
+
+#ATC vs generic codes - internal consistency::::select 0
+#	select code, term, fk_data_source from ref.atc except select code, term, fk_data_source from ref.generic_coding_system
+
+#LOINC codes::::select count(1) from ref.loinc
+#	select count(1) from ref.loinc
+
+#LOINC vs generic codes - internal consistency::::select 0
+#	select code, term, fk_data_source from ref.loinc except select code, term, fk_data_source from ref.generic_coding_system
+
+#generic codes (total) - internal consistency::::select True
+#	select ((select count(1) from ref.coding_system_root) = (select ((select count(1) from ref.atc) + (select count(1) from ref.loinc))))
+
+
+#----------------------------------
+[server local host]
+name = 
+port = 5432
+template database = template1
+super user alias = postgres
+schema base directory = ../sql/v20-v21/
+schema = $schema$
+$schema$
+
+#----------------------------------
+[user GNUmed owner]
+name = gm-dbo
+password = 
+
+[user postgres]
+name = postgres
+#password =
+
+#----------------------------------
+# these really shouldn't be changed
+#----------------------------------
+[GnuMed defaults]
+
+database owner alias = GNUmed owner
+
+groups = $groups$
+$groups$
+
+#----------------------------------
diff --git a/server/doc/gm-backup.8 b/server/doc/gm-backup.8
new file mode 100644
index 0000000..a1431b3
--- /dev/null
+++ b/server/doc/gm-backup.8
@@ -0,0 +1,30 @@
+.TH GM-BACKUP 8 "2016 March 13th" "GNUmed server database backup"
+
+.SH NAME
+.B gm-backup
+- complete backup of GNUmed database
+
+.SH SYNOPSIS
+.B gm-backup
+
+.SH DESCRIPTION
+The
+.B gm-backup
+script creates a backup of the database schema, data, and
+roles which can be used to recreate the backed up GNUmed
+database from scratch or to restore data into an existing
+GNUmed database (that is devoid of any data).
+
+It is a really good idea to use it in a daily cron/anacron
+job to ensure that GNUmed patient data are safe against data
+loss.  The Debian GNU/Linux packaged version of the GNUmed
+server installs such a cron job by default.
+
+.SH SEE ALSO
+gm-backup_database(8)
+
+/etc/gnumed/gnumed-backup.conf
+
+.SH AUTHOR
+This manual page was written by Andreas Tille <tille at debian.org>,
+for the Debian GNU/Linux system (but may be used by others).
diff --git a/server/doc/gm-restore_database_from_archive.8 b/server/doc/gm-restore_database_from_archive.8
new file mode 100644
index 0000000..76df1ec
--- /dev/null
+++ b/server/doc/gm-restore_database_from_archive.8
@@ -0,0 +1,35 @@
+.TH GM-RESTORE_DATABASE_FROM_ARCHIVE 8 "2016 March 13th" "GNUmed server database restore"
+
+.SH NAME
+.B gm-restore_database_from_archive
+- restoring a GNUmed database
+
+.SH SYNOPSIS
+.B gm-restore_database_from_archive
+.I <backup>
+
+.I <backup>:
+a database backup file ("backup-gnumed_vX-*.tar.bz2") created by gm-backup
+
+.SH DESCRIPTION
+The
+.B gm-restore_database_from_archive
+script attempts to recreate from scratch the backed up GNUmed
+database. It tries to be very conservative. It is intended
+for interactive use by root and may have to be adjusted to
+your needs.
+
+.SH KNOWN PROBLEMS
+
+Note that for some reason restoring does not work when
+the backup file you intend to restore is a link to the
+actual backup. Use the full path instead.
+
+.SH SEE ALSO
+gm-backup(8)
+
+/etc/gnumed/gnumed-restore.conf
+
+.SH AUTHOR
+This manual page was written by Karsten Hilbert,
+for the Debian GNU/Linux system (but may be used by others).
diff --git a/server/doc/schema/gnumed-entire_schema-no_audit.dot b/server/doc/schema/gnumed-entire_schema-no_audit.dot
index 15d0e4c..d0e77e7 100644
--- a/server/doc/schema/gnumed-entire_schema-no_audit.dot
+++ b/server/doc/schema/gnumed-entire_schema-no_audit.dot
@@ -11,7 +11,7 @@ shape = record
 edge [
 ];
 
-"au.referral" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD><T [...]
+"au.referral" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD><T [...]
 
 "audit.audit_fields" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer [...]
 
@@ -114,16 +114,15 @@ edge [
 
 
 
+"bill.bill" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD><TD  [...]
 
-"bill.bill" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD><TD  [...]
-
-"bill.bill_item" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD [...]
+"bill.bill_item" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD [...]
 
 "bill.lnk_enc_type2billable" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > fk_encounter_type </TD><TD align="left" > [...]
 
-"blobs.doc_desc" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD [...]
+"blobs.doc_desc" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD [...]
 
-"blobs.doc_med" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD> [...]
+"blobs.doc_med" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD> [...]
 
 "blobs.doc_obj" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > fk_doc </TD><TD align="left" > integer </TD><TD align= [...]
 
@@ -153,89 +152,89 @@ edge [
 
 "cfg.db_logon_banner" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > message </TD><TD align="left" > text </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > singularizer </TD><TD align="left" > boolean </ [...]
 
-"cfg.report_query" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </ [...]
+"cfg.report_query" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </ [...]
 
 "clin._enum_allergy_type" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > value </TD><TD align="left" > text </TD><TD  [...]
 
-"clin.allergy" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD>< [...]
+"clin.allergy" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD>< [...]
 
-"clin.allergy_state" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer  [...]
+"clin.allergy_state" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer  [...]
 
-"clin.clin_aux_note" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer  [...]
+"clin.clin_aux_note" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer  [...]
 
-"clin.clin_diag" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD [...]
+"clin.clin_diag" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD [...]
 
-"clin.clin_item_type" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer [...]
+"clin.clin_item_type" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer [...]
 
-"clin.clin_narrative" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer [...]
+"clin.clin_narrative" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer [...]
 
 "clin.clin_root_item" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer [...]
 
-"clin.encounter" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD [...]
+"clin.encounter" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD [...]
 
 "clin.encounter_type" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > description </TD><TD align="left" > text </TD><T [...]
 
-"clin.episode" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD>< [...]
+"clin.episode" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD>< [...]
 
 "clin.export_item" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > fk_identity </TD><TD align="left" > integer </TD><T [...]
 
-"clin.external_care" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer  [...]
+"clin.external_care" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer  [...]
 
-"clin.family_history" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer [...]
+"clin.family_history" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer [...]
 
-"clin.fhx_relation_type" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > inte [...]
+"clin.fhx_relation_type" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > inte [...]
 
-"clin.form_data" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD [...]
+"clin.form_data" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD [...]
 
-"clin.form_instances" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer [...]
+"clin.form_instances" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer [...]
 
-"clin.health_issue" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer < [...]
+"clin.health_issue" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer < [...]
 
-"clin.hospital_stay" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer  [...]
+"clin.hospital_stay" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer  [...]
 
-"clin.incoming_data_unmatchable" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left [...]
+"clin.incoming_data_unmatchable" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left [...]
 
-"clin.incoming_data_unmatched" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left"  [...]
+"clin.incoming_data_unmatched" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left"  [...]
 
-"clin.lab_request" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </ [...]
+"clin.lab_request" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </ [...]
 
-"clin.lnk_code2aoe" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer < [...]
+"clin.lnk_code2aoe" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer < [...]
 
-"clin.lnk_code2episode" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integ [...]
+"clin.lnk_code2episode" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integ [...]
 
-"clin.lnk_code2fhx" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer < [...]
+"clin.lnk_code2fhx" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer < [...]
 
-"clin.lnk_code2h_issue" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integ [...]
+"clin.lnk_code2h_issue" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integ [...]
 
 "clin.lnk_code2item_root" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > int [...]
 
-"clin.lnk_code2narrative" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > int [...]
+"clin.lnk_code2narrative" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > int [...]
 
-"clin.lnk_code2procedure" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > int [...]
+"clin.lnk_code2procedure" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > int [...]
 
-"clin.lnk_code2rfe" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer < [...]
+"clin.lnk_code2rfe" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer < [...]
 
-"clin.lnk_code2tst_pnl" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integ [...]
+"clin.lnk_code2tst_pnl" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integ [...]
 
-"clin.lnk_constraint2vacc_course" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="lef [...]
+"clin.lnk_constraint2vacc_course" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="lef [...]
 
-"clin.lnk_pat2vaccination_course" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="lef [...]
+"clin.lnk_pat2vaccination_course" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="lef [...]
 
 "clin.lnk_substance2episode" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" >  [...]
 
-"clin.lnk_tst2norm" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer < [...]
+"clin.lnk_tst2norm" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer < [...]
 
-"clin.lnk_type2item" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer  [...]
+"clin.lnk_type2item" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer  [...]
 
-"clin.lnk_vaccination_course2schedule" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align [...]
+"clin.lnk_vaccination_course2schedule" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align [...]
 
-"clin.lnk_vaccine2inds" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integ [...]
+"clin.lnk_vaccine2inds" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integ [...]
 
 "clin.meta_test_type" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > abbrev </TD><TD align="left" > text </TD><TD ali [...]
 
-"clin.patient" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD>< [...]
+"clin.patient" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD>< [...]
 
-"clin.procedure" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD [...]
+"clin.procedure" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD [...]
 
 "clin.review_root" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </ [...]
 
@@ -243,53 +242,51 @@ edge [
 
 "clin.soap_cat_ranks" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > rank </TD><TD align="left" > integer </TD><TD al [...]
 
-"clin.substance_intake" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integ [...]
-
-"clin.suppressed_hint" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > intege [...]
+"clin.substance_intake" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integ [...]
 
-"clin.test_org" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD> [...]
+"clin.suppressed_hint" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > intege [...]
 
-"clin.test_panel" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </T [...]
+"clin.test_org" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD> [...]
 
-"clin.test_result" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </ [...]
+"clin.test_panel" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </T [...]
 
-"clin.test_type" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD [...]
+"clin.test_result" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </ [...]
 
-"clin.vacc_indication" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > intege [...]
+"clin.test_type" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD [...]
 
-"clin.vacc_route" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </T [...]
+"clin.vacc_indication" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > intege [...]
 
-"clin.vaccination" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </ [...]
+"clin.vacc_route" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </T [...]
 
-"clin.vaccination_course" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > int [...]
+"clin.vaccination" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </ [...]
 
-"clin.vaccination_course_constraint" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align=" [...]
+"clin.vaccination_course" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > int [...]
 
-"clin.vaccination_definition" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > [...]
+"clin.vaccination_course_constraint" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align=" [...]
 
-"clin.vaccination_schedule" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > i [...]
+"clin.vaccination_definition" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > [...]
 
-"clin.vaccine" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD>< [...]
+"clin.vaccination_schedule" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > i [...]
 
-"clin.vaccine_batches" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > intege [...]
+"clin.vaccine" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD>< [...]
 
-"clin.waiting_list" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer < [...]
+"clin.vaccine_batches" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > intege [...]
 
-"de_de.beh_fall_typ" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer  [...]
+"clin.waiting_list" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer < [...]
 
-"de_de.behandlungsfall" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > fk_patient </TD><TD align="left" > integer </T [...]
+"de_de.beh_fall_typ" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer  [...]
 
 "de_de.kvk" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > fk_patient </TD><TD align="left" > integer </TD><TD align= [...]
 
-"de_de.lab_test_gnr" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer  [...]
+"de_de.lab_test_gnr" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer  [...]
 
 "de_de.payment_method" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > description </TD><TD align="left" > text </TD>< [...]
 
-"de_de.prax_geb_paid" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer [...]
+"de_de.prax_geb_paid" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer [...]
 
 "de_de.zuzahlungsbefreiung" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > id </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > id_patient </TD><TD align="left" > integer [...]
 
-"dem.address" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD><T [...]
+"dem.address" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD><T [...]
 
 "dem.address_type" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > id </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > name </TD><TD align="left" > text </TD><TD align="l [...]
 
@@ -299,59 +296,59 @@ edge [
 
 "dem.enum_ext_id_types" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > name </TD><TD align="left" > text </TD><TD ali [...]
 
-"dem.gender_label" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </ [...]
+"dem.gender_label" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </ [...]
 
-"dem.identity" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD>< [...]
+"dem.identity" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD>< [...]
 
-"dem.identity_tag" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </ [...]
+"dem.identity_tag" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </ [...]
 
-"dem.inbox_item_category" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > int [...]
+"dem.inbox_item_category" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > int [...]
 
-"dem.inbox_item_type" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer [...]
+"dem.inbox_item_type" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer [...]
 
 "dem.lnk_identity2comm" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > fk_identity </TD><TD align="left" > integer </ [...]
 
-"dem.lnk_identity2ext_id" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > int [...]
+"dem.lnk_identity2ext_id" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > int [...]
 
-"dem.lnk_job2person" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer  [...]
+"dem.lnk_job2person" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer  [...]
 
-"dem.lnk_org_unit2comm" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integ [...]
+"dem.lnk_org_unit2comm" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integ [...]
 
-"dem.lnk_org_unit2ext_id" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > int [...]
+"dem.lnk_org_unit2ext_id" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > int [...]
 
-"dem.lnk_person2relative" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > int [...]
+"dem.lnk_person2relative" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > int [...]
 
 "dem.lnk_person_org_address" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > id </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > id_identity </TD><TD align="left" > integ [...]
 
 "dem.marital_status" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > name </TD><TD align="left" > text </TD><TD align= [...]
 
-"dem.message_inbox" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer < [...]
+"dem.message_inbox" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer < [...]
 
 "dem.name_gender_map" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > id </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > name </TD><TD align="left" > text </TD><TD align [...]
 
 "dem.names" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > id </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > id_identity </TD><TD align="left" > integer </TD><TD align [...]
 
-"dem.occupation" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD [...]
+"dem.occupation" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD [...]
 
-"dem.org" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD><TD al [...]
+"dem.org" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD><TD al [...]
 
 "dem.org_category" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > description </TD><TD align="left" > text </TD><TD a [...]
 
-"dem.org_unit" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD>< [...]
+"dem.org_unit" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD>< [...]
 
-"dem.praxis_branch" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer < [...]
+"dem.praxis_branch" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer < [...]
 
-"dem.relation_types" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer  [...]
+"dem.region" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD><TD [...]
 
-"dem.staff" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD><TD  [...]
+"dem.relation_types" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer  [...]
 
-"dem.state" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD><TD  [...]
+"dem.staff" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD><TD  [...]
 
-"dem.street" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD><TD [...]
+"dem.street" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD><TD [...]
 
-"dem.urb" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD><TD al [...]
+"dem.urb" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD><TD al [...]
 
-"gm.access_log" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD> [...]
+"gm.access_log" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD> [...]
 
 "gm.notifying_tables" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > schema_name </TD><TD align="left" > name </TD><T [...]
 
@@ -383,15 +380,15 @@ edge [
 
 "public.unit" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > fk_basic_unit </TD><TD align="left" > integer </TD><TD a [...]
 
-"ref.atc" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_coding_system </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > code </TD><TD align="left" > text </TD><TD alig [...]
+"ref.atc" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_coding_system </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > code </TD><TD align="left" > text </TD><TD alig [...]
 
 "ref.atc_staging" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > atc </TD><TD align="left" > text </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > name </TD><TD align="left" > text </TD><TD align="left" [...]
 
-"ref.auto_hint" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD> [...]
+"ref.auto_hint" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD> [...]
 
 "ref.billable" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_coding_system </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > code </TD><TD align="left" > text </TD><TD [...]
 
-"ref.branded_drug" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </ [...]
+"ref.branded_drug" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </ [...]
 
 "ref.coda" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_coding_system </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > code </TD><TD align="left" > text </TD><TD ali [...]
 
@@ -399,9 +396,9 @@ edge [
 
 "ref.coding_system_root" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_coding_system </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > code </TD><TD align="left" > te [...]
 
-"ref.consumable_substance" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > in [...]
+"ref.consumable_substance" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > in [...]
 
-"ref.data_source" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </T [...]
+"ref.data_source" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </T [...]
 
 "ref.document_type" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > scope </TD><TD align="left" > text </TD><TD align= [...]
 
@@ -421,7 +418,7 @@ edge [
 
 "ref.keyword_expansion" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > fk_staff </TD><TD align="left" > integer </TD> [...]
 
-"ref.lnk_substance2brand" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > int [...]
+"ref.lnk_substance2brand" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > int [...]
 
 "ref.loinc" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_coding_system </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > code </TD><TD align="left" > text </TD><TD al [...]
 
@@ -431,9 +428,9 @@ edge [
 
 "ref.papersizes" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk </TD><TD align="left" > serial </TD><TD align="left" > PK </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > name </TD><TD align="left" > text </TD><TD align="lef [...]
 
-"ref.paperwork_templates" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > int [...]
+"ref.paperwork_templates" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > int [...]
 
-"ref.tag_image" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD> [...]
+"ref.tag_image" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer </TD> [...]
 
 "staging.lab_request" [shape = plaintext, label = < <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"> <TR ><TD PORT="ltcol0"> </TD> <TD bgcolor="grey90" border="1" COLSPAN="4"> \N </TD> <TD PORT="rtcol0"></TD></TR>  <TR><TD PORT="ltcol1" ></TD><TD align="left" > pk_audit </TD><TD align="left" > integer </TD><TD align="left" >  </TD><TD align="left" >  </TD><TD align="left" PORT="rtcol1"> </TD></TR> <TR><TD PORT="ltcol2" ></TD><TD align="left" > row_version </TD><TD align="left" > integer [...]
 
@@ -443,23 +440,29 @@ edge [
 
 
 
+"au.referral":rtcol4 -> "dem.staff":ltcol7 [label="fk_au_referral_fk_modified_by"];
 "au.referral":rtcol7 -> "clin.encounter":ltcol5 [label="referral_fk_encounter_fkey"];
 "au.referral":rtcol8 -> "clin.episode":ltcol5 [label="referral_fk_episode_fkey"];
 "au.referral":rtcol12 -> "dem.identity":ltcol5 [label="referral_fk_referee_fkey"];
 "au.referral":rtcol13 -> "clin.form_instances":ltcol11 [label="referral_fk_form_fkey"];
+"bill.bill":rtcol4 -> "dem.staff":ltcol7 [label="fk_bill_bill_fk_modified_by"];
 "bill.bill":rtcol9 -> "dem.identity":ltcol5 [label="bill_fk_receiver_identity_fkey"];
 "bill.bill":rtcol10 -> "dem.lnk_person_org_address":ltcol1 [label="bill_fk_receiver_address_fkey"];
 "bill.bill":rtcol11 -> "blobs.doc_med":ltcol5 [label="bill_fk_doc_fkey"];
+"bill.bill_item":rtcol4 -> "dem.staff":ltcol7 [label="fk_bill_bill_item_fk_modified_by"];
 "bill.bill_item":rtcol6 -> "dem.staff":ltcol5 [label="bill_item_fk_provider_fkey"];
 "bill.bill_item":rtcol7 -> "clin.encounter":ltcol5 [label="bill_item_fk_encounter_fkey"];
 "bill.bill_item":rtcol13 -> "ref.billable":ltcol6 [label="bill_item_fk_billable_fkey"];
 "bill.bill_item":rtcol14 -> "bill.bill":ltcol5 [label="fk_bill_item_fk_bill"];
 "bill.lnk_enc_type2billable":rtcol2 -> "clin.encounter_type":ltcol1 [label="lnk_enc_type2billable_fk_encounter_type_fkey"];
 "bill.lnk_enc_type2billable":rtcol3 -> "ref.billable":ltcol6 [label="lnk_enc_type2billable_fk_billable_fkey"];
+"blobs.doc_desc":rtcol4 -> "dem.staff":ltcol7 [label="fk_blobs_doc_desc_fk_modified_by"];
 "blobs.doc_desc":rtcol6 -> "blobs.doc_med":ltcol5 [label="doc_desc_doc_id_fkey"];
+"blobs.doc_med":rtcol4 -> "dem.staff":ltcol7 [label="fk_blobs_doc_med_fk_modified_by"];
 "blobs.doc_med":rtcol6 -> "clin.encounter":ltcol5 [label="doc_med_fk_encounter_fkey"];
 "blobs.doc_med":rtcol7 -> "clin.episode":ltcol5 [label="doc_med_fk_episode_fkey"];
 "blobs.doc_med":rtcol8 -> "blobs.doc_type":ltcol1 [label="doc_med_type_fkey"];
+"blobs.doc_med":rtcol12 -> "dem.org_unit":ltcol5 [label="fk_blobs_doc_med_dem_org_unit_pk"];
 "blobs.doc_obj":rtcol2 -> "blobs.doc_med":ltcol5 [label="doc_obj_fk_doc_fkey"];
 "blobs.doc_obj":rtcol5 -> "dem.staff":ltcol5 [label="doc_obj_fk_intended_reviewer_fkey"];
 "blobs.lnk_doc2hospital_stay":rtcol6 -> "clin.hospital_stay":ltcol11 [label="lnk_doc2hospital_stay_fk_stay_fkey"];
@@ -473,145 +476,216 @@ edge [
 "cfg.cfg_str_array":rtcol1 -> "cfg.cfg_item":ltcol1 [label="cfg_str_array_fk_item_fkey"];
 "cfg.cfg_string":rtcol1 -> "cfg.cfg_item":ltcol1 [label="cfg_string_fk_item_fkey"];
 "cfg.cfg_template":rtcol3 -> "cfg.cfg_type_enum":ltcol1 [label="cfg_template_type_fkey"];
+"cfg.report_query":rtcol4 -> "dem.staff":ltcol7 [label="fk_cfg_report_query_fk_modified_by"];
+"clin.allergy":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_allergy_fk_modified_by"];
 "clin.allergy":rtcol7 -> "clin.encounter":ltcol5 [label="allergy_fk_encounter_fkey"];
 "clin.allergy":rtcol8 -> "clin.episode":ltcol5 [label="allergy_fk_episode_fkey"];
 "clin.allergy":rtcol17 -> "clin._enum_allergy_type":ltcol1 [label="allergy_id_type_fkey"];
+"clin.allergy_state":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_allergy_state_fk_modified_by"];
 "clin.allergy_state":rtcol9 -> "clin.encounter":ltcol5 [label="allergy_state_fk_encounter_fkey"];
+"clin.clin_aux_note":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_clin_aux_note_fk_modified_by"];
 "clin.clin_aux_note":rtcol7 -> "clin.encounter":ltcol5 [label="clin_aux_note_fk_encounter_fkey"];
 "clin.clin_aux_note":rtcol8 -> "clin.episode":ltcol5 [label="clin_aux_note_fk_episode_fkey"];
+"clin.clin_diag":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_clin_diag_fk_modified_by"];
 "clin.clin_diag":rtcol6 -> "clin.clin_narrative":ltcol11 [label="clin_diag_fk_narrative_fkey"];
+"clin.clin_item_type":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_clin_item_type_fk_modified_by"];
+"clin.clin_narrative":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_clin_narrative_fk_modified_by"];
 "clin.clin_narrative":rtcol7 -> "clin.encounter":ltcol5 [label="clin_narrative_fk_encounter_fkey"];
 "clin.clin_narrative":rtcol8 -> "clin.episode":ltcol5 [label="clin_narrative_fk_episode_fkey"];
 "clin.clin_root_item":rtcol7 -> "clin.encounter":ltcol5 [label="clin_root_item_fk_encounter_fkey"];
 "clin.clin_root_item":rtcol8 -> "clin.episode":ltcol5 [label="clin_root_item_fk_episode_fkey"];
+"clin.encounter":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_encounter_fk_modified_by"];
 "clin.encounter":rtcol6 -> "clin.patient":ltcol6 [label="fk_clin_encounter_fk_patient"];
 "clin.encounter":rtcol7 -> "clin.encounter_type":ltcol1 [label="encounter_fk_type_fkey"];
 "clin.encounter":rtcol8 -> "dem.org_unit":ltcol5 [label="encounter_fk_location_fkey"];
+"clin.episode":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_episode_fk_modified_by"];
 "clin.episode":rtcol6 -> "clin.health_issue":ltcol5 [label="episode_fk_health_issue_fkey"];
 "clin.episode":rtcol9 -> "clin.encounter":ltcol5 [label="episode_fk_encounter_fkey"];
 "clin.export_item":rtcol2 -> "clin.patient":ltcol6 [label="fk_clin_export_item_fk_identity"];
 "clin.export_item":rtcol7 -> "blobs.doc_obj":ltcol1 [label="fk_clin_export_item_fk_doc_obj"];
+"clin.external_care":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_external_care_fk_modified_by"];
 "clin.external_care":rtcol6 -> "clin.encounter":ltcol5 [label="fk_clin_external_care_fk_encounter"];
 "clin.external_care":rtcol7 -> "clin.health_issue":ltcol5 [label="fk_clin_ext_care_fk_health_issue"];
 "clin.external_care":rtcol9 -> "dem.org_unit":ltcol5 [label="fk_clin_ext_care_fk_org_unit"];
+"clin.family_history":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_family_history_fk_modified_by"];
 "clin.family_history":rtcol7 -> "clin.encounter":ltcol5 [label="clin_hx_family_fk_encounter_fkey"];
 "clin.family_history":rtcol8 -> "clin.episode":ltcol5 [label="clin_hx_family_fk_episode_fkey"];
 "clin.family_history":rtcol12 -> "clin.fhx_relation_type":ltcol5 [label="family_history_fk_relation_type_fkey"];
+"clin.fhx_relation_type":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_fhx_relation_type_fk_modified_by"];
+"clin.form_data":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_form_data_fk_modified_by"];
 "clin.form_data":rtcol6 -> "clin.form_instances":ltcol11 [label="form_data_fk_instance_fkey"];
 "clin.form_data":rtcol7 -> "public.form_fields":ltcol1 [label="form_data_fk_form_field_fkey"];
+"clin.form_instances":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_form_instances_fk_modified_by"];
 "clin.form_instances":rtcol7 -> "clin.encounter":ltcol5 [label="form_instances_fk_encounter_fkey"];
 "clin.form_instances":rtcol8 -> "clin.episode":ltcol5 [label="form_instances_fk_episode_fkey"];
 "clin.form_instances":rtcol12 -> "ref.paperwork_templates":ltcol5 [label="form_instances_fk_form_def_fkey"];
+"clin.health_issue":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_health_issue_fk_modified_by"];
 "clin.health_issue":rtcol13 -> "clin.encounter":ltcol5 [label="health_issue_fk_encounter_fkey"];
+"clin.hospital_stay":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_hospital_stay_fk_modified_by"];
 "clin.hospital_stay":rtcol7 -> "clin.encounter":ltcol5 [label="hospital_stay_fk_encounter_fkey"];
 "clin.hospital_stay":rtcol8 -> "clin.episode":ltcol5 [label="hospital_stay_fk_episode_fkey"];
 "clin.hospital_stay":rtcol13 -> "dem.org_unit":ltcol5 [label="hospital_stay_fk_org_unit_fkey"];
+"clin.incoming_data_unmatchable":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_incoming_data_unmatchable_fk_modified_by"];
+"clin.incoming_data_unmatched":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_incoming_data_unmatched_fk_modified_by"];
 "clin.incoming_data_unmatched":rtcol18 -> "clin.patient":ltcol6 [label="fk_incoming_data_unmatched_fk_identity_disambiguated"];
 "clin.incoming_data_unmatched":rtcol20 -> "dem.staff":ltcol5 [label="incoming_data_unmatched_fk_provider_disambiguated_fkey"];
+"clin.lab_request":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_lab_request_fk_modified_by"];
 "clin.lab_request":rtcol7 -> "clin.encounter":ltcol5 [label="lab_request_fk_encounter_fkey"];
 "clin.lab_request":rtcol8 -> "clin.episode":ltcol5 [label="lab_request_fk_episode_fkey"];
 "clin.lab_request":rtcol12 -> "clin.test_org":ltcol5 [label="lab_request_fk_test_org_fkey"];
 "clin.lab_request":rtcol14 -> "dem.identity":ltcol5 [label="lab_request_fk_requestor_fkey"];
+"clin.lnk_code2aoe":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_lnk_code2aoe_fk_modified_by"];
 "clin.lnk_code2aoe":rtcol7 -> "clin.encounter":ltcol5 [label="lnk_code2aoe_fk_item_fkey"];
+"clin.lnk_code2episode":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_lnk_code2episode_fk_modified_by"];
 "clin.lnk_code2episode":rtcol7 -> "clin.episode":ltcol5 [label="lnk_code2episode_fk_item_fkey"];
+"clin.lnk_code2fhx":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_lnk_code2fhx_fk_modified_by"];
 "clin.lnk_code2fhx":rtcol7 -> "clin.family_history":ltcol11 [label="lnk_code2fhx_fk_item_fkey"];
+"clin.lnk_code2h_issue":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_lnk_code2h_issue_fk_modified_by"];
 "clin.lnk_code2h_issue":rtcol7 -> "clin.health_issue":ltcol5 [label="lnk_code2h_issue_fk_item_fkey"];
+"clin.lnk_code2narrative":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_lnk_code2narrative_fk_modified_by"];
 "clin.lnk_code2narrative":rtcol7 -> "clin.clin_narrative":ltcol11 [label="lnk_code2narrative_fk_item_fkey"];
+"clin.lnk_code2procedure":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_lnk_code2procedure_fk_modified_by"];
 "clin.lnk_code2procedure":rtcol7 -> "clin.procedure":ltcol11 [label="lnk_code2procedure_fk_item_fkey"];
+"clin.lnk_code2rfe":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_lnk_code2rfe_fk_modified_by"];
 "clin.lnk_code2rfe":rtcol7 -> "clin.encounter":ltcol5 [label="lnk_code2rfe_fk_item_fkey"];
+"clin.lnk_code2tst_pnl":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_lnk_code2tst_pnl_fk_modified_by"];
 "clin.lnk_code2tst_pnl":rtcol7 -> "clin.test_panel":ltcol5 [label="lnk_code2tst_pnl_fk_item_fkey"];
+"clin.lnk_constraint2vacc_course":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_lnk_constraint2vacc_course_fk_modified_by"];
 "clin.lnk_constraint2vacc_course":rtcol6 -> "clin.vaccination_course":ltcol5 [label="lnk_constraint2vacc_course_fk_vaccination_course_fkey"];
 "clin.lnk_constraint2vacc_course":rtcol7 -> "clin.vaccination_course_constraint":ltcol5 [label="lnk_constraint2vacc_course_fk_constraint_fkey"];
+"clin.lnk_pat2vaccination_course":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_lnk_pat2vaccination_course_fk_modified_by"];
 "clin.lnk_pat2vaccination_course":rtcol6 -> "clin.patient":ltcol6 [label="fk_lnk_pat2vaccination_course_fk_patient"];
 "clin.lnk_pat2vaccination_course":rtcol7 -> "clin.vaccination_course":ltcol5 [label="lnk_pat2vaccination_course_fk_course_fkey"];
 "clin.lnk_substance2episode":rtcol6 -> "clin.episode":ltcol5 [label="lnk_substance2episode_fk_episode_fkey"];
 "clin.lnk_substance2episode":rtcol7 -> "clin.substance_intake":ltcol11 [label="lnk_substance2episode_fk_substance_fkey"];
+"clin.lnk_tst2norm":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_lnk_tst2norm_fk_modified_by"];
 "clin.lnk_tst2norm":rtcol6 -> "clin.test_type":ltcol5 [label="lnk_tst2norm_id_test_fkey"];
+"clin.lnk_type2item":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_lnk_type2item_fk_modified_by"];
 "clin.lnk_type2item":rtcol6 -> "clin.clin_item_type":ltcol5 [label="lnk_type2item_fk_type_fkey"];
+"clin.lnk_vaccination_course2schedule":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_lnk_vaccination_course2schedule_fk_modified_by"];
 "clin.lnk_vaccination_course2schedule":rtcol6 -> "clin.vaccination_course":ltcol5 [label="lnk_vaccination_course2schedule_fk_course_fkey"];
 "clin.lnk_vaccination_course2schedule":rtcol7 -> "clin.vaccination_schedule":ltcol5 [label="lnk_vaccination_course2schedule_fk_schedule_fkey"];
+"clin.lnk_vaccine2inds":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_lnk_vaccine2inds_fk_modified_by"];
 "clin.lnk_vaccine2inds":rtcol6 -> "clin.vaccine":ltcol5 [label="lnk_vaccine2inds_fk_vaccine_fkey"];
 "clin.lnk_vaccine2inds":rtcol7 -> "clin.vacc_indication":ltcol5 [label="lnk_vaccine2inds_fk_indication_fkey"];
+"clin.patient":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_patient_fk_modified_by"];
 "clin.patient":rtcol6 -> "dem.identity":ltcol5 [label="fk_clin_patient_fk_identity"];
+"clin.procedure":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_procedure_fk_modified_by"];
 "clin.procedure":rtcol7 -> "clin.encounter":ltcol5 [label="procedure_fk_encounter_fkey"];
 "clin.procedure":rtcol8 -> "clin.episode":ltcol5 [label="procedure_fk_episode_fkey"];
-"clin.procedure":rtcol13 -> "clin.hospital_stay":ltcol11 [label="procedure_fk_hospital_stay_fkey"];
-"clin.procedure":rtcol16 -> "dem.org_unit":ltcol5 [label="procedure_fk_org_unit_fkey"];
+"clin.procedure":rtcol12 -> "clin.hospital_stay":ltcol11 [label="procedure_fk_hospital_stay_fkey"];
+"clin.procedure":rtcol15 -> "dem.org_unit":ltcol5 [label="procedure_fk_org_unit_fkey"];
 "clin.review_root":rtcol7 -> "dem.staff":ltcol5 [label="review_root_fk_reviewer_fkey"];
 "clin.reviewed_test_results":rtcol6 -> "clin.test_result":ltcol11 [label="reviewed_test_results_fk_reviewed_row_fkey"];
 "clin.reviewed_test_results":rtcol7 -> "dem.staff":ltcol5 [label="reviewed_test_results_fk_reviewer_fkey"];
+"clin.substance_intake":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_substance_intake_fk_modified_by"];
 "clin.substance_intake":rtcol7 -> "clin.encounter":ltcol5 [label="substance_intake_fk_encounter_fkey"];
 "clin.substance_intake":rtcol8 -> "clin.episode":ltcol5 [label="substance_intake_fk_episode_fkey"];
 "clin.substance_intake":rtcol12 -> "ref.consumable_substance":ltcol5 [label="substance_intake_fk_substance_fkey"];
 "clin.substance_intake":rtcol21 -> "ref.lnk_substance2brand":ltcol5 [label="substance_intake_fk_drug_component_fkey"];
+"clin.suppressed_hint":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_suppressed_hint_fk_modified_by"];
 "clin.suppressed_hint":rtcol6 -> "clin.encounter":ltcol5 [label="fk_clin_suppressed_hint_fk_encounter"];
 "clin.suppressed_hint":rtcol7 -> "ref.auto_hint":ltcol5 [label="fk_clin_suppressed_hint_fk_hint"];
+"clin.test_org":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_test_org_fk_modified_by"];
 "clin.test_org":rtcol6 -> "dem.org_unit":ltcol5 [label="test_org_fk_org_unit_fkey"];
 "clin.test_org":rtcol7 -> "dem.identity":ltcol5 [label="test_org_fk_adm_contact_fkey"];
 "clin.test_org":rtcol8 -> "dem.identity":ltcol5 [label="test_org_fk_med_contact_fkey"];
+"clin.test_panel":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_test_panel_fk_modified_by"];
+"clin.test_result":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_test_result_fk_modified_by"];
 "clin.test_result":rtcol7 -> "clin.encounter":ltcol5 [label="test_result_fk_encounter_fkey"];
 "clin.test_result":rtcol8 -> "clin.episode":ltcol5 [label="test_result_fk_episode_fkey"];
 "clin.test_result":rtcol12 -> "clin.test_type":ltcol5 [label="test_result_fk_type_fkey"];
 "clin.test_result":rtcol27 -> "dem.staff":ltcol5 [label="test_result_fk_intended_reviewer_fkey"];
 "clin.test_result":rtcol28 -> "clin.lab_request":ltcol11 [label="test_result_fk_request_fkey"];
+"clin.test_type":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_test_type_fk_modified_by"];
 "clin.test_type":rtcol6 -> "clin.test_org":ltcol5 [label="test_type_fk_test_org_fkey"];
 "clin.test_type":rtcol12 -> "clin.meta_test_type":ltcol1 [label="test_type_fk_meta_test_type_fkey"];
+"clin.vacc_indication":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_vacc_indication_fk_modified_by"];
+"clin.vacc_route":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_vacc_route_fk_modified_by"];
+"clin.vaccination":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_vaccination_fk_modified_by"];
 "clin.vaccination":rtcol7 -> "clin.encounter":ltcol5 [label="vaccination_fk_encounter_fkey"];
 "clin.vaccination":rtcol8 -> "clin.episode":ltcol5 [label="vaccination_fk_episode_fkey"];
 "clin.vaccination":rtcol12 -> "dem.staff":ltcol5 [label="vaccination_fk_provider_fkey"];
 "clin.vaccination":rtcol13 -> "clin.vaccine":ltcol5 [label="vaccination_fk_vaccine_fkey"];
+"clin.vaccination_course":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_vaccination_course_fk_modified_by"];
 "clin.vaccination_course":rtcol7 -> "clin.vacc_indication":ltcol5 [label="vaccination_course_fk_indication_fkey"];
+"clin.vaccination_course_constraint":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_vaccination_course_constraint_fk_modified_by"];
+"clin.vaccination_definition":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_vaccination_definition_fk_modified_by"];
 "clin.vaccination_definition":rtcol6 -> "clin.vaccination_course":ltcol5 [label="vaccination_definition_fk_course_fkey"];
+"clin.vaccination_schedule":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_vaccination_schedule_fk_modified_by"];
+"clin.vaccine":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_vaccine_fk_modified_by"];
 "clin.vaccine":rtcol6 -> "clin.vacc_route":ltcol5 [label="vaccine_id_route_fkey"];
 "clin.vaccine":rtcol11 -> "ref.branded_drug":ltcol5 [label="vaccine_fk_brand_fkey"];
+"clin.vaccine_batches":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_vaccine_batches_fk_modified_by"];
 "clin.vaccine_batches":rtcol6 -> "clin.vaccine":ltcol5 [label="vaccine_batches_fk_vaccine_fkey"];
+"clin.waiting_list":rtcol4 -> "dem.staff":ltcol7 [label="fk_clin_waiting_list_fk_modified_by"];
 "clin.waiting_list":rtcol6 -> "dem.identity":ltcol5 [label="waiting_list_fk_patient_fkey"];
-"de_de.behandlungsfall":rtcol2 -> "dem.identity":ltcol5 [label="behandlungsfall_fk_patient_fkey"];
-"de_de.behandlungsfall":rtcol3 -> "de_de.beh_fall_typ":ltcol5 [label="behandlungsfall_fk_falltyp_fkey"];
+"de_de.beh_fall_typ":rtcol4 -> "dem.staff":ltcol7 [label="fk_de_de_beh_fall_typ_fk_modified_by"];
 "de_de.kvk":rtcol2 -> "dem.identity":ltcol5 [label="kvk_fk_patient_fkey"];
+"de_de.lab_test_gnr":rtcol4 -> "dem.staff":ltcol7 [label="fk_de_de_lab_test_gnr_fk_modified_by"];
 "de_de.lab_test_gnr":rtcol6 -> "clin.test_type":ltcol5 [label="lab_test_gnr_id_test_fkey"];
-"de_de.prax_geb_paid":rtcol6 -> "de_de.behandlungsfall":ltcol1 [label="prax_geb_paid_fk_fall_fkey"];
+"de_de.prax_geb_paid":rtcol4 -> "dem.staff":ltcol7 [label="fk_de_de_prax_geb_paid_fk_modified_by"];
 "de_de.prax_geb_paid":rtcol9 -> "de_de.payment_method":ltcol1 [label="prax_geb_paid_paid_with_fkey"];
 "de_de.zuzahlungsbefreiung":rtcol2 -> "dem.identity":ltcol5 [label="zuzahlungsbefreiung_id_patient_fkey"];
+"dem.address":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_address_fk_modified_by"];
 "dem.address":rtcol6 -> "dem.street":ltcol5 [label="address_id_street_fkey"];
+"dem.gender_label":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_gender_label_fk_modified_by"];
+"dem.identity":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_identity_fk_modified_by"];
 "dem.identity":rtcol8 -> "dem.gender_label":ltcol6 [label="identity_gender_fkey"];
-"dem.identity":rtcol11 -> "dem.marital_status":ltcol1 [label="identity_fk_marital_status_fkey"];
-"dem.identity":rtcol17 -> "dem.identity":ltcol5 [label="identity_fk_emergency_contact_fkey"];
-"dem.identity":rtcol19 -> "dem.staff":ltcol5 [label="identity_fk_primary_provider_fkey"];
+"dem.identity":rtcol10 -> "dem.marital_status":ltcol1 [label="identity_fk_marital_status_fkey"];
+"dem.identity":rtcol16 -> "dem.identity":ltcol5 [label="identity_fk_emergency_contact_fkey"];
+"dem.identity":rtcol18 -> "dem.staff":ltcol5 [label="identity_fk_primary_provider_fkey"];
+"dem.identity_tag":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_identity_tag_fk_modified_by"];
 "dem.identity_tag":rtcol6 -> "dem.identity":ltcol5 [label="identity_tag_fk_identity_fkey"];
 "dem.identity_tag":rtcol7 -> "ref.tag_image":ltcol5 [label="identity_tag_fk_tag_fkey"];
+"dem.inbox_item_category":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_inbox_item_category_fk_modified_by"];
+"dem.inbox_item_type":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_inbox_item_type_fk_modified_by"];
 "dem.inbox_item_type":rtcol6 -> "dem.inbox_item_category":ltcol5 [label="inbox_item_type_fk_inbox_item_category_fkey"];
 "dem.lnk_identity2comm":rtcol2 -> "dem.identity":ltcol5 [label="lnk_identity2comm_id_identity_fkey"];
 "dem.lnk_identity2comm":rtcol3 -> "dem.address":ltcol5 [label="lnk_identity2comm_id_address_fkey"];
 "dem.lnk_identity2comm":rtcol5 -> "dem.enum_comm_types":ltcol1 [label="lnk_identity2comm_id_type_fkey"];
+"dem.lnk_identity2ext_id":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_lnk_identity2ext_id_fk_modified_by"];
 "dem.lnk_identity2ext_id":rtcol6 -> "dem.identity":ltcol5 [label="lnk_identity2ext_id_id_identity_fkey"];
 "dem.lnk_identity2ext_id":rtcol8 -> "dem.enum_ext_id_types":ltcol1 [label="lnk_identity2ext_id_fk_origin_fkey"];
+"dem.lnk_job2person":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_lnk_job2person_fk_modified_by"];
 "dem.lnk_job2person":rtcol6 -> "dem.identity":ltcol5 [label="lnk_job2person_fk_identity_fkey"];
 "dem.lnk_job2person":rtcol7 -> "dem.occupation":ltcol5 [label="lnk_job2person_fk_occupation_fkey"];
+"dem.lnk_org_unit2comm":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_lnk_org_unit2comm_fk_modified_by"];
 "dem.lnk_org_unit2comm":rtcol6 -> "dem.org_unit":ltcol5 [label="lnk_org_unit2comm_fk_org_unit_fkey"];
 "dem.lnk_org_unit2comm":rtcol8 -> "dem.enum_comm_types":ltcol1 [label="lnk_org_unit2comm_fk_type_fkey"];
+"dem.lnk_org_unit2ext_id":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_lnk_org_unit2ext_id_fk_modified_by"];
 "dem.lnk_org_unit2ext_id":rtcol6 -> "dem.org_unit":ltcol5 [label="lnk_org_unit2ext_id_fk_org_unit_fkey"];
 "dem.lnk_org_unit2ext_id":rtcol8 -> "dem.enum_ext_id_types":ltcol1 [label="lnk_org_unit2ext_id_fk_type_fkey"];
+"dem.lnk_person2relative":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_lnk_person2relative_fk_modified_by"];
 "dem.lnk_person2relative":rtcol6 -> "dem.identity":ltcol5 [label="lnk_person2relative_id_identity_fkey"];
 "dem.lnk_person2relative":rtcol7 -> "dem.identity":ltcol5 [label="lnk_person2relative_id_relative_fkey"];
 "dem.lnk_person2relative":rtcol8 -> "dem.relation_types":ltcol5 [label="lnk_person2relative_id_relation_type_fkey"];
 "dem.lnk_person_org_address":rtcol2 -> "dem.identity":ltcol5 [label="lnk_person_org_address_id_identity_fkey"];
 "dem.lnk_person_org_address":rtcol3 -> "dem.address":ltcol5 [label="lnk_person_org_address_id_address_fkey"];
 "dem.lnk_person_org_address":rtcol4 -> "dem.address_type":ltcol1 [label="lnk_person_org_address_id_type_fkey"];
+"dem.message_inbox":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_message_inbox_fk_modified_by"];
 "dem.message_inbox":rtcol6 -> "dem.staff":ltcol5 [label="provider_inbox_fk_staff_fkey"];
 "dem.message_inbox":rtcol7 -> "dem.inbox_item_type":ltcol5 [label="provider_inbox_fk_inbox_item_type_fkey"];
 "dem.message_inbox":rtcol11 -> "dem.identity":ltcol5 [label="message_inbox_fk_patient_fkey"];
 "dem.names":rtcol2 -> "dem.identity":ltcol5 [label="names_id_identity_fkey"];
+"dem.occupation":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_occupation_fk_modified_by"];
+"dem.org":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_org_fk_modified_by"];
 "dem.org":rtcol7 -> "dem.org_category":ltcol1 [label="org_fk_category_fkey"];
 "dem.org":rtcol8 -> "ref.data_source":ltcol5 [label="org_fk_data_source_fkey"];
+"dem.org_unit":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_org_unit_fk_modified_by"];
 "dem.org_unit":rtcol7 -> "dem.org":ltcol5 [label="org_unit_fk_org_fkey"];
 "dem.org_unit":rtcol8 -> "dem.address":ltcol5 [label="org_unit_fk_address_fkey"];
 "dem.org_unit":rtcol9 -> "dem.org_category":ltcol1 [label="org_unit_fk_category_fkey"];
+"dem.praxis_branch":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_praxis_branch_fk_modified_by"];
+"dem.region":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_region_fk_modified_by"];
+"dem.region":rtcol7 -> "dem.country":ltcol2 [label="state_country_fkey"];
+"dem.relation_types":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_relation_types_fk_modified_by"];
 "dem.relation_types":rtcol6 -> "dem.relation_types":ltcol5 [label="relation_types_inverse_fkey"];
 "dem.staff":rtcol6 -> "dem.identity":ltcol5 [label="staff_fk_identity_fkey"];
-"dem.state":rtcol7 -> "dem.country":ltcol2 [label="state_country_fkey"];
+"dem.street":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_street_fk_modified_by"];
 "dem.street":rtcol6 -> "dem.urb":ltcol5 [label="street_id_urb_fkey"];
-"dem.urb":rtcol6 -> "dem.state":ltcol5 [label="urb_id_state_fkey"];
+"dem.urb":rtcol4 -> "dem.staff":ltcol7 [label="fk_dem_urb_fk_modified_by"];
+"dem.urb":rtcol6 -> "dem.region":ltcol5 [label="fk_dem_urb_dem_region_pk"];
 "public.form_fields":rtcol2 -> "ref.paperwork_templates":ltcol5 [label="form_fields_fk_form_fkey"];
 "public.form_fields":rtcol6 -> "public.form_field_types":ltcol2 [label="form_fields_fk_type_fkey"];
 "public.form_job_queue":rtcol2 -> "clin.form_instances":ltcol11 [label="form_job_queue_fk_form_instance_fkey"];
@@ -619,10 +693,14 @@ edge [
 "public.form_print_defs":rtcol3 -> "ref.papersizes":ltcol1 [label="form_print_defs_fk_papersize_fkey"];
 "public.unit":rtcol2 -> "public.basic_unit":ltcol1 [label="unit_fk_basic_unit_fkey"];
 "ref.atc":rtcol4 -> "ref.data_source":ltcol5 [label="atc_fk_data_source_fkey"];
+"ref.auto_hint":rtcol4 -> "dem.staff":ltcol7 [label="fk_ref_auto_hint_fk_modified_by"];
 "ref.billable":rtcol4 -> "ref.data_source":ltcol5 [label="billable_fk_data_source_fkey"];
+"ref.branded_drug":rtcol4 -> "dem.staff":ltcol7 [label="fk_ref_branded_drug_fk_modified_by"];
 "ref.branded_drug":rtcol10 -> "ref.data_source":ltcol5 [label="branded_drug_fk_data_source_fkey"];
 "ref.coda":rtcol4 -> "ref.data_source":ltcol5 [label="coda_fk_data_source_fkey"];
 "ref.coding_system_root":rtcol4 -> "ref.data_source":ltcol5 [label="coding_system_root_fk_data_source_fkey"];
+"ref.consumable_substance":rtcol4 -> "dem.staff":ltcol7 [label="fk_ref_consumable_substance_fk_modified_by"];
+"ref.data_source":rtcol4 -> "dem.staff":ltcol7 [label="fk_ref_data_source_fk_modified_by"];
 "ref.icd10":rtcol4 -> "ref.data_source":ltcol5 [label="icd10_fk_data_source_fkey"];
 "ref.icd9":rtcol4 -> "ref.data_source":ltcol5 [label="icd9_fk_data_source_fkey"];
 "ref.icpc":rtcol4 -> "ref.data_source":ltcol5 [label="icpc_fk_data_source_fkey"];
@@ -630,12 +708,15 @@ edge [
 "ref.icpc":rtcol15 -> "ref.icpc_chapter":ltcol2 [label="icpc_fk_chapter_fkey"];
 "ref.icpc_thesaurus":rtcol2 -> "ref.icpc":ltcol1 [label="icpc_thesaurus_fk_code_fkey"];
 "ref.keyword_expansion":rtcol2 -> "dem.staff":ltcol5 [label="keyword_expansion_fk_staff_fkey"];
+"ref.lnk_substance2brand":rtcol4 -> "dem.staff":ltcol7 [label="fk_ref_lnk_substance2brand_fk_modified_by"];
 "ref.lnk_substance2brand":rtcol6 -> "ref.branded_drug":ltcol5 [label="lnk_substance2brand_fk_brand_fkey"];
 "ref.lnk_substance2brand":rtcol7 -> "ref.consumable_substance":ltcol5 [label="lnk_substance2brand_fk_substance_fkey"];
 "ref.loinc":rtcol4 -> "ref.data_source":ltcol5 [label="loinc_fk_data_source_fkey"];
 "ref.ops":rtcol4 -> "ref.data_source":ltcol5 [label="ops_fk_data_source_fkey"];
 "ref.other_code":rtcol4 -> "ref.data_source":ltcol5 [label="other_code_fk_data_source_fkey"];
+"ref.paperwork_templates":rtcol4 -> "dem.staff":ltcol7 [label="fk_ref_paperwork_templates_fk_modified_by"];
 "ref.paperwork_templates":rtcol6 -> "ref.form_types":ltcol2 [label="paperwork_templates_fk_template_type_fkey"];
+"ref.tag_image":rtcol4 -> "dem.staff":ltcol7 [label="fk_ref_tag_image_fk_modified_by"];
 "staging.lab_request":rtcol11 -> "clin.test_org":ltcol5 [label="lab_request_fk_test_org_fkey"];
 "staging.test_result":rtcol27 -> "staging.lab_request":ltcol10 [label="test_result_fk_request_fkey"];
 }
diff --git a/server/doc/schema/gnumed-entire_schema.html b/server/doc/schema/gnumed-entire_schema.html
index 713c711..a189b0f 100644
--- a/server/doc/schema/gnumed-entire_schema.html
+++ b/server/doc/schema/gnumed-entire_schema.html
@@ -4,7 +4,7 @@
 
 <html>
   <head>
-    <title>Index for gnumed_v20</title>
+    <title>Index for gnumed_v21</title>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     <style type="text/css">
 	BODY {
@@ -104,16 +104,16 @@
 		font-size: 12px;
 	}
     </style>
-    <link rel="stylesheet" type="text/css" media="all" href="http://publicdb.gnumed.de/~ncq/gnumed/schema/gnumed_v20/all.css">
-    <link rel="stylesheet" type="text/css" media="screen" href="http://publicdb.gnumed.de/~ncq/gnumed/schema/gnumed_v20/screen.css">
-    <link rel="stylesheet" type="text/css" media="print" href="http://publicdb.gnumed.de/~ncq/gnumed/schema/gnumed_v20/print.css">
+    <link rel="stylesheet" type="text/css" media="all" href="http://publicdb.gnumed.de/~ncq/gnumed/schema/gnumed_v21/all.css">
+    <link rel="stylesheet" type="text/css" media="screen" href="http://publicdb.gnumed.de/~ncq/gnumed/schema/gnumed_v21/screen.css">
+    <link rel="stylesheet" type="text/css" media="print" href="http://publicdb.gnumed.de/~ncq/gnumed/schema/gnumed_v21/print.css">
     <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   </head>
   <body>
 
     <!-- Primary Index -->
-	<p><br><br>Dumped on 2016-01-27</p>
-<h1><a name="index">Index of database - gnumed_v20</a></h1>
+	<p><br><br>Dumped on 2016-03-17</p>
+<h1><a name="index">Index of database - gnumed_v21</a></h1>
 <ul>
     
     <li><a name="au.schema">au</a></li><ul>
@@ -122,8 +122,8 @@
     </ul>
     
     <li><a name="audit.schema">audit</a></li><ul>
-    	<li><a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a></li><li><a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a></li><li><a href="gnumed-entire_schema.html#audit.table.audited-tables">audited_tables</a></li><li><a href="gnumed-entire_schema.html#audit.table.log-access-log">log_access_log</a></li><li><a href="gnumed-entire_schema.html#audit.table.log-address">log_address</a></li><li><a href="gnumed-entire_schema.html#audit.table.lo [...]
-  	<li><a href="gnumed-entire_schema.html#audit.function.add-table-for-audit-name">add_table_for_audit(name)</a></li><li><a href="gnumed-entire_schema.html#audit.function.add-table-for-audit-name-name">add_table_for_audit(name, name)</a></li><li><a href="gnumed-entire_schema.html#audit.function.ft-del-access-log">ft_del_access_log()</a></li><li><a href="gnumed-entire_schema.html#audit.function.ft-del-active-substance">ft_del_active_substance()</a></li><li><a href="gnumed-entire_schema.ht [...]
+    	<li><a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a></li><li><a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a></li><li><a href="gnumed-entire_schema.html#audit.table.audited-tables">audited_tables</a></li><li><a href="gnumed-entire_schema.html#audit.table.log-access-log">log_access_log</a></li><li><a href="gnumed-entire_schema.html#audit.table.log-address">log_address</a></li><li><a href="gnumed-entire_schema.html#audit.table.lo [...]
+  	<li><a href="gnumed-entire_schema.html#audit.function.add-table-for-audit-name">add_table_for_audit(name)</a></li><li><a href="gnumed-entire_schema.html#audit.function.add-table-for-audit-name-name">add_table_for_audit(name, name)</a></li><li><a href="gnumed-entire_schema.html#audit.function.ft-del-access-log">ft_del_access_log()</a></li><li><a href="gnumed-entire_schema.html#audit.function.ft-del-active-substance">ft_del_active_substance()</a></li><li><a href="gnumed-entire_schema.ht [...]
     </ul>
     
     <li><a name="bill.schema">bill</a></li><ul>
@@ -142,23 +142,23 @@
     </ul>
     
     <li><a name="clin.schema">clin</a></li><ul>
-    	<li><a href="gnumed-entire_schema.html#clin.table.-enum-allergy-type">_enum_allergy_type</a></li><li><a href="gnumed-entire_schema.html#clin.table.allergy">allergy</a></li><li><a href="gnumed-entire_schema.html#clin.table.allergy-state">allergy_state</a></li><li><a href="gnumed-entire_schema.html#clin.table.clin-aux-note">clin_aux_note</a></li><li><a href="gnumed-entire_schema.html#clin.table.clin-diag">clin_diag</a></li><li><a href="gnumed-entire_schema.html#clin.table.clin-item-ty [...]
-  	<li><a href="gnumed-entire_schema.html#clin.function.add-coded-phrase-text-text-text">add_coded_phrase(text, text, text)</a></li><li><a href="gnumed-entire_schema.html#clin.function.f-del-booster-must-have-base-immunity">f_del_booster_must_have_base_immunity()</a></li><li><a href="gnumed-entire_schema.html#clin.function.f-fk-reviewer-default">f_fk_reviewer_default()</a></li><li><a href="gnumed-entire_schema.html#clin.function.f-ins-booster-must-have-base-immunity">f_ins_booster_must_h [...]
+    	<li><a href="gnumed-entire_schema.html#clin.table.-enum-allergy-type">_enum_allergy_type</a></li><li><a href="gnumed-entire_schema.html#clin.table.allergy">allergy</a></li><li><a href="gnumed-entire_schema.html#clin.table.allergy-state">allergy_state</a></li><li><a href="gnumed-entire_schema.html#clin.table.clin-aux-note">clin_aux_note</a></li><li><a href="gnumed-entire_schema.html#clin.table.clin-diag">clin_diag</a></li><li><a href="gnumed-entire_schema.html#clin.table.clin-item-ty [...]
+  	<li><a href="gnumed-entire_schema.html#clin.function.-get-recommendation-for-patient-hint-text-integer">_get_recommendation_for_patient_hint(text, integer)</a></li><li><a href="gnumed-entire_schema.html#clin.function.add-coded-phrase-text-text-text">add_coded_phrase(text, text, text)</a></li><li><a href="gnumed-entire_schema.html#clin.function.f-del-booster-must-have-base-immunity">f_del_booster_must_have_base_immunity()</a></li><li><a href="gnumed-entire_schema.html#clin.function.f-f [...]
     </ul>
     
     <li><a name="de-de.schema">de_de</a></li><ul>
-    	<li><a href="gnumed-entire_schema.html#de-de.table.beh-fall-typ">beh_fall_typ</a></li><li><a href="gnumed-entire_schema.html#de-de.table.behandlungsfall">behandlungsfall</a></li><li><a href="gnumed-entire_schema.html#de-de.table.kvk">kvk</a></li><li><a href="gnumed-entire_schema.html#de-de.table.lab-test-gnr">lab_test_gnr</a></li><li><a href="gnumed-entire_schema.html#de-de.table.payment-method">payment_method</a></li><li><a href="gnumed-entire_schema.html#de-de.table.prax-geb-paid" [...]
+    	<li><a href="gnumed-entire_schema.html#de-de.table.beh-fall-typ">beh_fall_typ</a></li><li><a href="gnumed-entire_schema.html#de-de.table.kvk">kvk</a></li><li><a href="gnumed-entire_schema.html#de-de.table.lab-test-gnr">lab_test_gnr</a></li><li><a href="gnumed-entire_schema.html#de-de.table.payment-method">payment_method</a></li><li><a href="gnumed-entire_schema.html#de-de.table.prax-geb-paid">prax_geb_paid</a></li><li><a href="gnumed-entire_schema.html#de-de.table.zuzahlungsbefreiun [...]
   	
     </ul>
     
     <li><a name="dem.schema">dem</a></li><ul>
-    	<li><a href="gnumed-entire_schema.html#dem.table.address">address</a></li><li><a href="gnumed-entire_schema.html#dem.table.address-type">address_type</a></li><li><a href="gnumed-entire_schema.html#dem.table.country">country</a></li><li><a href="gnumed-entire_schema.html#dem.table.enum-comm-types">enum_comm_types</a></li><li><a href="gnumed-entire_schema.html#dem.table.enum-ext-id-types">enum_ext_id_types</a></li><li><a href="gnumed-entire_schema.html#dem.table.gender-label">gender_l [...]
-  	<li><a href="gnumed-entire_schema.html#dem.function.add-external-id-type-text-text">add_external_id_type(text, text)</a></li><li><a href="gnumed-entire_schema.html#dem.function.add-name-integer-text-text-boolean">add_name(integer, text, text, boolean)</a></li><li><a href="gnumed-entire_schema.html#dem.function.address-exists-text-text-text-text-text-text-text">address_exists(text, text, text, text, text, text, text)</a></li><li><a href="gnumed-entire_schema.html#dem.function.create-ad [...]
+    	<li><a href="gnumed-entire_schema.html#dem.table.address">address</a></li><li><a href="gnumed-entire_schema.html#dem.table.address-type">address_type</a></li><li><a href="gnumed-entire_schema.html#dem.table.country">country</a></li><li><a href="gnumed-entire_schema.html#dem.table.enum-comm-types">enum_comm_types</a></li><li><a href="gnumed-entire_schema.html#dem.table.enum-ext-id-types">enum_ext_id_types</a></li><li><a href="gnumed-entire_schema.html#dem.table.gender-label">gender_l [...]
+  	<li><a href="gnumed-entire_schema.html#dem.function.add-external-id-type-text-text">add_external_id_type(text, text)</a></li><li><a href="gnumed-entire_schema.html#dem.function.add-name-integer-text-text-boolean">add_name(integer, text, text, boolean)</a></li><li><a href="gnumed-entire_schema.html#dem.function.address-exists-text-text-text-text-text-text-text">address_exists(text, text, text, text, text, text, text)</a></li><li><a href="gnumed-entire_schema.html#dem.function.create-ad [...]
     </ul>
     
     <li><a name="gm.schema">gm</a></li><ul>
     	<li><a href="gnumed-entire_schema.html#gm.table.access-log">access_log</a></li><li><a href="gnumed-entire_schema.html#gm.table.notifying-tables">notifying_tables</a></li><li><a href="gnumed-entire_schema.html#gm.table.schema-revision">schema_revision</a></li>
-  	<li><a href="gnumed-entire_schema.html#gm.function.add-missing-array-bits">add_missing_array_bits()</a></li><li><a href="gnumed-entire_schema.html#gm.function.add-table-for-notifies-name-name">add_table_for_notifies(name, name)</a></li><li><a href="gnumed-entire_schema.html#gm.function.add-user-to-permission-group-name-name">add_user_to_permission_group(name, name)</a></li><li><a href="gnumed-entire_schema.html#gm.function.array-unnest-anyarray">array_unnest(anyarray)</a></li><li><a h [...]
+  	<li><a href="gnumed-entire_schema.html#gm.function.account-is-dbowner-or-staff-account-name">account_is_dbowner_or_staff(_account name)</a></li><li><a href="gnumed-entire_schema.html#gm.function.add-missing-array-bits">add_missing_array_bits()</a></li><li><a href="gnumed-entire_schema.html#gm.function.add-table-for-notifies-name-name">add_table_for_notifies(name, name)</a></li><li><a href="gnumed-entire_schema.html#gm.function.add-user-to-permission-group-name-name">add_user_to_permis [...]
     </ul>
     
     <li><a name="i18n.schema">i18n</a></li><ul>
@@ -166,6 +166,11 @@
   	<li><a href="gnumed-entire_schema.html#i18n.function.-text">_(text)</a></li><li><a href="gnumed-entire_schema.html#i18n.function.-text-text">_(text, text)</a></li><li><a href="gnumed-entire_schema.html#i18n.function.force-curr-lang-text">force_curr_lang(text)</a></li><li><a href="gnumed-entire_schema.html#i18n.function.force-curr-lang-text-name">force_curr_lang(text, name)</a></li><li><a href="gnumed-entire_schema.html#i18n.function.get-curr-lang">get_curr_lang()</a></li><li><a href=" [...]
     </ul>
     
+    <li><a name="pgtrgm.schema">pgtrgm</a></li><ul>
+    	
+  	<li><a href="gnumed-entire_schema.html#pgtrgm.function.gin-extract-query-trgm-text-internal-smallint-internal-internal-internal-internal">gin_extract_query_trgm(text, internal, smallint, internal, internal, internal, internal)</a></li><li><a href="gnumed-entire_schema.html#pgtrgm.function.gin-extract-value-trgm-text-internal">gin_extract_value_trgm(text, internal)</a></li><li><a href="gnumed-entire_schema.html#pgtrgm.function.gin-trgm-consistent-internal-smallint-text-integer-internal [...]
+    </ul>
+    
     <li><a name="public.schema">public</a></li><ul>
     	<li><a href="gnumed-entire_schema.html#public.table.basic-unit">basic_unit</a></li><li><a href="gnumed-entire_schema.html#public.table.form-field-types">form_field_types</a></li><li><a href="gnumed-entire_schema.html#public.table.form-fields">form_fields</a></li><li><a href="gnumed-entire_schema.html#public.table.form-job-queue">form_job_queue</a></li><li><a href="gnumed-entire_schema.html#public.table.form-job-targets">form_job_targets</a></li><li><a href="gnumed-entire_schema.html [...]
   	<li><a href="gnumed-entire_schema.html#public.function.-text">_(text)</a></li><li><a href="gnumed-entire_schema.html#public.function.-text-text">_(text, text)</a></li><li><a href="gnumed-entire_schema.html#public.function.f-rfi-type2item">f_rfi_type2item()</a></li><li><a href="gnumed-entire_schema.html#public.function.f-set-encounter-timezone">f_set_encounter_timezone()</a></li>
@@ -263,11 +268,19 @@
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -488,6 +501,11 @@ this referral.
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>clin_root_item_sane_soap_cat</td>
                 <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
             </tr>
@@ -630,6 +648,21 @@ this referral.
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>audit.audit_fields Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
@@ -824,6 +857,21 @@ this referral.
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -1222,6 +1270,21 @@ this referral.
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -1578,6 +1641,21 @@ this referral.
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -2062,6 +2140,21 @@ this referral.
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -2386,6 +2479,21 @@ this referral.
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -2731,6 +2839,22 @@ this referral.
 				</td>
 			 </tr>
             
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>recommendation_query</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
         </table>
 
         <!-- Inherits -->
@@ -2758,6 +2882,21 @@ this referral.
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -3066,6 +3205,21 @@ this referral.
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -3093,13 +3247,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-behandlungsfall">log_behandlungsfall</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-bill">log_bill</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_behandlungsfall Structure</caption>
+                <caption>audit.log_bill Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -3239,6 +3393,54 @@ this referral.
 				<td>
                 
                 </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
             	<td>pk</td>
             	<td>integer</td>
                 <td><i>
@@ -3251,11 +3453,59 @@ this referral.
 				</td>
 			 </tr>
             
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>invoice_id</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
             <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>fk_patient</td>
+            	<td>close_date</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>apply_vat</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>fk_receiver_identity</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -3271,7 +3521,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_falltyp</td>
+            	<td>fk_receiver_address</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -3287,8 +3537,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>started</td>
-            	<td>date</td>
+            	<td>fk_doc</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -3303,8 +3553,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>must_pay_prax_geb</td>
-            	<td>boolean</td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -3319,7 +3569,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_behandlungsfall Inherits
+        <p>Table audit.log_bill Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -3335,13 +3585,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_behandlungsfall Constraints</caption>
+            <caption>audit.log_bill Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -3369,13 +3634,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-bill">log_bill</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-bill-item">log_bill_item</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_bill Structure</caption>
+                <caption>audit.log_bill_item Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -3579,7 +3844,55 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>invoice_id</td>
+            	<td>fk_provider</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>date_to_bill</td>
+            	<td>date</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>description</td>
             	<td>text</td>
                 <td><i>
 				
@@ -3591,12 +3904,28 @@ this referral.
 				</td>
 			 </tr>
             
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>net_amount_per_unit</td>
+            	<td>numeric</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
             <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>close_date</td>
-            	<td>timestamp with time zone</td>
+            	<td>currency</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -3611,8 +3940,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>apply_vat</td>
-            	<td>boolean</td>
+            	<td>status</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -3627,7 +3956,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_receiver_identity</td>
+            	<td>fk_billable</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -3643,7 +3972,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_receiver_address</td>
+            	<td>fk_bill</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -3659,7 +3988,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_doc</td>
+            	<td>unit_count</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -3675,8 +4004,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>amount_multiplier</td>
+            	<td>numeric</td>
                 <td><i>
 				
 
@@ -3691,7 +4020,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_bill Inherits
+        <p>Table audit.log_bill_item Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -3707,13 +4036,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_bill Constraints</caption>
+            <caption>audit.log_bill_item Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -3741,13 +4085,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-bill-item">log_bill_item</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-billable">log_billable</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_bill_item Structure</caption>
+                <caption>audit.log_billable Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -3887,7 +4231,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
+            	<td>pk_coding_system</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -3903,8 +4247,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>code</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -3919,8 +4263,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>term</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -3935,7 +4279,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
+            	<td>fk_data_source</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -3951,8 +4295,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_provider</td>
-            	<td>integer</td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -3967,7 +4311,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_encounter</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -3983,39 +4327,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>date_to_bill</td>
-            	<td>date</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>description</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>net_amount_per_unit</td>
+            	<td>amount</td>
             	<td>numeric</td>
                 <td><i>
 				
@@ -4047,40 +4359,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>status</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>fk_billable</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>fk_bill</td>
-            	<td>integer</td>
+            	<td>vat_multiplier</td>
+            	<td>numeric</td>
                 <td><i>
 				
 
@@ -4095,8 +4375,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>unit_count</td>
-            	<td>integer</td>
+            	<td>active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -4111,8 +4391,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>amount_multiplier</td>
-            	<td>numeric</td>
+            	<td>discountable</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -4127,7 +4407,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_bill_item Inherits
+        <p>Table audit.log_billable Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -4143,13 +4423,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_bill_item Constraints</caption>
+            <caption>audit.log_billable Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -4177,13 +4472,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-billable">log_billable</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-branded-drug">log_branded_drug</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_billable Structure</caption>
+                <caption>audit.log_branded_drug Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -4323,7 +4618,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk_coding_system</td>
+            	<td>row_version</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -4339,8 +4634,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>code</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -4355,8 +4650,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>term</td>
-            	<td>text</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
@@ -4371,7 +4666,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_data_source</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -4387,7 +4682,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>comment</td>
+            	<td>description</td>
             	<td>text</td>
                 <td><i>
 				
@@ -4403,8 +4698,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
-            	<td>integer</td>
+            	<td>preparation</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -4419,8 +4714,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>amount</td>
-            	<td>numeric</td>
+            	<td>atc_code</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -4435,8 +4730,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>currency</td>
-            	<td>text</td>
+            	<td>is_fake</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -4451,8 +4746,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>vat_multiplier</td>
-            	<td>numeric</td>
+            	<td>fk_data_source</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -4467,8 +4762,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>active</td>
-            	<td>boolean</td>
+            	<td>external_code</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -4483,8 +4778,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>discountable</td>
-            	<td>boolean</td>
+            	<td>external_code_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -4499,7 +4794,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_billable Inherits
+        <p>Table audit.log_branded_drug Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -4515,13 +4810,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_billable Constraints</caption>
+            <caption>audit.log_branded_drug Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -4549,13 +4859,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-branded-drug">log_branded_drug</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-clin-aux-note">log_clin_aux_note</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_branded_drug Structure</caption>
+                <caption>audit.log_clin_aux_note Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -4743,7 +5053,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
+            	<td>pk_item</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -4759,8 +5069,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>description</td>
-            	<td>text</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -4775,8 +5085,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>preparation</td>
-            	<td>text</td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -4791,8 +5101,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>atc_code</td>
-            	<td>text</td>
+            	<td>fk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -4807,8 +5117,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>is_fake</td>
-            	<td>boolean</td>
+            	<td>narrative</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -4823,23 +5133,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_data_source</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>external_code</td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -4851,12 +5145,12 @@ this referral.
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>external_code_type</td>
-            	<td>text</td>
+            	<td>pk</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -4871,7 +5165,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_branded_drug Inherits
+        <p>Table audit.log_clin_aux_note Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -4887,13 +5181,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_branded_drug Constraints</caption>
+            <caption>audit.log_clin_aux_note Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -4921,13 +5230,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-clin-aux-note">log_clin_aux_note</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-clin-diag">log_clin_diag</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_clin_aux_note Structure</caption>
+                <caption>audit.log_clin_diag Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -5115,7 +5424,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -5131,8 +5440,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>fk_narrative</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -5147,8 +5456,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_encounter</td>
-            	<td>integer</td>
+            	<td>laterality</td>
+            	<td>bpchar</td>
                 <td><i>
 				
 
@@ -5163,8 +5472,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_episode</td>
-            	<td>integer</td>
+            	<td>is_chronic</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -5179,8 +5488,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>narrative</td>
-            	<td>text</td>
+            	<td>is_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -5195,8 +5504,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>is_definite</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -5211,8 +5520,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
-            	<td>integer</td>
+            	<td>clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -5227,7 +5536,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_clin_aux_note Inherits
+        <p>Table audit.log_clin_diag Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -5243,13 +5552,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_clin_aux_note Constraints</caption>
+            <caption>audit.log_clin_diag Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -5277,13 +5601,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-clin-diag">log_clin_diag</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-clin-item-type">log_clin_item_type</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_clin_diag Structure</caption>
+                <caption>audit.log_clin_item_type Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -5487,72 +5811,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_narrative</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>laterality</td>
-            	<td>bpchar</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>is_chronic</td>
-            	<td>boolean</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>is_active</td>
-            	<td>boolean</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>is_definite</td>
-            	<td>boolean</td>
+            	<td>type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -5567,8 +5827,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>clinically_relevant</td>
-            	<td>boolean</td>
+            	<td>code</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -5583,7 +5843,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_clin_diag Inherits
+        <p>Table audit.log_clin_item_type Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -5599,13 +5859,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_clin_diag Constraints</caption>
+            <caption>audit.log_clin_item_type Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -5633,13 +5908,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-clin-item-type">log_clin_item_type</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-clin-narrative">log_clin_narrative</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_clin_item_type Structure</caption>
+                <caption>audit.log_clin_narrative Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -5827,7 +6102,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
+            	<td>pk_item</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -5843,8 +6118,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>type</td>
-            	<td>text</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -5859,7 +6134,55 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>code</td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>fk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>narrative</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -5871,11 +6194,27 @@ this referral.
 				</td>
 			 </tr>
             
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
         </table>
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_clin_item_type Inherits
+        <p>Table audit.log_clin_narrative Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -5891,13 +6230,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_clin_item_type Constraints</caption>
+            <caption>audit.log_clin_narrative Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -5925,13 +6279,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-clin-narrative">log_clin_narrative</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-consumable-substance">log_consumable_substance</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_clin_narrative Structure</caption>
+                <caption>audit.log_consumable_substance Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -6119,39 +6473,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>fk_encounter</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -6167,8 +6489,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_episode</td>
-            	<td>integer</td>
+            	<td>description</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -6183,7 +6505,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>narrative</td>
+            	<td>atc_code</td>
             	<td>text</td>
                 <td><i>
 				
@@ -6199,8 +6521,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>amount</td>
+            	<td>numeric</td>
                 <td><i>
 				
 
@@ -6215,8 +6537,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
-            	<td>integer</td>
+            	<td>unit</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -6231,7 +6553,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_clin_narrative Inherits
+        <p>Table audit.log_consumable_substance Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -6247,13 +6569,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_clin_narrative Constraints</caption>
+            <caption>audit.log_consumable_substance Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -6281,13 +6618,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-consumable-substance">log_consumable_substance</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-consumed-substance">log_consumed_substance</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_consumable_substance Structure</caption>
+                <caption>audit.log_consumed_substance Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -6519,43 +6856,11 @@ this referral.
 				</td>
 			 </tr>
             
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>amount</td>
-            	<td>numeric</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>unit</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
         </table>
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_consumable_substance Inherits
+        <p>Table audit.log_consumed_substance Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -6571,13 +6876,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_consumable_substance Constraints</caption>
+            <caption>audit.log_consumed_substance Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -6605,13 +6925,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-consumed-substance">log_consumed_substance</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-data-source">log_data_source</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_consumed_substance Structure</caption>
+                <caption>audit.log_data_source Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -6815,6 +7135,54 @@ this referral.
 				<td>
                 
                 </td>
+            	<td>name_short</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>name_long</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>version</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
             	<td>description</td>
             	<td>text</td>
                 <td><i>
@@ -6827,11 +7195,27 @@ this referral.
 				</td>
 			 </tr>
             
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>source</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
             <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>atc_code</td>
+            	<td>lang</td>
             	<td>text</td>
                 <td><i>
 				
@@ -6847,7 +7231,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_consumed_substance Inherits
+        <p>Table audit.log_data_source Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -6863,13 +7247,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_consumed_substance Constraints</caption>
+            <caption>audit.log_data_source Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -6897,13 +7296,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-data-source">log_data_source</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-doc-desc">log_doc_desc</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_data_source Structure</caption>
+                <caption>audit.log_doc_desc Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -7107,8 +7506,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>name_short</td>
-            	<td>text</td>
+            	<td>fk_doc</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -7123,71 +7522,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>name_long</td>
             	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>version</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>description</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>source</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>lang</td>
             	<td>text</td>
                 <td><i>
 				
@@ -7203,7 +7538,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_data_source Inherits
+        <p>Table audit.log_doc_desc Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -7219,13 +7554,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_data_source Constraints</caption>
+            <caption>audit.log_doc_desc Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -7253,13 +7603,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-doc-desc">log_doc_desc</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-doc-med">log_doc_med</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_doc_desc Structure</caption>
+                <caption>audit.log_doc_med Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -7463,7 +7813,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_doc</td>
+            	<td>fk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -7479,7 +7829,71 @@ this referral.
 				<td>
                 
                 </td>
+            	<td>fk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>fk_type</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>comment</td>
             	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>ext_ref</td>
             	<td>text</td>
                 <td><i>
 				
@@ -7491,11 +7905,27 @@ this referral.
 				</td>
 			 </tr>
             
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>fk_org_unit</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
         </table>
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_doc_desc Inherits
+        <p>Table audit.log_doc_med Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -7511,13 +7941,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_doc_desc Constraints</caption>
+            <caption>audit.log_doc_med Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -7545,13 +7990,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-doc-med">log_doc_med</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-encounter">log_encounter</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_doc_med Structure</caption>
+                <caption>audit.log_encounter Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -7755,7 +8200,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_encounter</td>
+            	<td>fk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -7771,7 +8216,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_episode</td>
+            	<td>fk_type</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -7787,7 +8232,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_type</td>
+            	<td>fk_location</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -7803,7 +8248,39 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>comment</td>
+            	<td>source_time_zone</td>
+            	<td>interval</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>reason_for_encounter</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>assessment_of_encounter</td>
             	<td>text</td>
                 <td><i>
 				
@@ -7819,7 +8296,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
+            	<td>started</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
@@ -7835,8 +8312,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>ext_ref</td>
-            	<td>text</td>
+            	<td>last_affirmed</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -7851,7 +8328,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_doc_med Inherits
+        <p>Table audit.log_encounter Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -7867,13 +8344,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_doc_med Constraints</caption>
+            <caption>audit.log_encounter Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -7901,13 +8393,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-encounter">log_encounter</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-episode">log_episode</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_encounter Structure</caption>
+                <caption>audit.log_episode Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -8111,7 +8603,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_patient</td>
+            	<td>fk_health_issue</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -8127,8 +8619,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_type</td>
-            	<td>integer</td>
+            	<td>description</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -8143,8 +8635,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_location</td>
-            	<td>integer</td>
+            	<td>is_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -8159,8 +8651,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>source_time_zone</td>
-            	<td>interval</td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -8175,7 +8667,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>reason_for_encounter</td>
+            	<td>diagnostic_certainty_classification</td>
             	<td>text</td>
                 <td><i>
 				
@@ -8191,7 +8683,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>assessment_of_encounter</td>
+            	<td>summary</td>
             	<td>text</td>
                 <td><i>
 				
@@ -8203,43 +8695,11 @@ this referral.
 				</td>
 			 </tr>
             
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>started</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>last_affirmed</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
         </table>
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_encounter Inherits
+        <p>Table audit.log_episode Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -8255,13 +8715,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_encounter Constraints</caption>
+            <caption>audit.log_episode Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -8289,13 +8764,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-episode">log_episode</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-external-care">log_external_care</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_episode Structure</caption>
+                <caption>audit.log_external_care Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -8499,7 +8974,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_health_issue</td>
+            	<td>fk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -8515,8 +8990,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>description</td>
-            	<td>text</td>
+            	<td>fk_health_issue</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -8531,8 +9006,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>is_open</td>
-            	<td>boolean</td>
+            	<td>issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -8547,7 +9022,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_encounter</td>
+            	<td>fk_org_unit</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -8563,7 +9038,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>diagnostic_certainty_classification</td>
+            	<td>provider</td>
             	<td>text</td>
                 <td><i>
 				
@@ -8579,7 +9054,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>summary</td>
+            	<td>comment</td>
             	<td>text</td>
                 <td><i>
 				
@@ -8595,7 +9070,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_episode Inherits
+        <p>Table audit.log_external_care Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -8611,13 +9086,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_episode Constraints</caption>
+            <caption>audit.log_external_care Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -8645,13 +9135,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-external-care">log_external_care</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-family-history">log_family_history</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_external_care Structure</caption>
+                <caption>audit.log_family_history Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -8669,7 +9159,7 @@ this referral.
 				
 
 				NOT NULL
-				DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
+				DEFAULT nextval('audit_trail_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -8839,7 +9329,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
+            	<td>pk_item</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -8855,6 +9345,22 @@ this referral.
 				<td>
                 
                 </td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
             	<td>fk_encounter</td>
             	<td>integer</td>
                 <td><i>
@@ -8867,11 +9373,11 @@ this referral.
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>fk_health_issue</td>
+            	<td>fk_episode</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -8883,11 +9389,27 @@ this referral.
 				</td>
 			 </tr>
             
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>narrative</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>issue</td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -8903,7 +9425,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_org_unit</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -8919,7 +9441,71 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>provider</td>
+            	<td>fk_relation_type</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>age_noted</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>age_of_death</td>
+            	<td>interval</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>contributed_to_death</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>name_relative</td>
             	<td>text</td>
                 <td><i>
 				
@@ -8935,6 +9521,22 @@ this referral.
 				<td>
                 
                 </td>
+            	<td>dob_relative</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
             	<td>comment</td>
             	<td>text</td>
                 <td><i>
@@ -8951,7 +9553,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_external_care Inherits
+        <p>Table audit.log_family_history Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -8967,13 +9569,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_external_care Constraints</caption>
+            <caption>audit.log_family_history Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -9001,13 +9618,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-family-history">log_family_history</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-fhx-relation-type">log_fhx_relation_type</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_family_history Structure</caption>
+                <caption>audit.log_fhx_relation_type Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -9195,7 +9812,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -9211,8 +9828,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>description</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -9227,8 +9844,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_encounter</td>
-            	<td>integer</td>
+            	<td>is_genetic</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -9239,17 +9856,100 @@ this referral.
 				</td>
 			 </tr>
             
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table audit.log_fhx_relation_type Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>audit.log_fhx_relation_type Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_trail_audit_action_check</td>
+                <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#audit.schema">Schema audit</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-form-data">log_form_data</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>audit.log_form_data Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>fk_episode</td>
+            	<td>pk_audit</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit_trail_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -9259,15 +9959,47 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>narrative</td>
-            	<td>text</td>
+            	<td>orig_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
+				NOT NULL
+				
+				</i>
+				<br><br>the .row_version in the original row before the audited action took place, should be equal to .row_version
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>orig_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
 				
+
+				NOT NULL
 				
 				</i>
+				<br><br>the .modified_when in the original row before the audited action took place, should be equal to .modified_when
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>orig_by</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				NOT NULL
 				
+				</i>
+				<br><br>the .modified_by in the original row before the audited action took place, should be equal to .modified_by
 				</td>
 			 </tr>
             
@@ -9275,29 +10007,61 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>orig_tableoid</td>
+            	<td>oid</td>
                 <td><i>
 				
 
+				NOT NULL
 				
+				</i>
+				<br><br>the TG_RELID when the audit trigger was run
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>audit_action</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				NOT NULL
 				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk</td>
-            	<td>integer</td>
+            	<td>audit_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
+				NOT NULL
+				DEFAULT now()
+				</i>
 				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>audit_by</td>
+            	<td>name</td>
+                <td><i>
 				
+
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -9307,7 +10071,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_relation_type</td>
+            	<td>row_version</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -9323,8 +10087,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>age_noted</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -9339,8 +10103,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>age_of_death</td>
-            	<td>interval</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
@@ -9355,8 +10119,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>contributed_to_death</td>
-            	<td>boolean</td>
+            	<td>pk</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -9371,8 +10135,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>name_relative</td>
-            	<td>text</td>
+            	<td>fk_instance</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -9387,8 +10151,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>dob_relative</td>
-            	<td>timestamp with time zone</td>
+            	<td>fk_form_field</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -9403,7 +10167,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>comment</td>
+            	<td>value</td>
             	<td>text</td>
                 <td><i>
 				
@@ -9419,7 +10183,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_family_history Inherits
+        <p>Table audit.log_form_data Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -9435,13 +10199,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_family_history Constraints</caption>
+            <caption>audit.log_form_data Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -9469,13 +10248,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-fhx-relation-type">log_fhx_relation_type</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-form-instances">log_form_instances</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_fhx_relation_type Structure</caption>
+                <caption>audit.log_form_instances Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -9663,7 +10442,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
+            	<td>pk_item</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -9679,7 +10458,71 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>description</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>fk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>narrative</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -9695,8 +10538,40 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>is_genetic</td>
-            	<td>boolean</td>
+            	<td>pk</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>fk_form_def</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>form_name</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -9711,7 +10586,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_fhx_relation_type Inherits
+        <p>Table audit.log_form_instances Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -9727,13 +10602,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_fhx_relation_type Constraints</caption>
+            <caption>audit.log_form_instances Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -9761,13 +10651,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-form-data">log_form_data</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-gender-label">log_gender_label</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_form_data Structure</caption>
+                <caption>audit.log_gender_label Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -9971,8 +10861,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_instance</td>
-            	<td>integer</td>
+            	<td>tag</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -9987,8 +10877,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_form_field</td>
-            	<td>integer</td>
+            	<td>label</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -10003,7 +10893,23 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>value</td>
+            	<td>sort_weight</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>comment</td>
             	<td>text</td>
                 <td><i>
 				
@@ -10019,7 +10925,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_form_data Inherits
+        <p>Table audit.log_gender_label Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -10035,13 +10941,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_form_data Constraints</caption>
+            <caption>audit.log_gender_label Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -10069,13 +10990,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-form-instances">log_form_instances</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-health-issue">log_health_issue</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_form_instances Structure</caption>
+                <caption>audit.log_health_issue Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -10263,7 +11184,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -10279,8 +11200,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>description</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -10295,8 +11216,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_encounter</td>
-            	<td>integer</td>
+            	<td>laterality</td>
+            	<td>character varying</td>
                 <td><i>
 				
 
@@ -10311,8 +11232,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_episode</td>
-            	<td>integer</td>
+            	<td>age_noted</td>
+            	<td>interval</td>
                 <td><i>
 				
 
@@ -10327,8 +11248,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>narrative</td>
-            	<td>text</td>
+            	<td>is_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -10343,8 +11264,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -10359,8 +11280,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
-            	<td>integer</td>
+            	<td>is_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -10375,7 +11296,23 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_form_def</td>
+            	<td>is_cause_of_death</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>fk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -10387,11 +11324,43 @@ this referral.
 				</td>
 			 </tr>
             
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>grouping</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
             <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>form_name</td>
+            	<td>diagnostic_certainty_classification</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>summary</td>
             	<td>text</td>
                 <td><i>
 				
@@ -10407,7 +11376,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_form_instances Inherits
+        <p>Table audit.log_health_issue Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -10423,13 +11392,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_form_instances Constraints</caption>
+            <caption>audit.log_health_issue Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -10457,13 +11441,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-gender-label">log_gender_label</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-hospital-stay">log_hospital_stay</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_gender_label Structure</caption>
+                <caption>audit.log_hospital_stay Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -10651,7 +11635,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
+            	<td>pk_item</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -10667,8 +11651,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>tag</td>
-            	<td>text</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -10683,8 +11667,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>label</td>
-            	<td>text</td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -10699,7 +11683,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>sort_weight</td>
+            	<td>fk_episode</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -10715,7 +11699,23 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>comment</td>
+            	<td>narrative</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -10727,11 +11727,59 @@ this referral.
 				</td>
 			 </tr>
             
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>discharge</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>fk_org_unit</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
         </table>
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_gender_label Inherits
+        <p>Table audit.log_hospital_stay Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -10747,13 +11795,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_gender_label Constraints</caption>
+            <caption>audit.log_hospital_stay Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -10781,13 +11844,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-health-issue">log_health_issue</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-hx-family-item">log_hx_family_item</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_health_issue Structure</caption>
+                <caption>audit.log_hx_family_item Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -10991,40 +12054,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>description</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>laterality</td>
-            	<td>character varying</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>age_noted</td>
-            	<td>interval</td>
+            	<td>fk_narrative_condition</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -11039,8 +12070,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>is_active</td>
-            	<td>boolean</td>
+            	<td>fk_relative</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -11055,8 +12086,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>clinically_relevant</td>
-            	<td>boolean</td>
+            	<td>name_relative</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -11071,8 +12102,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>is_confidential</td>
-            	<td>boolean</td>
+            	<td>dob_relative</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -11087,8 +12118,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>is_cause_of_death</td>
-            	<td>boolean</td>
+            	<td>condition</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -11103,8 +12134,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_encounter</td>
-            	<td>integer</td>
+            	<td>age_noted</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -11119,8 +12150,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>grouping</td>
-            	<td>text</td>
+            	<td>age_of_death</td>
+            	<td>interval</td>
                 <td><i>
 				
 
@@ -11135,24 +12166,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>diagnostic_certainty_classification</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>summary</td>
-            	<td>text</td>
+            	<td>is_cause_of_death</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -11167,7 +12182,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_health_issue Inherits
+        <p>Table audit.log_hx_family_item Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -11183,13 +12198,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_health_issue Constraints</caption>
+            <caption>audit.log_hx_family_item Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -11217,13 +12247,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-hospital-stay">log_hospital_stay</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-identity">log_identity</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_hospital_stay Structure</caption>
+                <caption>audit.log_identity Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -11411,7 +12441,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -11427,7 +12457,39 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
+            	<td>deleted</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>gender</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>dob</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
@@ -11443,7 +12505,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_encounter</td>
+            	<td>fk_marital_status</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -11459,8 +12521,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_episode</td>
-            	<td>integer</td>
+            	<td>cob</td>
+            	<td>bpchar</td>
                 <td><i>
 				
 
@@ -11475,7 +12537,23 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>narrative</td>
+            	<td>deceased</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>title</td>
             	<td>text</td>
                 <td><i>
 				
@@ -11487,11 +12565,27 @@ this referral.
 				</td>
 			 </tr>
             
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>tob</td>
+            	<td>time without time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
+            	<td>emergency_contact</td>
             	<td>text</td>
                 <td><i>
 				
@@ -11507,7 +12601,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
+            	<td>fk_emergency_contact</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -11523,8 +12617,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>discharge</td>
-            	<td>timestamp with time zone</td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -11539,7 +12633,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_org_unit</td>
+            	<td>fk_primary_provider</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -11551,11 +12645,27 @@ this referral.
 				</td>
 			 </tr>
             
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>dob_is_estimated</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
         </table>
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_hospital_stay Inherits
+        <p>Table audit.log_identity Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -11571,13 +12681,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_hospital_stay Constraints</caption>
+            <caption>audit.log_identity Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -11605,13 +12730,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-hx-family-item">log_hx_family_item</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-identity-tag">log_identity_tag</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_hx_family_item Structure</caption>
+                <caption>audit.log_identity_tag Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -11815,7 +12940,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_narrative_condition</td>
+            	<td>fk_identity</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -11831,7 +12956,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_relative</td>
+            	<td>fk_tag</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -11847,7 +12972,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>name_relative</td>
+            	<td>comment</td>
             	<td>text</td>
                 <td><i>
 				
@@ -11859,19 +12984,150 @@ this referral.
 				</td>
 			 </tr>
             
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table audit.log_identity_tag Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>audit.log_identity_tag Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
             <tr class="tr1">
+				<td>audit_trail_audit_action_check</td>
+                <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#audit.schema">Schema audit</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-inbox-item-category">log_inbox_item_category</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>audit.log_inbox_item_category Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>dob_relative</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
                 <td><i>
 				
 
+				NOT NULL
+				DEFAULT nextval('audit_trail_pk_audit_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>orig_version</td>
+            	<td>integer</td>
+                <td><i>
 				
+
+				NOT NULL
 				
 				</i>
+				<br><br>the .row_version in the original row before the audited action took place, should be equal to .row_version
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>orig_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
 				
+
+				NOT NULL
+				
+				</i>
+				<br><br>the .modified_when in the original row before the audited action took place, should be equal to .modified_when
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>orig_by</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>the .modified_by in the original row before the audited action took place, should be equal to .modified_by
 				</td>
 			 </tr>
             
@@ -11879,13 +13135,45 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>condition</td>
+            	<td>orig_tableoid</td>
+            	<td>oid</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>the TG_RELID when the audit trigger was run
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>audit_action</td>
             	<td>text</td>
                 <td><i>
 				
 
+				NOT NULL
 				
+				</i>
 				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>audit_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -11895,8 +13183,40 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>age_noted</td>
-            	<td>text</td>
+            	<td>audit_by</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT "current_user"()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -11911,8 +13231,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>age_of_death</td>
-            	<td>interval</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
@@ -11927,7 +13247,39 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>is_cause_of_death</td>
+            	<td>pk</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>description</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>is_user</td>
             	<td>boolean</td>
                 <td><i>
 				
@@ -11943,7 +13295,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_hx_family_item Inherits
+        <p>Table audit.log_inbox_item_category Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -11959,13 +13311,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_hx_family_item Constraints</caption>
+            <caption>audit.log_inbox_item_category Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -11993,13 +13360,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-identity">log_identity</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-inbox-item-type">log_inbox_item_type</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_identity Structure</caption>
+                <caption>audit.log_inbox_item_type Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -12203,8 +13570,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>deleted</td>
-            	<td>boolean</td>
+            	<td>fk_inbox_item_category</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -12219,8 +13586,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pupic</td>
-            	<td>bpchar</td>
+            	<td>description</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -12235,8 +13602,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>gender</td>
-            	<td>text</td>
+            	<td>is_user</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -12247,33 +13614,100 @@ this referral.
 				</td>
 			 </tr>
             
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table audit.log_inbox_item_type Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>audit.log_inbox_item_type Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
             <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>dob</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_trail_audit_action_check</td>
+                <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
+            </tr>
+			
+		</table>
+		
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#audit.schema">Schema audit</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-incoming-data-unmatchable">log_incoming_data_unmatchable</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>audit.log_incoming_data_unmatchable Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>fk_marital_status</td>
+            	<td>pk_audit</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit_trail_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -12283,15 +13717,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>cob</td>
-            	<td>bpchar</td>
+            	<td>orig_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>the .row_version in the original row before the audited action took place, should be equal to .row_version
 				</td>
 			 </tr>
             
@@ -12299,15 +13733,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>deceased</td>
+            	<td>orig_when</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>the .modified_when in the original row before the audited action took place, should be equal to .modified_when
 				</td>
 			 </tr>
             
@@ -12315,15 +13749,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>title</td>
-            	<td>text</td>
+            	<td>orig_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>the .modified_by in the original row before the audited action took place, should be equal to .modified_by
 				</td>
 			 </tr>
             
@@ -12331,15 +13765,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>tob</td>
-            	<td>time without time zone</td>
+            	<td>orig_tableoid</td>
+            	<td>oid</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>the TG_RELID when the audit trigger was run
 				</td>
 			 </tr>
             
@@ -12347,12 +13781,12 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>emergency_contact</td>
+            	<td>audit_action</td>
             	<td>text</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -12363,13 +13797,13 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_emergency_contact</td>
-            	<td>integer</td>
+            	<td>audit_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -12379,13 +13813,13 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>audit_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -12395,7 +13829,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_primary_provider</td>
+            	<td>row_version</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -12411,8 +13845,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>dob_is_estimated</td>
-            	<td>boolean</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -12423,85 +13857,17 @@ this referral.
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table audit.log_identity Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_identity Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>audit_trail_audit_action_check</td>
-                <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
-            </tr>
-			
-		</table>
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#audit.schema">Schema audit</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-identity-tag">log_identity_tag</a>
-		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_identity_tag Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit_trail_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -12511,15 +13877,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>orig_version</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>the .row_version in the original row before the audited action took place, should be equal to .row_version
+				
 				</td>
 			 </tr>
             
@@ -12527,15 +13893,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>orig_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>fk_patient_candidates</td>
+            	<td>integer[]</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>the .modified_when in the original row before the audited action took place, should be equal to .modified_when
+				
 				</td>
 			 </tr>
             
@@ -12543,15 +13909,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>orig_by</td>
-            	<td>name</td>
+            	<td>request_id</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>the .modified_by in the original row before the audited action took place, should be equal to .modified_by
+				
 				</td>
 			 </tr>
             
@@ -12559,15 +13925,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>orig_tableoid</td>
-            	<td>oid</td>
+            	<td>firstnames</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>the TG_RELID when the audit trigger was run
+				
 				</td>
 			 </tr>
             
@@ -12575,12 +13941,12 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>audit_action</td>
+            	<td>lastnames</td>
             	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -12591,13 +13957,13 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>audit_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>dob</td>
+            	<td>date</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -12607,13 +13973,13 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>audit_by</td>
-            	<td>name</td>
+            	<td>postcode</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -12623,8 +13989,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>other_info</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -12639,8 +14005,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -12655,8 +14021,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>data</td>
+            	<td>bytea</td>
                 <td><i>
 				
 
@@ -12671,8 +14037,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
-            	<td>integer</td>
+            	<td>gender</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -12687,8 +14053,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_identity</td>
-            	<td>integer</td>
+            	<td>requestor</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -12703,8 +14069,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_tag</td>
-            	<td>integer</td>
+            	<td>external_data_id</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -12719,8 +14085,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>fk_identity_disambiguated</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -12735,7 +14101,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_identity_tag Inherits
+        <p>Table audit.log_incoming_data_unmatchable Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -12751,13 +14117,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_identity_tag Constraints</caption>
+            <caption>audit.log_incoming_data_unmatchable Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -12785,13 +14166,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-inbox-item-category">log_inbox_item_category</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-incoming-data-unmatched">log_incoming_data_unmatched</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_inbox_item_category Structure</caption>
+                <caption>audit.log_incoming_data_unmatched Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -12995,8 +14376,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>description</td>
-            	<td>text</td>
+            	<td>fk_patient_candidates</td>
+            	<td>integer[]</td>
                 <td><i>
 				
 
@@ -13011,8 +14392,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>is_user</td>
-            	<td>boolean</td>
+            	<td>request_id</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -13023,119 +14404,19 @@ this referral.
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table audit.log_inbox_item_category Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_inbox_item_category Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>audit_trail_audit_action_check</td>
-                <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
-            </tr>
-			
-		</table>
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#audit.schema">Schema audit</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-inbox-item-type">log_inbox_item_type</a>
-		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_inbox_item_type Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
+            	<td>firstnames</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit_trail_pk_audit_seq'::regclass)
-				</i>
 				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>orig_version</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
 				
 				</i>
-				<br><br>the .row_version in the original row before the audited action took place, should be equal to .row_version
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>orig_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
 				
-
-				NOT NULL
-				
-				</i>
-				<br><br>the .modified_when in the original row before the audited action took place, should be equal to .modified_when
 				</td>
 			 </tr>
             
@@ -13143,15 +14424,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>orig_by</td>
-            	<td>name</td>
+            	<td>lastnames</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>the .modified_by in the original row before the audited action took place, should be equal to .modified_by
+				
 				</td>
 			 </tr>
             
@@ -13159,15 +14440,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>orig_tableoid</td>
-            	<td>oid</td>
+            	<td>dob</td>
+            	<td>date</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>the TG_RELID when the audit trigger was run
+				
 				</td>
 			 </tr>
             
@@ -13175,12 +14456,12 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>audit_action</td>
+            	<td>postcode</td>
             	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -13191,13 +14472,13 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>audit_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>other_info</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -13207,13 +14488,13 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>audit_by</td>
-            	<td>name</td>
+            	<td>type</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -13223,8 +14504,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>data</td>
+            	<td>bytea</td>
                 <td><i>
 				
 
@@ -13239,8 +14520,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>gender</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -13255,8 +14536,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>requestor</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -13271,8 +14552,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
-            	<td>integer</td>
+            	<td>external_data_id</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -13287,7 +14568,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_inbox_item_category</td>
+            	<td>fk_identity_disambiguated</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -13303,7 +14584,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>description</td>
+            	<td>comment</td>
             	<td>text</td>
                 <td><i>
 				
@@ -13319,8 +14600,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>is_user</td>
-            	<td>boolean</td>
+            	<td>fk_provider_disambiguated</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -13335,7 +14616,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_inbox_item_type Inherits
+        <p>Table audit.log_incoming_data_unmatched Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -13351,13 +14632,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_inbox_item_type Constraints</caption>
+            <caption>audit.log_incoming_data_unmatched Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -13385,13 +14681,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-incoming-data-unmatchable">log_incoming_data_unmatchable</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lab-request">log_lab_request</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_incoming_data_unmatchable Structure</caption>
+                <caption>audit.log_lab_request Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -13579,6 +14875,102 @@ this referral.
 				<td>
                 
                 </td>
+            	<td>pk_item</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>fk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>narrative</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>soap_cat</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
             	<td>pk</td>
             	<td>integer</td>
                 <td><i>
@@ -13595,8 +14987,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_patient_candidates</td>
-            	<td>integer[]</td>
+            	<td>fk_test_org</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -13627,8 +15019,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>firstnames</td>
-            	<td>text</td>
+            	<td>fk_requestor</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -13643,7 +15035,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>lastnames</td>
+            	<td>lab_request_id</td>
             	<td>text</td>
                 <td><i>
 				
@@ -13659,8 +15051,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>dob</td>
-            	<td>date</td>
+            	<td>lab_rxd_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -13675,8 +15067,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>postcode</td>
-            	<td>text</td>
+            	<td>results_reported_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -13691,23 +15083,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>other_info</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>type</td>
+            	<td>request_status</td>
             	<td>text</td>
                 <td><i>
 				
@@ -13719,28 +15095,12 @@ this referral.
 				</td>
 			 </tr>
             
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>data</td>
-            	<td>bytea</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
             <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>gender</td>
-            	<td>text</td>
+            	<td>is_pending</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -13755,7 +15115,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>requestor</td>
+            	<td>diagnostic_service_section</td>
             	<td>text</td>
                 <td><i>
 				
@@ -13771,7 +15131,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>external_data_id</td>
+            	<td>ordered_service</td>
             	<td>text</td>
                 <td><i>
 				
@@ -13787,8 +15147,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_identity_disambiguated</td>
-            	<td>integer</td>
+            	<td>note_test_org</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -13803,7 +15163,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_incoming_data_unmatchable Inherits
+        <p>Table audit.log_lab_request Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -13819,13 +15179,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_incoming_data_unmatchable Constraints</caption>
+            <caption>audit.log_lab_request Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -13853,13 +15228,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-incoming-data-unmatched">log_incoming_data_unmatched</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lab-test-gnr">log_lab_test_gnr</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_incoming_data_unmatched Structure</caption>
+                <caption>audit.log_lab_test_gnr Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -14047,7 +15422,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
+            	<td>id</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -14063,8 +15438,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_patient_candidates</td>
-            	<td>integer[]</td>
+            	<td>id_test</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -14075,19 +15450,118 @@ this referral.
 				</td>
 			 </tr>
             
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table audit.log_lab_test_gnr Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>audit.log_lab_test_gnr Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
             <tr class="tr1">
+				<td>audit_trail_audit_action_check</td>
+                <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#audit.schema">Schema audit</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-code2aoe">log_lnk_code2aoe</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>audit.log_lnk_code2aoe Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>request_id</td>
-            	<td>text</td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
                 <td><i>
 				
 
+				NOT NULL
+				DEFAULT nextval('audit_trail_pk_audit_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>orig_version</td>
+            	<td>integer</td>
+                <td><i>
 				
+
+				NOT NULL
 				
 				</i>
-				
+				<br><br>the .row_version in the original row before the audited action took place, should be equal to .row_version
 				</td>
 			 </tr>
             
@@ -14095,15 +15569,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>firstnames</td>
-            	<td>text</td>
+            	<td>orig_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>the .modified_when in the original row before the audited action took place, should be equal to .modified_when
 				</td>
 			 </tr>
             
@@ -14111,15 +15585,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>lastnames</td>
-            	<td>text</td>
+            	<td>orig_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>the .modified_by in the original row before the audited action took place, should be equal to .modified_by
 				</td>
 			 </tr>
             
@@ -14127,15 +15601,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>dob</td>
-            	<td>date</td>
+            	<td>orig_tableoid</td>
+            	<td>oid</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>the TG_RELID when the audit trigger was run
 				</td>
 			 </tr>
             
@@ -14143,12 +15617,12 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>postcode</td>
+            	<td>audit_action</td>
             	<td>text</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -14159,13 +15633,13 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>other_info</td>
-            	<td>text</td>
+            	<td>audit_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -14175,13 +15649,13 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>type</td>
-            	<td>text</td>
+            	<td>audit_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -14191,8 +15665,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>data</td>
-            	<td>bytea</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -14207,8 +15681,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>gender</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -14223,8 +15697,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>requestor</td>
-            	<td>text</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
@@ -14239,8 +15713,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>external_data_id</td>
-            	<td>text</td>
+            	<td>pk_lnk_code2item</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -14255,7 +15729,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_identity_disambiguated</td>
+            	<td>fk_generic_code</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -14271,8 +15745,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>fk_item</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -14287,7 +15761,23 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_provider_disambiguated</td>
+            	<td>code_modifier</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -14303,7 +15793,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_incoming_data_unmatched Inherits
+        <p>Table audit.log_lnk_code2aoe Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -14319,13 +15809,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_incoming_data_unmatched Constraints</caption>
+            <caption>audit.log_lnk_code2aoe Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -14353,13 +15858,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lab-request">log_lab_request</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-code2episode">log_lnk_code2episode</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lab_request Structure</caption>
+                <caption>audit.log_lnk_code2episode Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -14547,7 +16052,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
+            	<td>pk_lnk_code2item</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -14563,8 +16068,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>fk_generic_code</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -14579,7 +16084,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_encounter</td>
+            	<td>fk_item</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -14595,8 +16100,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_episode</td>
-            	<td>integer</td>
+            	<td>code_modifier</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -14611,8 +16116,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>narrative</td>
-            	<td>text</td>
+            	<td>pk</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -14623,17 +16128,100 @@ this referral.
 				</td>
 			 </tr>
             
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table audit.log_lnk_code2episode Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>audit.log_lnk_code2episode Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_trail_audit_action_check</td>
+                <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#audit.schema">Schema audit</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-code2fhx">log_lnk_code2fhx</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>audit.log_lnk_code2fhx Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit_trail_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -14643,15 +16231,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
+            	<td>orig_version</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>the .row_version in the original row before the audited action took place, should be equal to .row_version
 				</td>
 			 </tr>
             
@@ -14659,15 +16247,47 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_test_org</td>
-            	<td>integer</td>
+            	<td>orig_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
+				NOT NULL
+				
+				</i>
+				<br><br>the .modified_when in the original row before the audited action took place, should be equal to .modified_when
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>orig_by</td>
+            	<td>name</td>
+                <td><i>
 				
+
+				NOT NULL
 				
 				</i>
+				<br><br>the .modified_by in the original row before the audited action took place, should be equal to .modified_by
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>orig_tableoid</td>
+            	<td>oid</td>
+                <td><i>
+				
+
+				NOT NULL
 				
+				</i>
+				<br><br>the TG_RELID when the audit trigger was run
 				</td>
 			 </tr>
             
@@ -14675,12 +16295,12 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>request_id</td>
+            	<td>audit_action</td>
             	<td>text</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -14691,13 +16311,13 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_requestor</td>
-            	<td>integer</td>
+            	<td>audit_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -14707,13 +16327,13 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>lab_request_id</td>
-            	<td>text</td>
+            	<td>audit_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -14723,8 +16343,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>lab_rxd_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -14739,7 +16359,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>results_reported_when</td>
+            	<td>modified_when</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
@@ -14755,8 +16375,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>request_status</td>
-            	<td>text</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
@@ -14771,8 +16391,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>is_pending</td>
-            	<td>boolean</td>
+            	<td>pk_lnk_code2item</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -14787,8 +16407,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>diagnostic_service_section</td>
-            	<td>text</td>
+            	<td>fk_generic_code</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -14803,8 +16423,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>ordered_service</td>
-            	<td>text</td>
+            	<td>fk_item</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -14819,7 +16439,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>note_test_org</td>
+            	<td>code_modifier</td>
             	<td>text</td>
                 <td><i>
 				
@@ -14831,11 +16451,27 @@ this referral.
 				</td>
 			 </tr>
             
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
         </table>
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lab_request Inherits
+        <p>Table audit.log_lnk_code2fhx Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -14851,13 +16487,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lab_request Constraints</caption>
+            <caption>audit.log_lnk_code2fhx Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -14885,13 +16536,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lab-test-gnr">log_lab_test_gnr</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-code2h-issue">log_lnk_code2h_issue</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lab_test_gnr Structure</caption>
+                <caption>audit.log_lnk_code2h_issue Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -15079,7 +16730,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>id</td>
+            	<td>pk_lnk_code2item</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -15095,7 +16746,55 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>id_test</td>
+            	<td>fk_generic_code</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>fk_item</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>code_modifier</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -15111,7 +16810,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lab_test_gnr Inherits
+        <p>Table audit.log_lnk_code2h_issue Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -15127,13 +16826,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lab_test_gnr Constraints</caption>
+            <caption>audit.log_lnk_code2h_issue Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -15161,13 +16875,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-code2aoe">log_lnk_code2aoe</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-code2narrative">log_lnk_code2narrative</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_code2aoe Structure</caption>
+                <caption>audit.log_lnk_code2narrative Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -15435,7 +17149,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_code2aoe Inherits
+        <p>Table audit.log_lnk_code2narrative Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -15451,13 +17165,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_code2aoe Constraints</caption>
+            <caption>audit.log_lnk_code2narrative Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -15485,13 +17214,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-code2episode">log_lnk_code2episode</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-code2procedure">log_lnk_code2procedure</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_code2episode Structure</caption>
+                <caption>audit.log_lnk_code2procedure Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -15759,7 +17488,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_code2episode Inherits
+        <p>Table audit.log_lnk_code2procedure Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -15775,13 +17504,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_code2episode Constraints</caption>
+            <caption>audit.log_lnk_code2procedure Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -15809,13 +17553,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-code2fhx">log_lnk_code2fhx</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-code2rfe">log_lnk_code2rfe</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_code2fhx Structure</caption>
+                <caption>audit.log_lnk_code2rfe Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -16083,7 +17827,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_code2fhx Inherits
+        <p>Table audit.log_lnk_code2rfe Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -16099,13 +17843,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_code2fhx Constraints</caption>
+            <caption>audit.log_lnk_code2rfe Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -16133,13 +17892,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-code2h-issue">log_lnk_code2h_issue</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-code2tst-pnl">log_lnk_code2tst_pnl</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_code2h_issue Structure</caption>
+                <caption>audit.log_lnk_code2tst_pnl Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -16407,7 +18166,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_code2h_issue Inherits
+        <p>Table audit.log_lnk_code2tst_pnl Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -16423,13 +18182,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_code2h_issue Constraints</caption>
+            <caption>audit.log_lnk_code2tst_pnl Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -16457,13 +18231,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-code2narrative">log_lnk_code2narrative</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-constraint2vacc-course">log_lnk_constraint2vacc_course</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_code2narrative Structure</caption>
+                <caption>audit.log_lnk_constraint2vacc_course Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -16651,7 +18425,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk_lnk_code2item</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -16667,7 +18441,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_generic_code</td>
+            	<td>fk_vaccination_course</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -16683,39 +18457,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_item</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>code_modifier</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>pk</td>
+            	<td>fk_constraint</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -16731,7 +18473,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_code2narrative Inherits
+        <p>Table audit.log_lnk_constraint2vacc_course Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -16747,13 +18489,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_code2narrative Constraints</caption>
+            <caption>audit.log_lnk_constraint2vacc_course Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -16781,13 +18538,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-code2procedure">log_lnk_code2procedure</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-identity2ext-id">log_lnk_identity2ext_id</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_code2procedure Structure</caption>
+                <caption>audit.log_lnk_identity2ext_id Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -16975,7 +18732,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk_lnk_code2item</td>
+            	<td>id</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -16991,7 +18748,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_generic_code</td>
+            	<td>id_identity</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -17007,8 +18764,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_item</td>
-            	<td>integer</td>
+            	<td>external_id</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -17023,8 +18780,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>code_modifier</td>
-            	<td>text</td>
+            	<td>fk_origin</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -17039,8 +18796,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
-            	<td>integer</td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -17055,7 +18812,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_code2procedure Inherits
+        <p>Table audit.log_lnk_identity2ext_id Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -17071,13 +18828,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_code2procedure Constraints</caption>
+            <caption>audit.log_lnk_identity2ext_id Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -17105,13 +18877,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-code2rfe">log_lnk_code2rfe</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-identity2primary-doc">log_lnk_identity2primary_doc</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_code2rfe Structure</caption>
+                <caption>audit.log_lnk_identity2primary_doc Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -17251,71 +19023,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>modified_by</td>
-            	<td>name</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>pk_lnk_code2item</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>fk_generic_code</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -17331,7 +19039,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_item</td>
+            	<td>fk_identity</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -17347,23 +19055,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>code_modifier</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>pk</td>
+            	<td>fk_primary_doc</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -17379,7 +19071,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_code2rfe Inherits
+        <p>Table audit.log_lnk_identity2primary_doc Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -17395,13 +19087,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_code2rfe Constraints</caption>
+            <caption>audit.log_lnk_identity2primary_doc Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -17429,13 +19136,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-code2tst-pnl">log_lnk_code2tst_pnl</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-job2person">log_lnk_job2person</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_code2tst_pnl Structure</caption>
+                <caption>audit.log_lnk_job2person Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -17623,7 +19330,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk_lnk_code2item</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -17639,7 +19346,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_generic_code</td>
+            	<td>fk_identity</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -17655,7 +19362,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_item</td>
+            	<td>fk_occupation</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -17671,7 +19378,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>code_modifier</td>
+            	<td>activities</td>
             	<td>text</td>
                 <td><i>
 				
@@ -17683,27 +19390,11 @@ this referral.
 				</td>
 			 </tr>
             
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>pk</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
         </table>
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_code2tst_pnl Inherits
+        <p>Table audit.log_lnk_job2person Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -17719,13 +19410,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_code2tst_pnl Constraints</caption>
+            <caption>audit.log_lnk_job2person Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -17753,13 +19459,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-constraint2vacc-course">log_lnk_constraint2vacc_course</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-org-unit2comm">log_lnk_org_unit2comm</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_constraint2vacc_course Structure</caption>
+                <caption>audit.log_lnk_org_unit2comm Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -17963,7 +19669,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_vaccination_course</td>
+            	<td>fk_org_unit</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -17979,7 +19685,23 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_constraint</td>
+            	<td>url</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>fk_type</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -17991,11 +19713,43 @@ this referral.
 				</td>
 			 </tr>
             
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>is_confidential</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>comment</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
         </table>
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_constraint2vacc_course Inherits
+        <p>Table audit.log_lnk_org_unit2comm Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -18011,13 +19765,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_constraint2vacc_course Constraints</caption>
+            <caption>audit.log_lnk_org_unit2comm Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -18045,13 +19814,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-identity2ext-id">log_lnk_identity2ext_id</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-org-unit2ext-id">log_lnk_org_unit2ext_id</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_identity2ext_id Structure</caption>
+                <caption>audit.log_lnk_org_unit2ext_id Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -18239,7 +20008,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>id</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -18255,7 +20024,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>id_identity</td>
+            	<td>fk_org_unit</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -18287,7 +20056,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_origin</td>
+            	<td>fk_type</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -18319,7 +20088,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_identity2ext_id Inherits
+        <p>Table audit.log_lnk_org_unit2ext_id Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -18335,13 +20104,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_identity2ext_id Constraints</caption>
+            <caption>audit.log_lnk_org_unit2ext_id Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -18369,13 +20153,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-identity2primary-doc">log_lnk_identity2primary_doc</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-pat2vaccination-course">log_lnk_pat2vaccination_course</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_identity2primary_doc Structure</caption>
+                <caption>audit.log_lnk_pat2vaccination_course Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -18515,7 +20299,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
+            	<td>row_version</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -18531,7 +20315,39 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_identity</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -18547,7 +20363,23 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_primary_doc</td>
+            	<td>fk_patient</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>fk_course</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -18563,7 +20395,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_identity2primary_doc Inherits
+        <p>Table audit.log_lnk_pat2vaccination_course Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -18579,13 +20411,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_identity2primary_doc Constraints</caption>
+            <caption>audit.log_lnk_pat2vaccination_course Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -18613,13 +20460,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-job2person">log_lnk_job2person</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-person2relative">log_lnk_person2relative</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_job2person Structure</caption>
+                <caption>audit.log_lnk_person2relative Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -18807,7 +20654,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
+            	<td>id</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -18823,7 +20670,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_identity</td>
+            	<td>id_identity</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -18839,7 +20686,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_occupation</td>
+            	<td>id_relative</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -18855,8 +20702,40 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>activities</td>
-            	<td>text</td>
+            	<td>id_relation_type</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>started</td>
+            	<td>date</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>ended</td>
+            	<td>date</td>
                 <td><i>
 				
 
@@ -18871,7 +20750,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_job2person Inherits
+        <p>Table audit.log_lnk_person2relative Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -18887,13 +20766,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_job2person Constraints</caption>
+            <caption>audit.log_lnk_person2relative Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -18921,13 +20815,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-org-unit2comm">log_lnk_org_unit2comm</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-substance2brand">log_lnk_substance2brand</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_org_unit2comm Structure</caption>
+                <caption>audit.log_lnk_substance2brand Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -19131,7 +21025,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_org_unit</td>
+            	<td>fk_brand</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -19147,13 +21041,224 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>url</td>
+            	<td>fk_substance</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table audit.log_lnk_substance2brand Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>audit.log_lnk_substance2brand Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_trail_audit_action_check</td>
+                <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#audit.schema">Schema audit</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-tst2norm">log_lnk_tst2norm</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>audit.log_lnk_tst2norm Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT nextval('audit_trail_pk_audit_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>orig_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>the .row_version in the original row before the audited action took place, should be equal to .row_version
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>orig_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>the .modified_when in the original row before the audited action took place, should be equal to .modified_when
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>orig_by</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>the .modified_by in the original row before the audited action took place, should be equal to .modified_by
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>orig_tableoid</td>
+            	<td>oid</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>the TG_RELID when the audit trigger was run
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>audit_action</td>
             	<td>text</td>
                 <td><i>
 				
 
+				NOT NULL
 				
+				</i>
 				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>audit_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>audit_by</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -19163,7 +21268,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_type</td>
+            	<td>row_version</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -19179,8 +21284,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>is_confidential</td>
-            	<td>boolean</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -19195,8 +21300,56 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>id</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>id_test</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>id_norm</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -19211,7 +21364,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_org_unit2comm Inherits
+        <p>Table audit.log_lnk_tst2norm Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -19227,13 +21380,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_org_unit2comm Constraints</caption>
+            <caption>audit.log_lnk_tst2norm Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -19261,13 +21429,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-org-unit2ext-id">log_lnk_org_unit2ext_id</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-type2item">log_lnk_type2item</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_org_unit2ext_id Structure</caption>
+                <caption>audit.log_lnk_type2item Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -19471,38 +21639,6 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_org_unit</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>external_id</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
             	<td>fk_type</td>
             	<td>integer</td>
                 <td><i>
@@ -19519,8 +21655,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>fk_item</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -19535,7 +21671,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_org_unit2ext_id Inherits
+        <p>Table audit.log_lnk_type2item Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -19551,13 +21687,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_org_unit2ext_id Constraints</caption>
+            <caption>audit.log_lnk_type2item Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -19585,13 +21736,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-pat2vaccination-course">log_lnk_pat2vaccination_course</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-vaccination-course2schedule">log_lnk_vaccination_course2schedule</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_pat2vaccination_course Structure</caption>
+                <caption>audit.log_lnk_vaccination_course2schedule Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -19795,7 +21946,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_patient</td>
+            	<td>fk_course</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -19811,7 +21962,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_course</td>
+            	<td>fk_schedule</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -19827,7 +21978,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_pat2vaccination_course Inherits
+        <p>Table audit.log_lnk_vaccination_course2schedule Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -19843,13 +21994,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_pat2vaccination_course Constraints</caption>
+            <caption>audit.log_lnk_vaccination_course2schedule Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -19877,13 +22043,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-person2relative">log_lnk_person2relative</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-vaccine2inds">log_lnk_vaccine2inds</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_person2relative Structure</caption>
+                <caption>audit.log_lnk_vaccine2inds Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -20087,7 +22253,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>id_identity</td>
+            	<td>fk_vaccine</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -20103,23 +22269,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>id_relative</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>id_relation_type</td>
+            	<td>fk_indication</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -20131,43 +22281,11 @@ this referral.
 				</td>
 			 </tr>
             
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>started</td>
-            	<td>date</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>ended</td>
-            	<td>date</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
         </table>
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_person2relative Inherits
+        <p>Table audit.log_lnk_vaccine2inds Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -20183,13 +22301,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_person2relative Constraints</caption>
+            <caption>audit.log_lnk_vaccine2inds Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -20217,13 +22350,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-substance2brand">log_lnk_substance2brand</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-message-inbox">log_message_inbox</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_substance2brand Structure</caption>
+                <caption>audit.log_message_inbox Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -20427,7 +22560,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_brand</td>
+            	<td>fk_staff</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -20443,7 +22576,71 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_substance</td>
+            	<td>fk_inbox_item_type</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>comment</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>data</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>importance</td>
+            	<td>smallint</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>fk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -20455,11 +22652,59 @@ this referral.
 				</td>
 			 </tr>
             
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>ufk_context</td>
+            	<td>integer[]</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>due_date</td>
+            	<td>date</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>expiry_date</td>
+            	<td>date</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
         </table>
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_substance2brand Inherits
+        <p>Table audit.log_message_inbox Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -20475,13 +22720,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_substance2brand Constraints</caption>
+            <caption>audit.log_message_inbox Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -20509,13 +22769,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-tst2norm">log_lnk_tst2norm</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-occupation">log_occupation</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_tst2norm Structure</caption>
+                <caption>audit.log_occupation Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -20719,24 +22979,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>id_test</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>id_norm</td>
-            	<td>integer</td>
+            	<td>name</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -20751,7 +22995,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_tst2norm Inherits
+        <p>Table audit.log_occupation Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -20767,13 +23011,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_tst2norm Constraints</caption>
+            <caption>audit.log_occupation Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -20801,13 +23060,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-type2item">log_lnk_type2item</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-operation">log_operation</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_type2item Structure</caption>
+                <caption>audit.log_operation Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -21011,7 +23270,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_type</td>
+            	<td>fk_health_issue</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -21027,7 +23286,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_item</td>
+            	<td>fk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -21039,11 +23298,43 @@ this referral.
 				</td>
 			 </tr>
             
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>clin_where</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>comment</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
         </table>
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_type2item Inherits
+        <p>Table audit.log_operation Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -21059,13 +23350,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_type2item Constraints</caption>
+            <caption>audit.log_operation Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -21093,13 +23399,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-vaccination-course2schedule">log_lnk_vaccination_course2schedule</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-org">log_org</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_vaccination_course2schedule Structure</caption>
+                <caption>audit.log_org Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -21303,8 +23609,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_course</td>
-            	<td>integer</td>
+            	<td>description</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -21319,7 +23625,23 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_schedule</td>
+            	<td>fk_category</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>fk_data_source</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -21335,7 +23657,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_vaccination_course2schedule Inherits
+        <p>Table audit.log_org Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -21351,13 +23673,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_vaccination_course2schedule Constraints</caption>
+            <caption>audit.log_org Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -21385,13 +23722,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-lnk-vaccine2inds">log_lnk_vaccine2inds</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-org-unit">log_org_unit</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_lnk_vaccine2inds Structure</caption>
+                <caption>audit.log_org_unit Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -21579,7 +23916,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>id</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -21595,7 +23932,39 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_vaccine</td>
+            	<td>description</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>fk_org</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>fk_address</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -21611,7 +23980,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_indication</td>
+            	<td>fk_category</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -21627,7 +23996,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_lnk_vaccine2inds Inherits
+        <p>Table audit.log_org_unit Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -21643,13 +24012,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_lnk_vaccine2inds Constraints</caption>
+            <caption>audit.log_org_unit Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -21677,13 +24061,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-message-inbox">log_message_inbox</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-paperwork-templates">log_paperwork_templates</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_message_inbox Structure</caption>
+                <caption>audit.log_paperwork_templates Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -21887,7 +24271,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_staff</td>
+            	<td>fk_template_type</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -21903,8 +24287,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_inbox_item_type</td>
-            	<td>integer</td>
+            	<td>instance_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -21919,7 +24303,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>comment</td>
+            	<td>name_short</td>
             	<td>text</td>
                 <td><i>
 				
@@ -21935,7 +24319,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>data</td>
+            	<td>name_long</td>
             	<td>text</td>
                 <td><i>
 				
@@ -21951,8 +24335,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>importance</td>
-            	<td>smallint</td>
+            	<td>external_version</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -21967,8 +24351,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_patient</td>
-            	<td>integer</td>
+            	<td>gnumed_revision</td>
+            	<td>double precision</td>
                 <td><i>
 				
 
@@ -21983,8 +24367,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>ufk_context</td>
-            	<td>integer[]</td>
+            	<td>engine</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -21999,8 +24383,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>due_date</td>
-            	<td>date</td>
+            	<td>in_use</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -22015,8 +24399,40 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>expiry_date</td>
-            	<td>date</td>
+            	<td>filename</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>data</td>
+            	<td>bytea</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>edit_after_substitution</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -22031,7 +24447,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_message_inbox Inherits
+        <p>Table audit.log_paperwork_templates Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -22047,13 +24463,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_message_inbox Constraints</caption>
+            <caption>audit.log_paperwork_templates Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -22081,13 +24512,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-occupation">log_occupation</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-patient">log_patient</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_occupation Structure</caption>
+                <caption>audit.log_patient Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -22275,7 +24706,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>id</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -22291,8 +24722,24 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>name</td>
-            	<td>text</td>
+            	<td>fk_identity</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>edc</td>
+            	<td>date</td>
                 <td><i>
 				
 
@@ -22307,7 +24754,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_occupation Inherits
+        <p>Table audit.log_patient Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -22323,13 +24770,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_occupation Constraints</caption>
+            <caption>audit.log_patient Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -22357,13 +24819,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-operation">log_operation</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-prax-geb-paid">log_prax_geb_paid</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_operation Structure</caption>
+                <caption>audit.log_prax_geb_paid Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -22567,7 +25029,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_health_issue</td>
+            	<td>fk_fall</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -22583,8 +25045,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_encounter</td>
-            	<td>integer</td>
+            	<td>paid_amount</td>
+            	<td>numeric</td>
                 <td><i>
 				
 
@@ -22599,8 +25061,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>clin_where</td>
-            	<td>text</td>
+            	<td>paid_when</td>
+            	<td>date</td>
                 <td><i>
 				
 
@@ -22615,8 +25077,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>paid_with</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -22631,7 +25093,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_operation Inherits
+        <p>Table audit.log_prax_geb_paid Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -22647,13 +25109,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_operation Constraints</caption>
+            <caption>audit.log_prax_geb_paid Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -22681,13 +25158,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-org">log_org</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-praxis-branch">log_praxis_branch</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_org Structure</caption>
+                <caption>audit.log_praxis_branch Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -22891,39 +25368,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>description</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>fk_category</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>fk_data_source</td>
+            	<td>fk_org_unit</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -22939,7 +25384,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_org Inherits
+        <p>Table audit.log_praxis_branch Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -22955,13 +25400,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_org Constraints</caption>
+            <caption>audit.log_praxis_branch Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -22989,13 +25449,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-org-unit">log_org_unit</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-procedure">log_procedure</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_org_unit Structure</caption>
+                <caption>audit.log_procedure Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -23183,7 +25643,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
+            	<td>pk_item</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -23199,7 +25659,71 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>description</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>fk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>narrative</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -23215,7 +25739,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_org</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -23231,7 +25755,23 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_address</td>
+            	<td>clin_where</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>fk_hospital_stay</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -23243,11 +25783,43 @@ this referral.
 				</td>
 			 </tr>
             
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>clin_end</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
             <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>fk_category</td>
+            	<td>is_ongoing</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>fk_org_unit</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -23263,7 +25835,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_org_unit Inherits
+        <p>Table audit.log_procedure Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -23279,13 +25851,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_org_unit Constraints</caption>
+            <caption>audit.log_procedure Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -23313,13 +25900,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-paperwork-templates">log_paperwork_templates</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-referral">log_referral</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_paperwork_templates Structure</caption>
+                <caption>audit.log_referral Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -23507,7 +26094,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
+            	<td>pk_item</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -23523,8 +26110,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_template_type</td>
-            	<td>integer</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -23539,8 +26126,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>instance_type</td>
-            	<td>text</td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -23555,8 +26142,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>name_short</td>
-            	<td>text</td>
+            	<td>fk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -23571,23 +26158,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>name_long</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>external_version</td>
+            	<td>narrative</td>
             	<td>text</td>
                 <td><i>
 				
@@ -23599,27 +26170,11 @@ this referral.
 				</td>
 			 </tr>
             
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>gnumed_revision</td>
-            	<td>double precision</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>engine</td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -23635,8 +26190,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>in_use</td>
-            	<td>boolean</td>
+            	<td>id</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -23651,8 +26206,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>filename</td>
-            	<td>text</td>
+            	<td>fk_referee</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -23667,24 +26222,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>data</td>
-            	<td>bytea</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>edit_after_substitution</td>
-            	<td>boolean</td>
+            	<td>fk_form</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -23699,7 +26238,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_paperwork_templates Inherits
+        <p>Table audit.log_referral Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -23715,13 +26254,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_paperwork_templates Constraints</caption>
+            <caption>audit.log_referral Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -23749,13 +26303,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-patient">log_patient</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-region">log_region</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_patient Structure</caption>
+                <caption>audit.log_region Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -23773,7 +26327,7 @@ this referral.
 				
 
 				NOT NULL
-				DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
+				DEFAULT nextval('audit_trail_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -23959,8 +26513,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_identity</td>
-            	<td>integer</td>
+            	<td>code</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -23975,8 +26529,24 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>edc</td>
-            	<td>date</td>
+            	<td>country</td>
+            	<td>bpchar</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>name</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -23991,7 +26561,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_patient Inherits
+        <p>Table audit.log_region Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -24007,13 +26577,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_patient Constraints</caption>
+            <caption>audit.log_region Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -24041,13 +26626,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-prax-geb-paid">log_prax_geb_paid</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-relation-types">log_relation_types</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_prax_geb_paid Structure</caption>
+                <caption>audit.log_relation_types Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -24235,7 +26820,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
+            	<td>id</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -24251,7 +26836,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_fall</td>
+            	<td>inverse</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -24267,8 +26852,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>paid_amount</td>
-            	<td>numeric</td>
+            	<td>biological</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -24283,8 +26868,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>paid_when</td>
-            	<td>date</td>
+            	<td>biol_verified</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -24299,8 +26884,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>paid_with</td>
-            	<td>integer</td>
+            	<td>description</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -24315,7 +26900,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_prax_geb_paid Inherits
+        <p>Table audit.log_relation_types Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -24331,13 +26916,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_prax_geb_paid Constraints</caption>
+            <caption>audit.log_relation_types Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -24365,13 +26965,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-praxis-branch">log_praxis_branch</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-report-query">log_report_query</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_praxis_branch Structure</caption>
+                <caption>audit.log_report_query Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -24389,7 +26989,7 @@ this referral.
 				
 
 				NOT NULL
-				DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
+				DEFAULT nextval('audit_trail_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -24575,8 +27175,24 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_org_unit</td>
-            	<td>integer</td>
+            	<td>label</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>cmd</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -24591,7 +27207,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_praxis_branch Inherits
+        <p>Table audit.log_report_query Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -24607,13 +27223,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_praxis_branch Constraints</caption>
+            <caption>audit.log_report_query Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -24641,13 +27272,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-procedure">log_procedure</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-staff">log_staff</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_procedure Structure</caption>
+                <caption>audit.log_staff Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -24835,39 +27466,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>fk_encounter</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -24883,7 +27482,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_episode</td>
+            	<td>fk_identity</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -24899,8 +27498,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>narrative</td>
-            	<td>text</td>
+            	<td>db_user</td>
+            	<td>name</td>
                 <td><i>
 				
 
@@ -24915,7 +27514,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
+            	<td>short_alias</td>
             	<td>text</td>
                 <td><i>
 				
@@ -24931,23 +27530,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>clin_where</td>
+            	<td>comment</td>
             	<td>text</td>
                 <td><i>
 				
@@ -24959,43 +27542,11 @@ this referral.
 				</td>
 			 </tr>
             
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>fk_hospital_stay</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>clin_end</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>is_ongoing</td>
+            	<td>is_active</td>
             	<td>boolean</td>
                 <td><i>
 				
@@ -25007,27 +27558,11 @@ this referral.
 				</td>
 			 </tr>
             
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>fk_org_unit</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
         </table>
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_procedure Inherits
+        <p>Table audit.log_staff Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -25043,13 +27578,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_procedure Constraints</caption>
+            <caption>audit.log_staff Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -25077,13 +27627,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-referral">log_referral</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-street">log_street</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_referral Structure</caption>
+                <caption>audit.log_street Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -25271,39 +27821,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>fk_encounter</td>
+            	<td>id</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -25319,7 +27837,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_episode</td>
+            	<td>id_urb</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -25335,7 +27853,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>narrative</td>
+            	<td>name</td>
             	<td>text</td>
                 <td><i>
 				
@@ -25351,7 +27869,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
+            	<td>postcode</td>
             	<td>text</td>
                 <td><i>
 				
@@ -25367,8 +27885,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>id</td>
-            	<td>integer</td>
+            	<td>suburb</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -25383,24 +27901,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_referee</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>fk_form</td>
-            	<td>integer</td>
+            	<td>lat_lon</td>
+            	<td>point</td>
                 <td><i>
 				
 
@@ -25415,7 +27917,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_referral Inherits
+        <p>Table audit.log_street Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -25431,13 +27933,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_referral Constraints</caption>
+            <caption>audit.log_street Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -25465,13 +27982,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-relation-types">log_relation_types</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-substance-in-brand">log_substance_in_brand</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_relation_types Structure</caption>
+                <caption>audit.log_substance_in_brand Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -25659,7 +28176,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>id</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -25675,7 +28192,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>inverse</td>
+            	<td>fk_brand</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -25691,8 +28208,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>biological</td>
-            	<td>boolean</td>
+            	<td>description</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -25707,23 +28224,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>biol_verified</td>
-            	<td>boolean</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>description</td>
+            	<td>atc_code</td>
             	<td>text</td>
                 <td><i>
 				
@@ -25739,7 +28240,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_relation_types Inherits
+        <p>Table audit.log_substance_in_brand Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -25755,13 +28256,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_relation_types Constraints</caption>
+            <caption>audit.log_substance_in_brand Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -25789,13 +28305,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-report-query">log_report_query</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-substance-intake">log_substance_intake</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_report_query Structure</caption>
+                <caption>audit.log_substance_intake Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -25983,7 +28499,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
+            	<td>pk_item</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -25999,8 +28515,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>label</td>
-            	<td>text</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -26015,8 +28531,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>cmd</td>
-            	<td>text</td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -26027,85 +28543,17 @@ this referral.
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table audit.log_report_query Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_report_query Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>audit_trail_audit_action_check</td>
-                <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
-            </tr>
-			
-		</table>
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#audit.schema">Schema audit</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-staff">log_staff</a>
-		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_staff Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
+            	<td>fk_episode</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit_trail_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -26115,15 +28563,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>orig_version</td>
-            	<td>integer</td>
+            	<td>narrative</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>the .row_version in the original row before the audited action took place, should be equal to .row_version
+				
 				</td>
 			 </tr>
             
@@ -26131,15 +28579,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>orig_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>the .modified_when in the original row before the audited action took place, should be equal to .modified_when
+				
 				</td>
 			 </tr>
             
@@ -26147,15 +28595,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>orig_by</td>
-            	<td>name</td>
+            	<td>pk</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>the .modified_by in the original row before the audited action took place, should be equal to .modified_by
+				
 				</td>
 			 </tr>
             
@@ -26163,15 +28611,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>orig_tableoid</td>
-            	<td>oid</td>
+            	<td>fk_substance</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>the TG_RELID when the audit trigger was run
+				
 				</td>
 			 </tr>
             
@@ -26179,12 +28627,12 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>audit_action</td>
+            	<td>preparation</td>
             	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -26195,13 +28643,13 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>audit_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>schedule</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -26211,13 +28659,13 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>audit_by</td>
-            	<td>name</td>
+            	<td>aim</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -26227,8 +28675,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>duration</td>
+            	<td>interval</td>
                 <td><i>
 				
 
@@ -26243,8 +28691,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>intake_is_approved_of</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -26259,8 +28707,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>is_long_term</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -26275,8 +28723,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
-            	<td>integer</td>
+            	<td>discontinued</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -26291,8 +28739,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_identity</td>
-            	<td>integer</td>
+            	<td>discontinue_reason</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -26307,8 +28755,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>db_user</td>
-            	<td>name</td>
+            	<td>fk_drug_component</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -26323,7 +28771,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>short_alias</td>
+            	<td>comment_on_start</td>
             	<td>text</td>
                 <td><i>
 				
@@ -26339,24 +28787,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>is_active</td>
-            	<td>boolean</td>
+            	<td>harmful_use_type</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -26371,7 +28803,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_staff Inherits
+        <p>Table audit.log_substance_intake Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -26387,13 +28819,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_staff Constraints</caption>
+            <caption>audit.log_substance_intake Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -26421,13 +28868,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-state">log_state</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-suppressed-hint">log_suppressed_hint</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_state Structure</caption>
+                <caption>audit.log_suppressed_hint Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -26615,7 +29062,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>id</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -26631,8 +29078,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>code</td>
-            	<td>text</td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -26647,8 +29094,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>country</td>
-            	<td>bpchar</td>
+            	<td>fk_hint</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -26663,7 +29110,55 @@ this referral.
 				<td>
                 
                 </td>
+            	<td>suppressed_by</td>
             	<td>name</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>suppressed_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>rationale</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>md5_sum</td>
             	<td>text</td>
                 <td><i>
 				
@@ -26679,7 +29174,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_state Inherits
+        <p>Table audit.log_suppressed_hint Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -26695,13 +29190,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_state Constraints</caption>
+            <caption>audit.log_suppressed_hint Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -26729,13 +29239,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-street">log_street</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-tag-image">log_tag_image</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_street Structure</caption>
+                <caption>audit.log_tag_image Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -26923,23 +29433,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>id</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>id_urb</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -26951,27 +29445,11 @@ this referral.
 				</td>
 			 </tr>
             
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>name</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>postcode</td>
+            	<td>description</td>
             	<td>text</td>
                 <td><i>
 				
@@ -26987,7 +29465,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>suburb</td>
+            	<td>filename</td>
             	<td>text</td>
                 <td><i>
 				
@@ -27003,8 +29481,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>lat_lon</td>
-            	<td>point</td>
+            	<td>image</td>
+            	<td>bytea</td>
                 <td><i>
 				
 
@@ -27019,7 +29497,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_street Inherits
+        <p>Table audit.log_tag_image Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -27035,13 +29513,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_street Constraints</caption>
+            <caption>audit.log_tag_image Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -27069,13 +29562,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-substance-in-brand">log_substance_in_brand</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-test-org">log_test_org</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_substance_in_brand Structure</caption>
+                <caption>audit.log_test_org Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -27279,7 +29772,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_brand</td>
+            	<td>fk_org_unit</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -27295,7 +29788,39 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>description</td>
+            	<td>fk_adm_contact</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>fk_med_contact</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>comment</td>
             	<td>text</td>
                 <td><i>
 				
@@ -27311,7 +29836,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>atc_code</td>
+            	<td>contact</td>
             	<td>text</td>
                 <td><i>
 				
@@ -27327,7 +29852,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_substance_in_brand Inherits
+        <p>Table audit.log_test_org Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -27343,13 +29868,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_substance_in_brand Constraints</caption>
+            <caption>audit.log_test_org Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -27377,13 +29917,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-substance-intake">log_substance_intake</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-test-panel">log_test_panel</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_substance_intake Structure</caption>
+                <caption>audit.log_test_panel Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -27571,102 +30111,6 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>fk_encounter</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>fk_episode</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>narrative</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
             	<td>pk</td>
             	<td>integer</td>
                 <td><i>
@@ -27683,39 +30127,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_substance</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>preparation</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>schedule</td>
+            	<td>description</td>
             	<td>text</td>
                 <td><i>
 				
@@ -27731,7 +30143,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>aim</td>
+            	<td>comment</td>
             	<td>text</td>
                 <td><i>
 				
@@ -27747,88 +30159,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>duration</td>
-            	<td>interval</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>intake_is_approved_of</td>
-            	<td>boolean</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>is_long_term</td>
-            	<td>boolean</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>discontinued</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>discontinue_reason</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>fk_drug_component</td>
-            	<td>integer</td>
+            	<td>fk_test_types</td>
+            	<td>integer[]</td>
                 <td><i>
 				
 
@@ -27843,7 +30175,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_substance_intake Inherits
+        <p>Table audit.log_test_panel Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -27859,13 +30191,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_substance_intake Constraints</caption>
+            <caption>audit.log_test_panel Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -27893,13 +30240,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-suppressed-hint">log_suppressed_hint</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-test-result">log_test_result</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_suppressed_hint Structure</caption>
+                <caption>audit.log_test_result Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -27917,7 +30264,7 @@ this referral.
 				
 
 				NOT NULL
-				DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
+				DEFAULT nextval('audit_trail_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -28087,7 +30434,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
+            	<td>pk_item</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -28103,8 +30450,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_encounter</td>
-            	<td>integer</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -28119,7 +30466,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_hint</td>
+            	<td>fk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -28135,8 +30482,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>suppressed_by</td>
-            	<td>name</td>
+            	<td>fk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -28151,8 +30498,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>suppressed_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>narrative</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -28167,7 +30514,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>rationale</td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -28183,8 +30530,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>md5_sum</td>
-            	<td>text</td>
+            	<td>pk</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -28195,85 +30542,81 @@ this referral.
 				</td>
 			 </tr>
             
-        </table>
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>fk_type</td>
+            	<td>integer</td>
+                <td><i>
+				
 
-        <!-- Inherits -->
-		
-        <p>Table audit.log_suppressed_hint Inherits
-        
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
             
-           <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
-        
-        </p>
-		
-
-		
-		
-		
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>val_num</td>
+            	<td>numeric</td>
+                <td><i>
+				
 
-        <!-- Constraint List -->
-		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_suppressed_hint Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
             <tr class="tr0">
-				<td>audit_trail_audit_action_check</td>
-                <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
-            </tr>
-			
-		</table>
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#audit.schema">Schema audit</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-tag-image">log_tag_image</a>
-		</h2>
-        
+				<td>
+                
+                </td>
+            	<td>val_alpha</td>
+            	<td>text</td>
+                <td><i>
+				
 
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>val_unit</td>
+            	<td>text</td>
+                <td><i>
+				
 
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_tag_image Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
+            	<td>val_normal_min</td>
+            	<td>numeric</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit_trail_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -28283,15 +30626,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>orig_version</td>
-            	<td>integer</td>
+            	<td>val_normal_max</td>
+            	<td>numeric</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>the .row_version in the original row before the audited action took place, should be equal to .row_version
+				
 				</td>
 			 </tr>
             
@@ -28299,15 +30642,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>orig_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>val_normal_range</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>the .modified_when in the original row before the audited action took place, should be equal to .modified_when
+				
 				</td>
 			 </tr>
             
@@ -28315,15 +30658,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>orig_by</td>
-            	<td>name</td>
+            	<td>val_target_min</td>
+            	<td>numeric</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>the .modified_by in the original row before the audited action took place, should be equal to .modified_by
+				
 				</td>
 			 </tr>
             
@@ -28331,15 +30674,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>orig_tableoid</td>
-            	<td>oid</td>
+            	<td>val_target_max</td>
+            	<td>numeric</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>the TG_RELID when the audit trigger was run
+				
 				</td>
 			 </tr>
             
@@ -28347,12 +30690,12 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>audit_action</td>
+            	<td>val_target_range</td>
             	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -28363,13 +30706,13 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>audit_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>abnormality_indicator</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -28379,13 +30722,13 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>audit_by</td>
-            	<td>name</td>
+            	<td>norm_ref_group</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -28395,8 +30738,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>note_test_org</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -28411,8 +30754,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>material</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -28427,8 +30770,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>material_detail</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -28443,7 +30786,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
+            	<td>fk_intended_reviewer</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -28459,8 +30802,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>description</td>
-            	<td>text</td>
+            	<td>fk_request</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -28475,7 +30818,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>filename</td>
+            	<td>status</td>
             	<td>text</td>
                 <td><i>
 				
@@ -28491,8 +30834,24 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>image</td>
-            	<td>bytea</td>
+            	<td>source_data</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>val_grouping</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -28507,7 +30866,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_tag_image Inherits
+        <p>Table audit.log_test_result Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -28523,13 +30882,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_tag_image Constraints</caption>
+            <caption>audit.log_test_result Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -28557,13 +30931,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-test-org">log_test_org</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-test-type">log_test_type</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_test_org Structure</caption>
+                <caption>audit.log_test_type Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -28767,7 +31141,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_org_unit</td>
+            	<td>fk_test_org</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -28783,8 +31157,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_adm_contact</td>
-            	<td>integer</td>
+            	<td>name</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -28799,8 +31173,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_med_contact</td>
-            	<td>integer</td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -28815,7 +31189,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>comment</td>
+            	<td>reference_unit</td>
             	<td>text</td>
                 <td><i>
 				
@@ -28831,7 +31205,23 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>contact</td>
+            	<td>loinc</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>abbrev</td>
             	<td>text</td>
                 <td><i>
 				
@@ -28843,11 +31233,27 @@ this referral.
 				</td>
 			 </tr>
             
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>fk_meta_test_type</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
         </table>
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_test_org Inherits
+        <p>Table audit.log_test_type Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -28863,13 +31269,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_test_org Constraints</caption>
+            <caption>audit.log_test_type Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -28897,13 +31318,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-test-panel">log_test_panel</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-urb">log_urb</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_test_panel Structure</caption>
+                <caption>audit.log_urb Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -29091,7 +31512,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
+            	<td>id</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -29107,8 +31528,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>description</td>
-            	<td>text</td>
+            	<td>fk_region</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -29123,7 +31544,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>comment</td>
+            	<td>postcode</td>
             	<td>text</td>
                 <td><i>
 				
@@ -29139,8 +31560,24 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_test_types</td>
-            	<td>integer[]</td>
+            	<td>lat_lon</td>
+            	<td>point</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>name</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -29155,7 +31592,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_test_panel Inherits
+        <p>Table audit.log_urb Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -29171,13 +31608,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_test_panel Constraints</caption>
+            <caption>audit.log_urb Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -29205,13 +31657,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-test-result">log_test_result</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-vacc-indication">log_vacc_indication</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_test_result Structure</caption>
+                <caption>audit.log_vacc_indication Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -29399,7 +31851,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
+            	<td>id</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -29415,8 +31867,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>description</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -29431,8 +31883,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_encounter</td>
-            	<td>integer</td>
+            	<td>atcs_single_indication</td>
+            	<td>text[]</td>
                 <td><i>
 				
 
@@ -29447,8 +31899,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_episode</td>
-            	<td>integer</td>
+            	<td>atcs_combi_indication</td>
+            	<td>text[]</td>
                 <td><i>
 				
 
@@ -29459,161 +31911,100 @@ this referral.
 				</td>
 			 </tr>
             
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>narrative</td>
-            	<td>text</td>
-                <td><i>
-				
+        </table>
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
+        <!-- Inherits -->
+		
+        <p>Table audit.log_vacc_indication Inherits
+        
             
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
-                <td><i>
-				
+           <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
+        
+        </p>
+		
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>pk</td>
-            	<td>integer</td>
-                <td><i>
-				
+		
+		
+		
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>audit.log_vacc_indication Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
             <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>fk_type</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
             <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>val_num</td>
-            	<td>numeric</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
             <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>val_alpha</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
             <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>val_unit</td>
-            	<td>text</td>
-                <td><i>
-				
+				<td>audit_trail_audit_action_check</td>
+                <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
+            </tr>
+			
+		</table>
+		
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>val_normal_min</td>
-            	<td>numeric</td>
-                <td><i>
-				
+        <!-- Foreign Key Discovery -->
+		
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>val_normal_max</td>
-            	<td>numeric</td>
-                <td><i>
-				
+    <!-- Indexes -->
+    
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#audit.schema">Schema audit</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-vacc-route">log_vacc_route</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>audit.log_vacc_route Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>val_normal_range</td>
-            	<td>text</td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit_trail_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -29623,15 +32014,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>val_target_min</td>
-            	<td>numeric</td>
+            	<td>orig_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>the .row_version in the original row before the audited action took place, should be equal to .row_version
 				</td>
 			 </tr>
             
@@ -29639,15 +32030,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>val_target_max</td>
-            	<td>numeric</td>
+            	<td>orig_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>the .modified_when in the original row before the audited action took place, should be equal to .modified_when
 				</td>
 			 </tr>
             
@@ -29655,15 +32046,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>val_target_range</td>
-            	<td>text</td>
+            	<td>orig_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>the .modified_by in the original row before the audited action took place, should be equal to .modified_by
 				</td>
 			 </tr>
             
@@ -29671,15 +32062,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>abnormality_indicator</td>
-            	<td>text</td>
+            	<td>orig_tableoid</td>
+            	<td>oid</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>the TG_RELID when the audit trigger was run
 				</td>
 			 </tr>
             
@@ -29687,12 +32078,12 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>norm_ref_group</td>
+            	<td>audit_action</td>
             	<td>text</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -29703,13 +32094,13 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>note_test_org</td>
-            	<td>text</td>
+            	<td>audit_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -29719,13 +32110,13 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>material</td>
-            	<td>text</td>
+            	<td>audit_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -29735,8 +32126,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>material_detail</td>
-            	<td>text</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -29751,8 +32142,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_intended_reviewer</td>
-            	<td>integer</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -29767,8 +32158,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_request</td>
-            	<td>integer</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
@@ -29783,8 +32174,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>status</td>
-            	<td>text</td>
+            	<td>id</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -29799,7 +32190,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>source_data</td>
+            	<td>abbreviation</td>
             	<td>text</td>
                 <td><i>
 				
@@ -29815,7 +32206,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>val_grouping</td>
+            	<td>description</td>
             	<td>text</td>
                 <td><i>
 				
@@ -29831,7 +32222,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_test_result Inherits
+        <p>Table audit.log_vacc_route Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -29847,13 +32238,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_test_result Constraints</caption>
+            <caption>audit.log_vacc_route Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -29881,13 +32287,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-test-type">log_test_type</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-vaccination">log_vaccination</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_test_type Structure</caption>
+                <caption>audit.log_vaccination Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -30075,7 +32481,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
+            	<td>pk_item</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -30091,8 +32497,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_test_org</td>
-            	<td>integer</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -30107,8 +32513,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>name</td>
-            	<td>text</td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -30123,8 +32529,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>fk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -30139,7 +32545,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>reference_unit</td>
+            	<td>narrative</td>
             	<td>text</td>
                 <td><i>
 				
@@ -30155,7 +32561,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>loinc</td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -30171,192 +32577,12 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>abbrev</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>fk_meta_test_type</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table audit.log_test_type Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_test_type Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>audit_trail_audit_action_check</td>
-                <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
-            </tr>
-			
-		</table>
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#audit.schema">Schema audit</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-urb">log_urb</a>
-		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_urb Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT nextval('audit_trail_pk_audit_seq'::regclass)
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>orig_version</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				
-				</i>
-				<br><br>the .row_version in the original row before the audited action took place, should be equal to .row_version
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>orig_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				NOT NULL
-				
-				</i>
-				<br><br>the .modified_when in the original row before the audited action took place, should be equal to .modified_when
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>orig_by</td>
-            	<td>name</td>
-                <td><i>
 				
-
-				NOT NULL
-				
-				</i>
-				<br><br>the .modified_by in the original row before the audited action took place, should be equal to .modified_by
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>orig_tableoid</td>
-            	<td>oid</td>
-                <td><i>
-				
-
-				NOT NULL
-				
-				</i>
-				<br><br>the TG_RELID when the audit trigger was run
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>audit_action</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				NOT NULL
 				
 				</i>
 				
@@ -30367,39 +32593,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>audit_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT now()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>audit_by</td>
-            	<td>name</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT "current_user"()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>row_version</td>
+            	<td>fk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -30415,39 +32609,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>modified_by</td>
-            	<td>name</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>id</td>
+            	<td>fk_provider</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -30463,7 +32625,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>id_state</td>
+            	<td>fk_vaccine</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -30479,7 +32641,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>postcode</td>
+            	<td>site</td>
             	<td>text</td>
                 <td><i>
 				
@@ -30495,8 +32657,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>lat_lon</td>
-            	<td>point</td>
+            	<td>batch_no</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -30511,7 +32673,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>name</td>
+            	<td>reaction</td>
             	<td>text</td>
                 <td><i>
 				
@@ -30527,7 +32689,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_urb Inherits
+        <p>Table audit.log_vaccination Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -30543,13 +32705,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_urb Constraints</caption>
+            <caption>audit.log_vaccination Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -30577,13 +32754,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-vacc-indication">log_vacc_indication</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-vaccination-course">log_vaccination_course</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_vacc_indication Structure</caption>
+                <caption>audit.log_vaccination_course Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -30771,7 +32948,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>id</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -30787,8 +32964,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>description</td>
-            	<td>text</td>
+            	<td>fk_recommended_by</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -30803,8 +32980,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>atcs_single_indication</td>
-            	<td>text[]</td>
+            	<td>fk_indication</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -30819,8 +32996,24 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>atcs_combi_indication</td>
-            	<td>text[]</td>
+            	<td>is_active</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -30835,7 +33028,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_vacc_indication Inherits
+        <p>Table audit.log_vaccination_course Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -30851,13 +33044,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_vacc_indication Constraints</caption>
+            <caption>audit.log_vaccination_course Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -30885,13 +33093,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-vacc-route">log_vacc_route</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-vaccination-course-constraint">log_vaccination_course_constraint</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_vacc_route Structure</caption>
+                <caption>audit.log_vaccination_course_constraint Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -31079,7 +33287,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>id</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -31095,22 +33303,6 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>abbreviation</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
             	<td>description</td>
             	<td>text</td>
                 <td><i>
@@ -31127,7 +33319,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_vacc_route Inherits
+        <p>Table audit.log_vaccination_course_constraint Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -31143,13 +33335,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_vacc_route Constraints</caption>
+            <caption>audit.log_vaccination_course_constraint Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -31177,13 +33384,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-vaccination">log_vaccination</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-vaccination-definition">log_vaccination_definition</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_vaccination Structure</caption>
+                <caption>audit.log_vaccination_definition Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -31371,39 +33578,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>fk_encounter</td>
+            	<td>id</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -31419,7 +33594,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_episode</td>
+            	<td>fk_course</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -31435,40 +33610,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>narrative</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>pk</td>
-            	<td>integer</td>
+            	<td>is_booster</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -31483,7 +33626,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_patient</td>
+            	<td>seq_no</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -31499,8 +33642,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_provider</td>
-            	<td>integer</td>
+            	<td>min_age_due</td>
+            	<td>interval</td>
                 <td><i>
 				
 
@@ -31515,8 +33658,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_vaccine</td>
-            	<td>integer</td>
+            	<td>max_age_due</td>
+            	<td>interval</td>
                 <td><i>
 				
 
@@ -31531,8 +33674,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>site</td>
-            	<td>text</td>
+            	<td>min_interval</td>
+            	<td>interval</td>
                 <td><i>
 				
 
@@ -31547,23 +33690,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>batch_no</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>reaction</td>
+            	<td>comment</td>
             	<td>text</td>
                 <td><i>
 				
@@ -31579,7 +33706,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_vaccination Inherits
+        <p>Table audit.log_vaccination_definition Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -31595,13 +33722,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_vaccination Constraints</caption>
+            <caption>audit.log_vaccination_definition Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -31629,13 +33771,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-vaccination-course">log_vaccination_course</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-vaccination-schedule">log_vaccination_schedule</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_vaccination_course Structure</caption>
+                <caption>audit.log_vaccination_schedule Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -31839,40 +33981,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_recommended_by</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>fk_indication</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>is_active</td>
-            	<td>boolean</td>
+            	<td>name</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -31903,7 +34013,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_vaccination_course Inherits
+        <p>Table audit.log_vaccination_schedule Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -31919,13 +34029,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_vaccination_course Constraints</caption>
+            <caption>audit.log_vaccination_schedule Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -31953,13 +34078,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-vaccination-course-constraint">log_vaccination_course_constraint</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-vaccine">log_vaccine</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_vaccination_course_constraint Structure</caption>
+                <caption>audit.log_vaccine Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -32163,7 +34288,71 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>description</td>
+            	<td>id_route</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>is_live</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>min_age</td>
+            	<td>interval</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>max_age</td>
+            	<td>interval</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>comment</td>
             	<td>text</td>
                 <td><i>
 				
@@ -32175,11 +34364,27 @@ this referral.
 				</td>
 			 </tr>
             
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>fk_brand</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
         </table>
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_vaccination_course_constraint Inherits
+        <p>Table audit.log_vaccine Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -32195,13 +34400,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_vaccination_course_constraint Constraints</caption>
+            <caption>audit.log_vaccine Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -32229,13 +34449,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-vaccination-definition">log_vaccination_definition</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-vaccine-batches">log_vaccine_batches</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_vaccination_definition Structure</caption>
+                <caption>audit.log_vaccine_batches Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -32423,23 +34643,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>id</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>fk_course</td>
+            	<td>pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -32451,27 +34655,11 @@ this referral.
 				</td>
 			 </tr>
             
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>is_booster</td>
-            	<td>boolean</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>seq_no</td>
+            	<td>fk_vaccine</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -32487,55 +34675,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>min_age_due</td>
-            	<td>interval</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>max_age_due</td>
-            	<td>interval</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>min_interval</td>
-            	<td>interval</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>comment</td>
+            	<td>batch_no</td>
             	<td>text</td>
                 <td><i>
 				
@@ -32551,7 +34691,7 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_vaccination_definition Inherits
+        <p>Table audit.log_vaccine_batches Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -32567,13 +34707,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_vaccination_definition Constraints</caption>
+            <caption>audit.log_vaccine_batches Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -32601,13 +34756,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-vaccination-schedule">log_vaccination_schedule</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-waiting-list">log_waiting_list</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_vaccination_schedule Structure</caption>
+                <caption>audit.log_waiting_list Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -32811,8 +34966,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>name</td>
-            	<td>text</td>
+            	<td>fk_patient</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -32827,6 +34982,54 @@ this referral.
 				<td>
                 
                 </td>
+            	<td>registered</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>urgency</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>list_position</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
             	<td>comment</td>
             	<td>text</td>
                 <td><i>
@@ -32839,11 +35042,27 @@ this referral.
 				</td>
 			 </tr>
             
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>area</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
         </table>
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_vaccination_schedule Inherits
+        <p>Table audit.log_waiting_list Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -32859,13 +35078,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_vaccination_schedule Constraints</caption>
+            <caption>audit.log_waiting_list Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -32893,13 +35127,13 @@ this referral.
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-vaccine">log_vaccine</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-xlnk-identity">log_xlnk_identity</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_vaccine Structure</caption>
+                <caption>audit.log_xlnk_identity Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -33103,7 +35337,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>id_route</td>
+            	<td>xfk_identity</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -33119,40 +35353,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>is_live</td>
-            	<td>boolean</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>min_age</td>
-            	<td>interval</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>max_age</td>
-            	<td>interval</td>
+            	<td>pupic</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -33167,7 +35369,7 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>comment</td>
+            	<td>data</td>
             	<td>text</td>
                 <td><i>
 				
@@ -33179,27 +35381,11 @@ this referral.
 				</td>
 			 </tr>
             
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>fk_brand</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
         </table>
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_vaccine Inherits
+        <p>Table audit.log_xlnk_identity Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
@@ -33215,13 +35401,28 @@ this referral.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_vaccine Constraints</caption>
+            <caption>audit.log_xlnk_identity Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_trail_orig_before_audit_when</td>
+                <td>CHECK (((orig_when <= audit_when) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>audit_audit_trail_sane_audit_when</td>
+                <td>CHECK (((audit_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_trail_sane_orig_when</td>
+                <td>CHECK (((orig_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>audit_trail_audit_action_check</td>
                 <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
             </tr>
@@ -33247,15 +35448,15 @@ this referral.
     </p>
 	
         <hr>
-		<h2>Table:
+		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-vaccine-batches">log_vaccine_batches</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.view.v-audit-trail">v_audit_trail</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_vaccine_batches Structure</caption>
+                <caption>audit.v_audit_trail Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -33267,79 +35468,15 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT nextval('audit_trail_pk_audit_seq'::regclass)
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>orig_version</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				
-				</i>
-				<br><br>the .row_version in the original row before the audited action took place, should be equal to .row_version
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>orig_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>event_when</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				
-				</i>
-				<br><br>the .modified_when in the original row before the audited action took place, should be equal to .modified_when
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>orig_by</td>
-            	<td>name</td>
-                <td><i>
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>the .modified_by in the original row before the audited action took place, should be equal to .modified_by
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>orig_tableoid</td>
-            	<td>oid</td>
-                <td><i>
-				
-
-				NOT NULL
 				
-				</i>
-				<br><br>the TG_RELID when the audit trigger was run
 				</td>
 			 </tr>
             
@@ -33347,45 +35484,13 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>audit_action</td>
+            	<td>event_by</td>
             	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>audit_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT now()
-				</i>
 				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>audit_by</td>
-            	<td>name</td>
-                <td><i>
 				
-
-				NOT NULL
-				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -33395,8 +35500,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>event_table</td>
+            	<td>regclass</td>
                 <td><i>
 				
 
@@ -33411,8 +35516,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>row_version_before</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -33427,8 +35532,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>row_version_after</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -33443,8 +35548,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>pk</td>
-            	<td>integer</td>
+            	<td>event</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -33459,8 +35564,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>fk_vaccine</td>
-            	<td>integer</td>
+            	<td>audit_when_ts</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -33475,8 +35580,8 @@ this referral.
 				<td>
                 
                 </td>
-            	<td>batch_no</td>
-            	<td>text</td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -33491,35 +35596,11 @@ this referral.
 
         <!-- Inherits -->
 		
-        <p>Table audit.log_vaccine_batches Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
-        
-        </p>
-		
 
 		
-		
-		
 
         <!-- Constraint List -->
 		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_vaccine_batches Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>audit_trail_audit_action_check</td>
-                <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
-            </tr>
-			
-		</table>
-		
 
         <!-- Foreign Key Discovery -->
 		
@@ -33529,6 +35610,126 @@ this referral.
 
 	<!-- View Definition -->
 	
+	<pre>
+SELECT to_char
+(aat.audit_when
+     ,'YYYY-MM-DD HH24:MI'::text
+) AS event_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = aat.audit_by)
+     )
+     , (
+           ('<'::text || 
+                 (aat.audit_by)::text
+           ) || '>'::text
+     )
+) AS event_by
+,
+    
+(aat.orig_tableoid)::regclass AS event_table
+,
+    aat.orig_version AS row_version_before
+,
+        CASE
+            WHEN 
+(aat.audit_action = 'DELETE'::text) THEN NULL::integer
+            ELSE 
+(aat.orig_version + 1)
+        END AS row_version_after
+,
+    aat.audit_action AS event
+,
+    aat.audit_when AS audit_when_ts
+,
+    aat.pk_audit
+   
+FROM audit.audit_trail aat
+
+UNION ALL
+ 
+SELECT to_char
+(gal.modified_when
+     ,'YYYY-MM-DD HH24:MI'::text
+) AS event_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = gal.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (gal.modified_by)::text
+           ) || '>'::text
+     )
+) AS event_by
+,
+    'gm.access_log'::regclass AS event_table
+,
+    NULL::integer AS row_version_before
+,
+    0 AS row_version_after
+,
+    gal.user_action AS event
+,
+    gal.modified_when AS audit_when_ts
+,
+    gal.pk_audit
+   
+FROM gm.access_log gal
+  
+WHERE (gal.row_version = 0)
+UNION ALL
+ 
+SELECT to_char
+(aaf.modified_when
+     ,'YYYY-MM-DD HH24:MI'::text
+) AS event_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = aaf.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (aaf.modified_by)::text
+           ) || '>'::text
+     )
+) AS event_by
+,
+    
+(aaf.tableoid)::regclass AS event_table
+,
+    NULL::integer AS row_version_before
+,
+    0 AS row_version_after
+,
+    'INSERT'::text AS event
+,
+    aaf.modified_when AS audit_when_ts
+,
+    aaf.pk_audit
+   
+FROM audit.audit_fields aaf
+  
+WHERE (aaf.row_version = 0);</pre>
+	
 
 	<!-- List off permissions -->
 	
@@ -33538,1091 +35739,230 @@ this referral.
 		<a href="gnumed-entire_schema.html#audit.schema">Schema audit</a>
     </p>
 	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-waiting-list">log_waiting_list</a>
+
+	<!-- We've gone through the table structure, now lets take a look at user functions -->
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.add-table-for-audit-name">add_table_for_audit(name)</a>
 		</h2>
+<h3>Returns: boolean</h3>
+<h3>Language: SQL</h3>
         
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_waiting_list Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT nextval('audit_trail_pk_audit_seq'::regclass)
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>orig_version</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				
-				</i>
-				<br><br>the .row_version in the original row before the audited action took place, should be equal to .row_version
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>orig_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				NOT NULL
-				
-				</i>
-				<br><br>the .modified_when in the original row before the audited action took place, should be equal to .modified_when
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>orig_by</td>
-            	<td>name</td>
-                <td><i>
-				
-
-				NOT NULL
-				
-				</i>
-				<br><br>the .modified_by in the original row before the audited action took place, should be equal to .modified_by
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>orig_tableoid</td>
-            	<td>oid</td>
-                <td><i>
-				
-
-				NOT NULL
-				
-				</i>
-				<br><br>the TG_RELID when the audit trigger was run
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>audit_action</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>audit_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT now()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>audit_by</td>
-            	<td>name</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT "current_user"()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>row_version</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>modified_by</td>
-            	<td>name</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>pk</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>fk_patient</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>registered</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>urgency</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>list_position</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>comment</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>area</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table audit.log_waiting_list Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
+        <pre>select audit.register_table_for_auditing('public', $1);</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.add-table-for-audit-name-name">add_table_for_audit(name, name)</a>
+		</h2>
+<h3>Returns: boolean</h3>
+<h3>Language: SQL</h3>
         
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_waiting_list Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>audit_trail_audit_action_check</td>
-                <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
-            </tr>
-			
-		</table>
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
+        <pre>select audit.register_table_for_auditing($1, $2);</pre>
 	
-
-	<!-- List off permissions -->
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-access-log">ft_del_access_log()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        
+        <pre>
+DECLARE
+	_is_allowed_deleter boolean;
+BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
+	INSERT INTO audit.log_access_log (
+		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
+		pk, user_action
+	) VALUES (
+		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
+		OLD.pk, OLD.user_action
+	);
+	return OLD;
+END;</pre>
 	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#audit.schema">Schema audit</a>
-    </p>
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-active-substance">ft_del_active_substance()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        
+        <pre>
+BEGIN
+	INSERT INTO audit.log_active_substance (
+		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
+		pk_audit, row_version, modified_when, modified_by, pk, description, atc_code
+	) VALUES (
+		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
+		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.atc_code
+	);
+	return OLD;
+END;</pre>
 	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.table.log-xlnk-identity">log_xlnk_identity</a>
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-address">ft_del_address()</a>
 		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
         
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.log_xlnk_identity Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT nextval('audit_trail_pk_audit_seq'::regclass)
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>orig_version</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				
-				</i>
-				<br><br>the .row_version in the original row before the audited action took place, should be equal to .row_version
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>orig_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				NOT NULL
-				
-				</i>
-				<br><br>the .modified_when in the original row before the audited action took place, should be equal to .modified_when
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>orig_by</td>
-            	<td>name</td>
-                <td><i>
-				
-
-				NOT NULL
-				
-				</i>
-				<br><br>the .modified_by in the original row before the audited action took place, should be equal to .modified_by
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>orig_tableoid</td>
-            	<td>oid</td>
-                <td><i>
-				
-
-				NOT NULL
-				
-				</i>
-				<br><br>the TG_RELID when the audit trigger was run
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>audit_action</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>audit_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT now()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>audit_by</td>
-            	<td>name</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT "current_user"()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>row_version</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>modified_by</td>
-            	<td>name</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>pk</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>xfk_identity</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>pupic</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>data</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table audit.log_xlnk_identity Inherits
+        <pre>
+DECLARE
+	_is_allowed_deleter boolean;
+BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
+	INSERT INTO audit.log_address (
+		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
+		id, id_street, aux_street, number, subunit, addendum, lat_lon
+	) VALUES (
+		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
+		OLD.id, OLD.id_street, OLD.aux_street, OLD.number, OLD.subunit, OLD.addendum, OLD.lat_lon
+	);
+	return OLD;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-allergy">ft_del_allergy()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
         
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-trail">audit_trail</a>, 
+        <pre>
+DECLARE
+	_is_allowed_deleter boolean;
+BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
+	INSERT INTO audit.log_allergy (
+		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, substance, substance_code, generics, allergene, atc_code, fk_type, generic_specific, definite
+	) VALUES (
+		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.substance, OLD.substance_code, OLD.generics, OLD.allergene, OLD.atc_code, OLD.fk_type, OLD.generic_specific, OLD.definite
+	);
+	return OLD;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-allergy-state">ft_del_allergy_state()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
         
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>audit.log_xlnk_identity Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>audit_trail_audit_action_check</td>
-                <td>CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))</td>
-            </tr>
-			
-		</table>
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
+        <pre>
+DECLARE
+	_is_allowed_deleter boolean;
+BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
+	INSERT INTO audit.log_allergy_state (
+		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
+		pk, has_allergy, comment, last_confirmed, fk_encounter
+	) VALUES (
+		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
+		OLD.pk, OLD.has_allergy, OLD.comment, OLD.last_confirmed, OLD.fk_encounter
+	);
+	return OLD;
+END;</pre>
 	
-
-	<!-- List off permissions -->
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-atc-group">ft_del_atc_group()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        
+        <pre>
+BEGIN
+	INSERT INTO audit.log_atc_group (
+		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
+		pk_audit, row_version, modified_when, modified_by, pk, code, description
+	) VALUES (
+		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
+		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.code, OLD.description
+	);
+	return OLD;
+END;</pre>
 	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#audit.schema">Schema audit</a>
-    </p>
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-atc-substance">ft_del_atc_substance()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        
+        <pre>
+BEGIN
+	INSERT INTO audit.log_atc_substance (
+		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
+		pk_audit, row_version, modified_when, modified_by, pk, code, name, ddd_amount, fk_ddd_unit, route, comment
+	) VALUES (
+		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
+		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.code, OLD.name, OLD.ddd_amount, OLD.fk_ddd_unit, OLD.route, OLD.comment
+	);
+	return OLD;
+END;</pre>
 	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.view.v-audit-trail">v_audit_trail</a>
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-auto-hint">ft_del_auto_hint()</a>
 		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>audit.v_audit_trail Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>event_when</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>event_by</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>event_table</td>
-            	<td>regclass</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>row_version_before</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>row_version_after</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>event</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>audit_when_ts</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-(
-SELECT to_char
-     (aat.audit_when
-           ,'YYYY-MM-DD HH24:MI'::text
-     ) AS event_when
-     , COALESCE
-     (
-           (
-            SELECT staff.short_alias 
-              FROM dem.staff 
-             WHERE (staff.db_user = aat.audit_by)
-           )
-           , (
-                 ('<'::text || 
-                       (aat.audit_by)::text
-                 ) || '>'::text
-           )
-     ) AS event_by
-     , (aat.orig_tableoid)::regclass AS event_table
-     , aat.orig_version AS row_version_before
-     , CASE WHEN 
-     (aat.audit_action = 'DELETE'::text) THEN NULL::integer ELSE 
-     (aat.orig_version + 1) END AS row_version_after
-     , aat.audit_action AS event
-     , aat.audit_when AS audit_when_ts
-     , aat.pk_audit 
-  FROM audit.audit_trail aat 
-UNION ALLSELECT to_char
-     (gal.modified_when
-           ,'YYYY-MM-DD HH24:MI'::text
-     ) AS event_when
-     , COALESCE
-     (
-           (
-            SELECT staff.short_alias 
-              FROM dem.staff 
-             WHERE (staff.db_user = gal.modified_by)
-           )
-           , (
-                 ('<'::text || 
-                       (gal.modified_by)::text
-                 ) || '>'::text
-           )
-     ) AS event_by
-     ,'gm.access_log'::regclass AS event_table
-     , NULL::integer AS row_version_before
-     , 0 AS row_version_after
-     , gal.user_action AS event
-     , gal.modified_when AS audit_when_ts
-     , gal.pk_audit 
-  FROM gm.access_log gal 
- WHERE (gal.row_version = 0)
-)
-UNION ALLSELECT to_char
-(aaf.modified_when
-     ,'YYYY-MM-DD HH24:MI'::text
-) AS event_when
-, COALESCE
-(
-     (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.db_user = aaf.modified_by)
-     )
-     , (
-           ('<'::text || 
-                 (aaf.modified_by)::text
-           ) || '>'::text
-     )
-) AS event_by
-, (aaf.tableoid)::regclass AS event_table
-, NULL::integer AS row_version_before
-, 0 AS row_version_after
-,'INSERT'::text AS event
-, aaf.modified_when AS audit_when_ts
-, aaf.pk_audit 
-FROM audit.audit_fields aaf 
-WHERE (aaf.row_version = 0);</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#audit.schema">Schema audit</a>
-    </p>
-	
-
-	<!-- We've gone through the table structure, now lets take a look at user functions -->
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.add-table-for-audit-name">add_table_for_audit(name)</a>
-		</h2>
-<h3>Returns: boolean</h3>
-<h3>Language: SQL</h3>
-        
-        <pre>select audit.register_table_for_auditing('public', $1);</pre>
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.add-table-for-audit-name-name">add_table_for_audit(name, name)</a>
-		</h2>
-<h3>Returns: boolean</h3>
-<h3>Language: SQL</h3>
-        
-        <pre>select audit.register_table_for_auditing($1, $2);</pre>
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-access-log">ft_del_access_log()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-BEGIN
-	INSERT INTO audit.log_access_log (
-		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, user_action
-	) VALUES (
-		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.user_action
-	);
-	return OLD;
-END;</pre>
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-active-substance">ft_del_active_substance()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-BEGIN
-	INSERT INTO audit.log_active_substance (
-		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description, atc_code
-	) VALUES (
-		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.atc_code
-	);
-	return OLD;
-END;</pre>
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-address">ft_del_address()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-BEGIN
-	INSERT INTO audit.log_address (
-		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, id_street, aux_street, number, subunit, addendum, lat_lon
-	) VALUES (
-		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.id_street, OLD.aux_street, OLD.number, OLD.subunit, OLD.addendum, OLD.lat_lon
-	);
-	return OLD;
-END;</pre>
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-allergy">ft_del_allergy()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-BEGIN
-	INSERT INTO audit.log_allergy (
-		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, substance, substance_code, generics, allergene, atc_code, fk_type, generic_specific, definite
-	) VALUES (
-		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.substance, OLD.substance_code, OLD.generics, OLD.allergene, OLD.atc_code, OLD.fk_type, OLD.generic_specific, OLD.definite
-	);
-	return OLD;
-END;</pre>
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-allergy-state">ft_del_allergy_state()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-BEGIN
-	INSERT INTO audit.log_allergy_state (
-		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, has_allergy, comment, last_confirmed, fk_encounter
-	) VALUES (
-		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.has_allergy, OLD.comment, OLD.last_confirmed, OLD.fk_encounter
-	);
-	return OLD;
-END;</pre>
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-atc-group">ft_del_atc_group()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-BEGIN
-	INSERT INTO audit.log_atc_group (
-		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, code, description
-	) VALUES (
-		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.code, OLD.description
-	);
-	return OLD;
-END;</pre>
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-atc-substance">ft_del_atc_substance()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-BEGIN
-	INSERT INTO audit.log_atc_substance (
-		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, code, name, ddd_amount, fk_ddd_unit, route, comment
-	) VALUES (
-		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.code, OLD.name, OLD.ddd_amount, OLD.fk_ddd_unit, OLD.route, OLD.comment
-	);
-	return OLD;
-END;</pre>
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-auto-hint">ft_del_auto_hint()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_auto_hint (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, query, title, hint, url, is_active, source, lang
+		pk, query, title, hint, url, is_active, source, lang, recommendation_query
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.query, OLD.title, OLD.hint, OLD.url, OLD.is_active, OLD.source, OLD.lang
+		OLD.pk, OLD.query, OLD.title, OLD.hint, OLD.url, OLD.is_active, OLD.source, OLD.lang, OLD.recommendation_query
 	);
 	return OLD;
 END;</pre>
@@ -34635,13 +35975,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_beh_fall_typ (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, code, kurzform, name
+		pk, code, kurzform, name
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.code, OLD.kurzform, OLD.name
+		OLD.pk, OLD.code, OLD.kurzform, OLD.name
 	);
 	return OLD;
 END;</pre>
@@ -34673,13 +36024,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_bill (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, invoice_id, close_date, apply_vat, fk_receiver_identity, fk_receiver_address, fk_doc, comment
+		pk, invoice_id, close_date, apply_vat, fk_receiver_identity, fk_receiver_address, fk_doc, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.invoice_id, OLD.close_date, OLD.apply_vat, OLD.fk_receiver_identity, OLD.fk_receiver_address, OLD.fk_doc, OLD.comment
+		OLD.pk, OLD.invoice_id, OLD.close_date, OLD.apply_vat, OLD.fk_receiver_identity, OLD.fk_receiver_address, OLD.fk_doc, OLD.comment
 	);
 	return OLD;
 END;</pre>
@@ -34692,13 +36054,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_bill_item (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_provider, fk_encounter, date_to_bill, description, net_amount_per_unit, currency, status, fk_billable, fk_bill, unit_count, amount_multiplier
+		pk, fk_provider, fk_encounter, date_to_bill, description, net_amount_per_unit, currency, status, fk_billable, fk_bill, unit_count, amount_multiplier
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_provider, OLD.fk_encounter, OLD.date_to_bill, OLD.description, OLD.net_amount_per_unit, OLD.currency, OLD.status, OLD.fk_billable, OLD.fk_bill, OLD.unit_count, OLD.amount_multiplier
+		OLD.pk, OLD.fk_provider, OLD.fk_encounter, OLD.date_to_bill, OLD.description, OLD.net_amount_per_unit, OLD.currency, OLD.status, OLD.fk_billable, OLD.fk_bill, OLD.unit_count, OLD.amount_multiplier
 	);
 	return OLD;
 END;</pre>
@@ -34711,13 +36084,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_branded_drug (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description, preparation, atc_code, is_fake, fk_data_source, external_code, external_code_type
+		pk, description, preparation, atc_code, is_fake, fk_data_source, external_code, external_code_type
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.preparation, OLD.atc_code, OLD.is_fake, OLD.fk_data_source, OLD.external_code, OLD.external_code_type
+		OLD.pk, OLD.description, OLD.preparation, OLD.atc_code, OLD.is_fake, OLD.fk_data_source, OLD.external_code, OLD.external_code_type
 	);
 	return OLD;
 END;</pre>
@@ -34730,13 +36114,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_clin_aux_note (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk
 	);
 	return OLD;
 END;</pre>
@@ -34749,13 +36144,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_clin_diag (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_narrative, laterality, is_chronic, is_active, is_definite, clinically_relevant
+		pk, fk_narrative, laterality, is_chronic, is_active, is_definite, clinically_relevant
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_narrative, OLD.laterality, OLD.is_chronic, OLD.is_active, OLD.is_definite, OLD.clinically_relevant
+		OLD.pk, OLD.fk_narrative, OLD.laterality, OLD.is_chronic, OLD.is_active, OLD.is_definite, OLD.clinically_relevant
 	);
 	return OLD;
 END;</pre>
@@ -34768,13 +36174,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_clin_item_type (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, type, code
+		pk, type, code
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.type, OLD.code
+		OLD.pk, OLD.type, OLD.code
 	);
 	return OLD;
 END;</pre>
@@ -34806,13 +36223,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_clin_narrative (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk
 	);
 	return OLD;
 END;</pre>
@@ -34844,13 +36272,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_consumable_substance (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description, atc_code, amount, unit
+		pk, description, atc_code, amount, unit
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.atc_code, OLD.amount, OLD.unit
+		OLD.pk, OLD.description, OLD.atc_code, OLD.amount, OLD.unit
 	);
 	return OLD;
 END;</pre>
@@ -34882,13 +36321,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_data_source (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, name_long, name_short, version, description, source, lang
+		pk, name_long, name_short, version, description, source, lang
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.name_long, OLD.name_short, OLD.version, OLD.description, OLD.source, OLD.lang
+		OLD.pk, OLD.name_long, OLD.name_short, OLD.version, OLD.description, OLD.source, OLD.lang
 	);
 	return OLD;
 END;</pre>
@@ -34901,13 +36351,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_doc_desc (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_doc, text
+		pk, fk_doc, text
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_doc, OLD.text
+		OLD.pk, OLD.fk_doc, OLD.text
 	);
 	return OLD;
 END;</pre>
@@ -34920,13 +36381,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_doc_med (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_encounter, fk_episode, fk_type, comment, clin_when, ext_ref
+		pk, fk_encounter, fk_episode, fk_type, comment, clin_when, ext_ref, fk_org_unit
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_encounter, OLD.fk_episode, OLD.fk_type, OLD.comment, OLD.clin_when, OLD.ext_ref
+		OLD.pk, OLD.fk_encounter, OLD.fk_episode, OLD.fk_type, OLD.comment, OLD.clin_when, OLD.ext_ref, OLD.fk_org_unit
 	);
 	return OLD;
 END;</pre>
@@ -34939,13 +36411,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_encounter (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_patient, fk_type, fk_location, source_time_zone, reason_for_encounter, assessment_of_encounter, started, last_affirmed
+		pk, fk_patient, fk_type, fk_location, source_time_zone, reason_for_encounter, assessment_of_encounter, started, last_affirmed
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_patient, OLD.fk_type, OLD.fk_location, OLD.source_time_zone, OLD.reason_for_encounter, OLD.assessment_of_encounter, OLD.started, OLD.last_affirmed
+		OLD.pk, OLD.fk_patient, OLD.fk_type, OLD.fk_location, OLD.source_time_zone, OLD.reason_for_encounter, OLD.assessment_of_encounter, OLD.started, OLD.last_affirmed
 	);
 	return OLD;
 END;</pre>
@@ -34958,13 +36441,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_episode (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_health_issue, description, is_open, fk_encounter, diagnostic_certainty_classification, summary
+		pk, fk_health_issue, description, is_open, fk_encounter, diagnostic_certainty_classification, summary
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_health_issue, OLD.description, OLD.is_open, OLD.fk_encounter, OLD.diagnostic_certainty_classification, OLD.summary
+		OLD.pk, OLD.fk_health_issue, OLD.description, OLD.is_open, OLD.fk_encounter, OLD.diagnostic_certainty_classification, OLD.summary
 	);
 	return OLD;
 END;</pre>
@@ -34977,13 +36471,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_external_care (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_encounter, fk_health_issue, issue, fk_org_unit, provider, comment
+		pk, fk_encounter, fk_health_issue, issue, fk_org_unit, provider, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_encounter, OLD.fk_health_issue, OLD.issue, OLD.fk_org_unit, OLD.provider, OLD.comment
+		OLD.pk, OLD.fk_encounter, OLD.fk_health_issue, OLD.issue, OLD.fk_org_unit, OLD.provider, OLD.comment
 	);
 	return OLD;
 END;</pre>
@@ -34996,13 +36501,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_family_history (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_relation_type, age_noted, age_of_death, contributed_to_death, name_relative, dob_relative, comment
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_relation_type, age_noted, age_of_death, contributed_to_death, name_relative, dob_relative, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_relation_type, OLD.age_noted, OLD.age_of_death, OLD.contributed_to_death, OLD.name_relative, OLD.dob_relative, OLD.comment
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_relation_type, OLD.age_noted, OLD.age_of_death, OLD.contributed_to_death, OLD.name_relative, OLD.dob_relative, OLD.comment
 	);
 	return OLD;
 END;</pre>
@@ -35015,13 +36531,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_fhx_relation_type (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description, is_genetic
+		pk, description, is_genetic
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.is_genetic
+		OLD.pk, OLD.description, OLD.is_genetic
 	);
 	return OLD;
 END;</pre>
@@ -35034,13 +36561,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_form_data (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_instance, fk_form_field, value
+		pk, fk_instance, fk_form_field, value
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_instance, OLD.fk_form_field, OLD.value
+		OLD.pk, OLD.fk_instance, OLD.fk_form_field, OLD.value
 	);
 	return OLD;
 END;</pre>
@@ -35072,13 +36610,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_form_instances (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_form_def, form_name
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_form_def, form_name
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_form_def, OLD.form_name
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_form_def, OLD.form_name
 	);
 	return OLD;
 END;</pre>
@@ -35091,13 +36640,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_gender_label (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, tag, label, sort_weight, comment
+		pk, tag, label, sort_weight, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.tag, OLD.label, OLD.sort_weight, OLD.comment
+		OLD.pk, OLD.tag, OLD.label, OLD.sort_weight, OLD.comment
 	);
 	return OLD;
 END;</pre>
@@ -35110,13 +36670,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_health_issue (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description, laterality, age_noted, is_active, clinically_relevant, is_confidential, is_cause_of_death, fk_encounter, grouping, diagnostic_certainty_classification, summary
+		pk, description, laterality, age_noted, is_active, clinically_relevant, is_confidential, is_cause_of_death, fk_encounter, grouping, diagnostic_certainty_classification, summary
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.laterality, OLD.age_noted, OLD.is_active, OLD.clinically_relevant, OLD.is_confidential, OLD.is_cause_of_death, OLD.fk_encounter, OLD.grouping, OLD.diagnostic_certainty_classification, OLD.summary
+		OLD.pk, OLD.description, OLD.laterality, OLD.age_noted, OLD.is_active, OLD.clinically_relevant, OLD.is_confidential, OLD.is_cause_of_death, OLD.fk_encounter, OLD.grouping, OLD.diagnostic_certainty_classification, OLD.summary
 	);
 	return OLD;
 END;</pre>
@@ -35129,13 +36700,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_hospital_stay (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, discharge, fk_org_unit
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, discharge, fk_org_unit
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.discharge, OLD.fk_org_unit
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.discharge, OLD.fk_org_unit
 	);
 	return OLD;
 END;</pre>
@@ -35167,13 +36749,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_identity (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, deleted, pupic, gender, dob, fk_marital_status, cob, deceased, title, tob, emergency_contact, fk_emergency_contact, comment, fk_primary_provider, dob_is_estimated
+		pk, deleted, gender, dob, fk_marital_status, cob, deceased, title, tob, emergency_contact, fk_emergency_contact, comment, fk_primary_provider, dob_is_estimated
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.deleted, OLD.pupic, OLD.gender, OLD.dob, OLD.fk_marital_status, OLD.cob, OLD.deceased, OLD.title, OLD.tob, OLD.emergency_contact, OLD.fk_emergency_contact, OLD.comment, OLD.fk_primary_provider, OLD.dob_is_estimated
+		OLD.pk, OLD.deleted, OLD.gender, OLD.dob, OLD.fk_marital_status, OLD.cob, OLD.deceased, OLD.title, OLD.tob, OLD.emergency_contact, OLD.fk_emergency_contact, OLD.comment, OLD.fk_primary_provider, OLD.dob_is_estimated
 	);
 	return OLD;
 END;</pre>
@@ -35186,13 +36779,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_identity_tag (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_identity, fk_tag, comment
+		pk, fk_identity, fk_tag, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_identity, OLD.fk_tag, OLD.comment
+		OLD.pk, OLD.fk_identity, OLD.fk_tag, OLD.comment
 	);
 	return OLD;
 END;</pre>
@@ -35205,13 +36809,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_inbox_item_category (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description, is_user
+		pk, description, is_user
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.is_user
+		OLD.pk, OLD.description, OLD.is_user
 	);
 	return OLD;
 END;</pre>
@@ -35224,13 +36839,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_inbox_item_type (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_inbox_item_category, description, is_user
+		pk, fk_inbox_item_category, description, is_user
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_inbox_item_category, OLD.description, OLD.is_user
+		OLD.pk, OLD.fk_inbox_item_category, OLD.description, OLD.is_user
 	);
 	return OLD;
 END;</pre>
@@ -35243,13 +36869,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_incoming_data_unmatchable (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_patient_candidates, request_id, firstnames, lastnames, dob, postcode, other_info, type, data, gender, requestor, external_data_id, fk_identity_disambiguated
+		pk, fk_patient_candidates, request_id, firstnames, lastnames, dob, postcode, other_info, type, data, gender, requestor, external_data_id, fk_identity_disambiguated
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_patient_candidates, OLD.request_id, OLD.firstnames, OLD.lastnames, OLD.dob, OLD.postcode, OLD.other_info, OLD.type, OLD.data, OLD.gender, OLD.requestor, OLD.external_data_id, OLD.fk_identity_disambiguated
+		OLD.pk, OLD.fk_patient_candidates, OLD.request_id, OLD.firstnames, OLD.lastnames, OLD.dob, OLD.postcode, OLD.other_info, OLD.type, OLD.data, OLD.gender, OLD.requestor, OLD.external_data_id, OLD.fk_identity_disambiguated
 	);
 	return OLD;
 END;</pre>
@@ -35262,13 +36899,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_incoming_data_unmatched (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_patient_candidates, request_id, firstnames, lastnames, dob, postcode, other_info, type, data, gender, requestor, external_data_id, fk_identity_disambiguated, comment, fk_provider_disambiguated
+		pk, fk_patient_candidates, request_id, firstnames, lastnames, dob, postcode, other_info, type, data, gender, requestor, external_data_id, fk_identity_disambiguated, comment, fk_provider_disambiguated
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_patient_candidates, OLD.request_id, OLD.firstnames, OLD.lastnames, OLD.dob, OLD.postcode, OLD.other_info, OLD.type, OLD.data, OLD.gender, OLD.requestor, OLD.external_data_id, OLD.fk_identity_disambiguated, OLD.comment, OLD.fk_provider_disambiguated
+		OLD.pk, OLD.fk_patient_candidates, OLD.request_id, OLD.firstnames, OLD.lastnames, OLD.dob, OLD.postcode, OLD.other_info, OLD.type, OLD.data, OLD.gender, OLD.requestor, OLD.external_data_id, OLD.fk_identity_disambiguated, OLD.comment, OLD.fk_provider_disambiguated
 	);
 	return OLD;
 END;</pre>
@@ -35281,13 +36929,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lab_request (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_test_org, request_id, fk_requestor, lab_request_id, lab_rxd_when, results_reported_when, request_status, is_pending, diagnostic_service_section, ordered_service, note_test_org
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_test_org, request_id, fk_requestor, lab_request_id, lab_rxd_when, results_reported_when, request_status, is_pending, diagnostic_service_section, ordered_service, note_test_org
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_test_org, OLD.request_id, OLD.fk_requestor, OLD.lab_request_id, OLD.lab_rxd_when, OLD.results_reported_when, OLD.request_status, OLD.is_pending, OLD.diagnostic_service_section, OLD.ordered_service, OLD.note_test_org
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_test_org, OLD.request_id, OLD.fk_requestor, OLD.lab_request_id, OLD.lab_rxd_when, OLD.results_reported_when, OLD.request_status, OLD.is_pending, OLD.diagnostic_service_section, OLD.ordered_service, OLD.note_test_org
 	);
 	return OLD;
 END;</pre>
@@ -35300,13 +36959,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lab_test_gnr (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, id_test
+		id, id_test
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.id_test
+		OLD.id, OLD.id_test
 	);
 	return OLD;
 END;</pre>
@@ -35319,13 +36989,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lnk_code2aoe (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
+		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
+		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
 	);
 	return OLD;
 END;</pre>
@@ -35338,13 +37019,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lnk_code2episode (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
+		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
+		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
 	);
 	return OLD;
 END;</pre>
@@ -35357,13 +37049,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lnk_code2fhx (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
+		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
+		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
 	);
 	return OLD;
 END;</pre>
@@ -35376,13 +37079,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lnk_code2h_issue (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
+		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
+		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
 	);
 	return OLD;
 END;</pre>
@@ -35395,13 +37109,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lnk_code2narrative (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
+		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
+		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
 	);
 	return OLD;
 END;</pre>
@@ -35414,13 +37139,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lnk_code2procedure (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
+		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
+		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
 	);
 	return OLD;
 END;</pre>
@@ -35433,13 +37169,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lnk_code2rfe (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
+		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
+		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
 	);
 	return OLD;
 END;</pre>
@@ -35452,13 +37199,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lnk_code2tst_pnl (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
+		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
+		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
 	);
 	return OLD;
 END;</pre>
@@ -35471,13 +37229,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lnk_constraint2vacc_course (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_vaccination_course, fk_constraint
+		pk, fk_vaccination_course, fk_constraint
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_vaccination_course, OLD.fk_constraint
+		OLD.pk, OLD.fk_vaccination_course, OLD.fk_constraint
 	);
 	return OLD;
 END;</pre>
@@ -35490,13 +37259,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lnk_identity2ext_id (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, id_identity, external_id, fk_origin, comment
+		id, id_identity, external_id, fk_origin, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.id_identity, OLD.external_id, OLD.fk_origin, OLD.comment
+		OLD.id, OLD.id_identity, OLD.external_id, OLD.fk_origin, OLD.comment
 	);
 	return OLD;
 END;</pre>
@@ -35528,13 +37308,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lnk_job2person (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_identity, fk_occupation, activities
+		pk, fk_identity, fk_occupation, activities
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_identity, OLD.fk_occupation, OLD.activities
+		OLD.pk, OLD.fk_identity, OLD.fk_occupation, OLD.activities
 	);
 	return OLD;
 END;</pre>
@@ -35547,13 +37338,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lnk_org_unit2comm (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_org_unit, url, fk_type, is_confidential, comment
+		pk, fk_org_unit, url, fk_type, is_confidential, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_org_unit, OLD.url, OLD.fk_type, OLD.is_confidential, OLD.comment
+		OLD.pk, OLD.fk_org_unit, OLD.url, OLD.fk_type, OLD.is_confidential, OLD.comment
 	);
 	return OLD;
 END;</pre>
@@ -35566,13 +37368,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lnk_org_unit2ext_id (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_org_unit, external_id, fk_type, comment
+		pk, fk_org_unit, external_id, fk_type, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_org_unit, OLD.external_id, OLD.fk_type, OLD.comment
+		OLD.pk, OLD.fk_org_unit, OLD.external_id, OLD.fk_type, OLD.comment
 	);
 	return OLD;
 END;</pre>
@@ -35585,13 +37398,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
-	INSERT INTO audit.log_lnk_pat2vaccination_course (
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
+	INSERT INTO audit.log_lnk_pat2vaccination_course (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_patient, fk_course
+		pk, fk_patient, fk_course
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_patient, OLD.fk_course
+		OLD.pk, OLD.fk_patient, OLD.fk_course
 	);
 	return OLD;
 END;</pre>
@@ -35604,13 +37428,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lnk_person2relative (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, id_identity, id_relative, id_relation_type, started, ended
+		id, id_identity, id_relative, id_relation_type, started, ended
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.id_identity, OLD.id_relative, OLD.id_relation_type, OLD.started, OLD.ended
+		OLD.id, OLD.id_identity, OLD.id_relative, OLD.id_relation_type, OLD.started, OLD.ended
 	);
 	return OLD;
 END;</pre>
@@ -35623,13 +37458,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lnk_substance2brand (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_brand, fk_substance
+		pk, fk_brand, fk_substance
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_brand, OLD.fk_substance
+		OLD.pk, OLD.fk_brand, OLD.fk_substance
 	);
 	return OLD;
 END;</pre>
@@ -35642,13 +37488,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lnk_tst2norm (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, id_test, id_norm
+		id, id_test, id_norm
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.id_test, OLD.id_norm
+		OLD.id, OLD.id_test, OLD.id_norm
 	);
 	return OLD;
 END;</pre>
@@ -35661,13 +37518,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lnk_type2item (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_type, fk_item
+		pk, fk_type, fk_item
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_type, OLD.fk_item
+		OLD.pk, OLD.fk_type, OLD.fk_item
 	);
 	return OLD;
 END;</pre>
@@ -35680,13 +37548,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lnk_vaccination_course2schedule (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_course, fk_schedule
+		pk, fk_course, fk_schedule
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_course, OLD.fk_schedule
+		OLD.pk, OLD.fk_course, OLD.fk_schedule
 	);
 	return OLD;
 END;</pre>
@@ -35699,13 +37578,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_lnk_vaccine2inds (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, fk_vaccine, fk_indication
+		id, fk_vaccine, fk_indication
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.fk_vaccine, OLD.fk_indication
+		OLD.id, OLD.fk_vaccine, OLD.fk_indication
 	);
 	return OLD;
 END;</pre>
@@ -35718,13 +37608,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_message_inbox (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_staff, fk_inbox_item_type, comment, data, importance, fk_patient, ufk_context, due_date, expiry_date
+		pk, fk_staff, fk_inbox_item_type, comment, data, importance, fk_patient, ufk_context, due_date, expiry_date
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_staff, OLD.fk_inbox_item_type, OLD.comment, OLD.data, OLD.importance, OLD.fk_patient, OLD.ufk_context, OLD.due_date, OLD.expiry_date
+		OLD.pk, OLD.fk_staff, OLD.fk_inbox_item_type, OLD.comment, OLD.data, OLD.importance, OLD.fk_patient, OLD.ufk_context, OLD.due_date, OLD.expiry_date
 	);
 	return OLD;
 END;</pre>
@@ -35737,13 +37638,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_occupation (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, name
+		id, name
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.name
+		OLD.id, OLD.name
 	);
 	return OLD;
 END;</pre>
@@ -35775,13 +37687,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_org (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description, fk_category, fk_data_source
+		pk, description, fk_category, fk_data_source
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.fk_category, OLD.fk_data_source
+		OLD.pk, OLD.description, OLD.fk_category, OLD.fk_data_source
 	);
 	return OLD;
 END;</pre>
@@ -35794,13 +37717,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_org_unit (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description, fk_org, fk_address, fk_category
+		pk, description, fk_org, fk_address, fk_category
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.fk_org, OLD.fk_address, OLD.fk_category
+		OLD.pk, OLD.description, OLD.fk_org, OLD.fk_address, OLD.fk_category
 	);
 	return OLD;
 END;</pre>
@@ -35813,13 +37747,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_paperwork_templates (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_template_type, instance_type, name_short, name_long, external_version, gnumed_revision, engine, in_use, filename, data, edit_after_substitution
+		pk, fk_template_type, instance_type, name_short, name_long, external_version, gnumed_revision, engine, in_use, filename, data, edit_after_substitution
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_template_type, OLD.instance_type, OLD.name_short, OLD.name_long, OLD.external_version, OLD.gnumed_revision, OLD.engine, OLD.in_use, OLD.filename, OLD.data, OLD.edit_after_substitution
+		OLD.pk, OLD.fk_template_type, OLD.instance_type, OLD.name_short, OLD.name_long, OLD.external_version, OLD.gnumed_revision, OLD.engine, OLD.in_use, OLD.filename, OLD.data, OLD.edit_after_substitution
 	);
 	return OLD;
 END;</pre>
@@ -35832,13 +37777,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_patient (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_identity, edc
+		pk, fk_identity, edc
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_identity, OLD.edc
+		OLD.pk, OLD.fk_identity, OLD.edc
 	);
 	return OLD;
 END;</pre>
@@ -35851,13 +37807,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_prax_geb_paid (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_fall, paid_amount, paid_when, paid_with
+		pk, fk_fall, paid_amount, paid_when, paid_with
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_fall, OLD.paid_amount, OLD.paid_when, OLD.paid_with
+		OLD.pk, OLD.fk_fall, OLD.paid_amount, OLD.paid_when, OLD.paid_with
 	);
 	return OLD;
 END;</pre>
@@ -35870,13 +37837,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_praxis_branch (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_org_unit
+		pk, fk_org_unit
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_org_unit
+		OLD.pk, OLD.fk_org_unit
 	);
 	return OLD;
 END;</pre>
@@ -35889,13 +37867,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_procedure (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_hospital_stay, clin_end, is_ongoing, fk_org_unit
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_hospital_stay, clin_end, is_ongoing, fk_org_unit
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_hospital_stay, OLD.clin_end, OLD.is_ongoing, OLD.fk_org_unit
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_hospital_stay, OLD.clin_end, OLD.is_ongoing, OLD.fk_org_unit
 	);
 	return OLD;
 END;</pre>
@@ -35927,108 +37916,163 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_referral (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, id, fk_referee, fk_form
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, id, fk_referee, fk_form
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.id, OLD.fk_referee, OLD.fk_form
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.id, OLD.fk_referee, OLD.fk_form
 	);
 	return OLD;
 END;</pre>
 	
 		<hr>
 		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-relation-types">ft_del_relation_types()</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-region">ft_del_region()</a>
 		</h2>
 <h3>Returns: trigger</h3>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
-	INSERT INTO audit.log_relation_types (
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
+	INSERT INTO audit.log_region (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, inverse, biological, biol_verified, description
+		pk, code, country, name
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.inverse, OLD.biological, OLD.biol_verified, OLD.description
+		OLD.pk, OLD.code, OLD.country, OLD.name
 	);
 	return OLD;
 END;</pre>
 	
 		<hr>
 		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-report-query">ft_del_report_query()</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-relation-types">ft_del_relation_types()</a>
 		</h2>
 <h3>Returns: trigger</h3>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
-	INSERT INTO audit.log_report_query (
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
+	INSERT INTO audit.log_relation_types (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, label, cmd
+		id, inverse, biological, biol_verified, description
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.label, OLD.cmd
+		OLD.id, OLD.inverse, OLD.biological, OLD.biol_verified, OLD.description
 	);
 	return OLD;
 END;</pre>
 	
 		<hr>
 		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-staff">ft_del_staff()</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-report-query">ft_del_report_query()</a>
 		</h2>
 <h3>Returns: trigger</h3>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
-	INSERT INTO audit.log_staff (
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
+	INSERT INTO audit.log_report_query (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_identity, db_user, short_alias, comment, is_active
+		pk, label, cmd
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_identity, OLD.db_user, OLD.short_alias, OLD.comment, OLD.is_active
+		OLD.pk, OLD.label, OLD.cmd
 	);
 	return OLD;
 END;</pre>
 	
 		<hr>
 		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-staff-role">ft_del_staff_role()</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-staff">ft_del_staff()</a>
 		</h2>
 <h3>Returns: trigger</h3>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
-	INSERT INTO audit.log_staff_role (
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
+	INSERT INTO audit.log_staff (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, name, comment
+		pk, fk_identity, db_user, short_alias, comment, is_active
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.name, OLD.comment
+		OLD.pk, OLD.fk_identity, OLD.db_user, OLD.short_alias, OLD.comment, OLD.is_active
 	);
 	return OLD;
 END;</pre>
 	
 		<hr>
 		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-state">ft_del_state()</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-del-staff-role">ft_del_staff_role()</a>
 		</h2>
 <h3>Returns: trigger</h3>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
 BEGIN
-	INSERT INTO audit.log_state (
+	INSERT INTO audit.log_staff_role (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, code, country, name
+		pk_audit, row_version, modified_when, modified_by, pk, name, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.code, OLD.country, OLD.name
+		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.name, OLD.comment
 	);
 	return OLD;
 END;</pre>
@@ -36041,13 +38085,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_street (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, id_urb, name, postcode, suburb, lat_lon
+		id, id_urb, name, postcode, suburb, lat_lon
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.id_urb, OLD.name, OLD.postcode, OLD.suburb, OLD.lat_lon
+		OLD.id, OLD.id_urb, OLD.name, OLD.postcode, OLD.suburb, OLD.lat_lon
 	);
 	return OLD;
 END;</pre>
@@ -36079,13 +38134,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_substance_intake (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_substance, preparation, schedule, aim, duration, intake_is_approved_of, is_long_term, discontinued, discontinue_reason, fk_drug_component
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_substance, preparation, schedule, aim, duration, intake_is_approved_of, is_long_term, discontinued, discontinue_reason, fk_drug_component, comment_on_start, harmful_use_type
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_substance, OLD.preparation, OLD.schedule, OLD.aim, OLD.duration, OLD.intake_is_approved_of, OLD.is_long_term, OLD.discontinued, OLD.discontinue_reason, OLD.fk_drug_component
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_substance, OLD.preparation, OLD.schedule, OLD.aim, OLD.duration, OLD.intake_is_approved_of, OLD.is_long_term, OLD.discontinued, OLD.discontinue_reason, OLD.fk_drug_component, OLD.comment_on_start, OLD.harmful_use_type
 	);
 	return OLD;
 END;</pre>
@@ -36098,13 +38164,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_suppressed_hint (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_encounter, fk_hint, suppressed_by, suppressed_when, rationale, md5_sum
+		pk, fk_encounter, fk_hint, suppressed_by, suppressed_when, rationale, md5_sum
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_encounter, OLD.fk_hint, OLD.suppressed_by, OLD.suppressed_when, OLD.rationale, OLD.md5_sum
+		OLD.pk, OLD.fk_encounter, OLD.fk_hint, OLD.suppressed_by, OLD.suppressed_when, OLD.rationale, OLD.md5_sum
 	);
 	return OLD;
 END;</pre>
@@ -36117,13 +38194,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_tag_image (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description, filename, image
+		pk, description, filename, image
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.filename, OLD.image
+		OLD.pk, OLD.description, OLD.filename, OLD.image
 	);
 	return OLD;
 END;</pre>
@@ -36136,13 +38224,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_test_org (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_org_unit, fk_adm_contact, fk_med_contact, comment, contact
+		pk, fk_org_unit, fk_adm_contact, fk_med_contact, comment, contact
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_org_unit, OLD.fk_adm_contact, OLD.fk_med_contact, OLD.comment, OLD.contact
+		OLD.pk, OLD.fk_org_unit, OLD.fk_adm_contact, OLD.fk_med_contact, OLD.comment, OLD.contact
 	);
 	return OLD;
 END;</pre>
@@ -36155,13 +38254,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_test_panel (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description, comment, fk_test_types
+		pk, description, comment, fk_test_types
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.comment, OLD.fk_test_types
+		OLD.pk, OLD.description, OLD.comment, OLD.fk_test_types
 	);
 	return OLD;
 END;</pre>
@@ -36174,13 +38284,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_test_result (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_type, val_num, val_alpha, val_unit, val_normal_min, val_normal_max, val_normal_range, val_target_min, val_target_max, val_target_range, abnormality_indicator, norm_ref_group, note_test_org, material, material_detail, fk_intended_reviewer, fk_request, status, source_data, val_grouping
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_type, val_num, val_alpha, val_unit, val_normal_min, val_normal_max, val_normal_range, val_target_min, val_target_max, val_target_range, abnormality_indicator, norm_ref_group, note_test_org, material, material_detail, fk_intended_reviewer, fk_request, status, source_data, val_grouping
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_type, OLD.val_num, OLD.val_alpha, OLD.val_unit, OLD.val_normal_min, OLD.val_normal_max, OLD.val_normal_range, OLD.val_target_min, OLD.val_target_max, OLD.val_target_range, OLD.abnormality_indicator, OLD.norm_ref_group, OLD.note_test_org, OLD.material, OLD.material_detail, OLD.fk_intended_reviewer, OLD.fk_request, OL [...]
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_type, OLD.val_num, OLD.val_alpha, OLD.val_unit, OLD.val_normal_min, OLD.val_normal_max, OLD.val_normal_range, OLD.val_target_min, OLD.val_target_max, OLD.val_target_range, OLD.abnormality_indicator, OLD.norm_ref_group, OLD.note_test_org, OLD.material, OLD.material_detail, OLD.fk_intended_reviewer, OLD.fk_request, OLD.status, OLD.source_data, OLD.val_grouping
 	);
 	return OLD;
 END;</pre>
@@ -36193,13 +38314,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_test_type (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_test_org, name, comment, reference_unit, loinc, abbrev, fk_meta_test_type
+		pk, fk_test_org, name, comment, reference_unit, loinc, abbrev, fk_meta_test_type
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_test_org, OLD.name, OLD.comment, OLD.reference_unit, OLD.loinc, OLD.abbrev, OLD.fk_meta_test_type
+		OLD.pk, OLD.fk_test_org, OLD.name, OLD.comment, OLD.reference_unit, OLD.loinc, OLD.abbrev, OLD.fk_meta_test_type
 	);
 	return OLD;
 END;</pre>
@@ -36212,13 +38344,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_urb (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, id_state, postcode, lat_lon, name
+		id, fk_region, postcode, lat_lon, name
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.id_state, OLD.postcode, OLD.lat_lon, OLD.name
+		OLD.id, OLD.fk_region, OLD.postcode, OLD.lat_lon, OLD.name
 	);
 	return OLD;
 END;</pre>
@@ -36231,13 +38374,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_vacc_indication (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, description, atcs_single_indication, atcs_combi_indication
+		id, description, atcs_single_indication, atcs_combi_indication
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.description, OLD.atcs_single_indication, OLD.atcs_combi_indication
+		OLD.id, OLD.description, OLD.atcs_single_indication, OLD.atcs_combi_indication
 	);
 	return OLD;
 END;</pre>
@@ -36250,13 +38404,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_vacc_route (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, abbreviation, description
+		id, abbreviation, description
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.abbreviation, OLD.description
+		OLD.id, OLD.abbreviation, OLD.description
 	);
 	return OLD;
 END;</pre>
@@ -36269,13 +38434,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_vaccination (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_provider, fk_vaccine, site, batch_no, reaction
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_provider, fk_vaccine, site, batch_no, reaction
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_provider, OLD.fk_vaccine, OLD.site, OLD.batch_no, OLD.reaction
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_provider, OLD.fk_vaccine, OLD.site, OLD.batch_no, OLD.reaction
 	);
 	return OLD;
 END;</pre>
@@ -36288,13 +38464,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_vaccination_course (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_recommended_by, fk_indication, is_active, comment
+		pk, fk_recommended_by, fk_indication, is_active, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_recommended_by, OLD.fk_indication, OLD.is_active, OLD.comment
+		OLD.pk, OLD.fk_recommended_by, OLD.fk_indication, OLD.is_active, OLD.comment
 	);
 	return OLD;
 END;</pre>
@@ -36307,13 +38494,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_vaccination_course_constraint (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description
+		pk, description
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description
+		OLD.pk, OLD.description
 	);
 	return OLD;
 END;</pre>
@@ -36326,13 +38524,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_vaccination_definition (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, fk_course, is_booster, seq_no, min_age_due, max_age_due, min_interval, comment
+		id, fk_course, is_booster, seq_no, min_age_due, max_age_due, min_interval, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.fk_course, OLD.is_booster, OLD.seq_no, OLD.min_age_due, OLD.max_age_due, OLD.min_interval, OLD.comment
+		OLD.id, OLD.fk_course, OLD.is_booster, OLD.seq_no, OLD.min_age_due, OLD.max_age_due, OLD.min_interval, OLD.comment
 	);
 	return OLD;
 END;</pre>
@@ -36345,13 +38554,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_vaccination_schedule (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, name, comment
+		pk, name, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.name, OLD.comment
+		OLD.pk, OLD.name, OLD.comment
 	);
 	return OLD;
 END;</pre>
@@ -36364,13 +38584,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_vaccine (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, id_route, is_live, min_age, max_age, comment, fk_brand
+		pk, id_route, is_live, min_age, max_age, comment, fk_brand
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.id_route, OLD.is_live, OLD.min_age, OLD.max_age, OLD.comment, OLD.fk_brand
+		OLD.pk, OLD.id_route, OLD.is_live, OLD.min_age, OLD.max_age, OLD.comment, OLD.fk_brand
 	);
 	return OLD;
 END;</pre>
@@ -36383,13 +38614,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_vaccine_batches (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_vaccine, batch_no
+		pk, fk_vaccine, batch_no
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_vaccine, OLD.batch_no
+		OLD.pk, OLD.fk_vaccine, OLD.batch_no
 	);
 	return OLD;
 END;</pre>
@@ -36402,13 +38644,24 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_deleter boolean;
 BEGIN
+	-- is the session user allowed to delete data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
+	IF _is_allowed_deleter IS FALSE THEN
+		RAISE EXCEPTION
+			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return OLD;
+	END IF;
 	INSERT INTO audit.log_waiting_list (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_patient, registered, urgency, list_position, comment, area
+		pk, fk_patient, registered, urgency, list_position, comment, area
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_patient, OLD.registered, OLD.urgency, OLD.list_position, OLD.comment, OLD.area
+		OLD.pk, OLD.fk_patient, OLD.registered, OLD.urgency, OLD.list_position, OLD.comment, OLD.area
 	);
 	return OLD;
 END;</pre>
@@ -36440,7 +38693,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36470,7 +38734,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36485,7 +38760,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36500,7 +38786,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36545,7 +38842,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36560,7 +38868,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36590,7 +38909,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36605,7 +38935,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36620,7 +38961,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36635,7 +38987,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36650,7 +39013,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36665,7 +39039,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36695,7 +39080,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36725,7 +39121,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36755,7 +39162,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36770,7 +39188,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36785,7 +39214,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36800,7 +39240,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36815,7 +39266,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36830,7 +39292,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36845,7 +39318,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36860,7 +39344,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36875,7 +39370,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36905,7 +39411,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36920,7 +39437,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36935,7 +39463,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36950,7 +39489,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36980,7 +39530,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -36995,7 +39556,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37010,7 +39582,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37025,7 +39608,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37040,7 +39634,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37055,7 +39660,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37070,7 +39686,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37085,7 +39712,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37100,7 +39738,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37115,7 +39764,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37130,7 +39790,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37145,7 +39816,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37160,7 +39842,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37175,7 +39868,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37190,7 +39894,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37205,7 +39920,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37220,7 +39946,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37235,7 +39972,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37265,7 +40013,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37280,7 +40039,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37295,7 +40065,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37310,7 +40091,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37325,7 +40117,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37340,7 +40143,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37355,7 +40169,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37370,7 +40195,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37385,7 +40221,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37400,7 +40247,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37415,7 +40273,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37430,7 +40299,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37460,7 +40340,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37475,7 +40366,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37490,7 +40392,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37505,7 +40418,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37520,7 +40444,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37535,7 +40470,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37550,7 +40496,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37580,7 +40537,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37589,13 +40557,24 @@ END;</pre>
 	
 		<hr>
 		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-ins-relation-types">ft_ins_relation_types()</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-ins-region">ft_ins_region()</a>
 		</h2>
 <h3>Returns: trigger</h3>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37604,13 +40583,24 @@ END;</pre>
 	
 		<hr>
 		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-ins-report-query">ft_ins_report_query()</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-ins-relation-types">ft_ins_relation_types()</a>
 		</h2>
 <h3>Returns: trigger</h3>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37619,13 +40609,24 @@ END;</pre>
 	
 		<hr>
 		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-ins-staff">ft_ins_staff()</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-ins-report-query">ft_ins_report_query()</a>
 		</h2>
 <h3>Returns: trigger</h3>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37634,13 +40635,24 @@ END;</pre>
 	
 		<hr>
 		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-ins-staff-role">ft_ins_staff_role()</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-ins-staff">ft_ins_staff()</a>
 		</h2>
 <h3>Returns: trigger</h3>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37649,7 +40661,7 @@ END;</pre>
 	
 		<hr>
 		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-ins-state">ft_ins_state()</a>
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-ins-staff-role">ft_ins_staff_role()</a>
 		</h2>
 <h3>Returns: trigger</h3>
 <h3>Language: PLPGSQL</h3>
@@ -37670,7 +40682,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37700,7 +40723,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37715,7 +40749,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37730,7 +40775,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37745,7 +40801,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37760,7 +40827,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37775,7 +40853,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37790,7 +40879,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37805,7 +40905,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37820,7 +40931,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37835,7 +40957,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37850,7 +40983,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37865,7 +41009,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37880,7 +41035,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37895,7 +41061,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37910,7 +41087,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37925,7 +41113,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37940,7 +41139,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37955,7 +41165,18 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_inserter boolean;
 BEGIN
+	-- is the session user allowed to insert data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
+	IF _is_allowed_inserter IS FALSE THEN
+		RAISE EXCEPTION
+			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := 0;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
@@ -37985,16 +41206,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_access_log (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, user_action
+		pk, user_action
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.user_action
+		OLD.pk, OLD.user_action
 	);
 	return NEW;
 END;</pre>
@@ -38029,16 +41261,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_address (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, id_street, aux_street, number, subunit, addendum, lat_lon
+		id, id_street, aux_street, number, subunit, addendum, lat_lon
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.id_street, OLD.aux_street, OLD.number, OLD.subunit, OLD.addendum, OLD.lat_lon
+		OLD.id, OLD.id_street, OLD.aux_street, OLD.number, OLD.subunit, OLD.addendum, OLD.lat_lon
 	);
 	return NEW;
 END;</pre>
@@ -38051,16 +41294,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_allergy (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, substance, substance_code, generics, allergene, atc_code, fk_type, generic_specific, definite
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, substance, substance_code, generics, allergene, atc_code, fk_type, generic_specific, definite
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.substance, OLD.substance_code, OLD.generics, OLD.allergene, OLD.atc_code, OLD.fk_type, OLD.generic_specific, OLD.definite
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.substance, OLD.substance_code, OLD.generics, OLD.allergene, OLD.atc_code, OLD.fk_type, OLD.generic_specific, OLD.definite
 	);
 	return NEW;
 END;</pre>
@@ -38073,16 +41327,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_allergy_state (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, has_allergy, comment, last_confirmed, fk_encounter
+		pk, has_allergy, comment, last_confirmed, fk_encounter
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.has_allergy, OLD.comment, OLD.last_confirmed, OLD.fk_encounter
+		OLD.pk, OLD.has_allergy, OLD.comment, OLD.last_confirmed, OLD.fk_encounter
 	);
 	return NEW;
 END;</pre>
@@ -38139,16 +41404,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_auto_hint (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, query, title, hint, url, is_active, source, lang
+		pk, query, title, hint, url, is_active, source, lang, recommendation_query
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.query, OLD.title, OLD.hint, OLD.url, OLD.is_active, OLD.source, OLD.lang
+		OLD.pk, OLD.query, OLD.title, OLD.hint, OLD.url, OLD.is_active, OLD.source, OLD.lang, OLD.recommendation_query
 	);
 	return NEW;
 END;</pre>
@@ -38161,16 +41437,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_beh_fall_typ (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, code, kurzform, name
+		pk, code, kurzform, name
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.code, OLD.kurzform, OLD.name
+		OLD.pk, OLD.code, OLD.kurzform, OLD.name
 	);
 	return NEW;
 END;</pre>
@@ -38205,16 +41492,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_bill (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, invoice_id, close_date, apply_vat, fk_receiver_identity, fk_receiver_address, fk_doc, comment
+		pk, invoice_id, close_date, apply_vat, fk_receiver_identity, fk_receiver_address, fk_doc, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.invoice_id, OLD.close_date, OLD.apply_vat, OLD.fk_receiver_identity, OLD.fk_receiver_address, OLD.fk_doc, OLD.comment
+		OLD.pk, OLD.invoice_id, OLD.close_date, OLD.apply_vat, OLD.fk_receiver_identity, OLD.fk_receiver_address, OLD.fk_doc, OLD.comment
 	);
 	return NEW;
 END;</pre>
@@ -38227,16 +41525,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_bill_item (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_provider, fk_encounter, date_to_bill, description, net_amount_per_unit, currency, status, fk_billable, fk_bill, unit_count, amount_multiplier
+		pk, fk_provider, fk_encounter, date_to_bill, description, net_amount_per_unit, currency, status, fk_billable, fk_bill, unit_count, amount_multiplier
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_provider, OLD.fk_encounter, OLD.date_to_bill, OLD.description, OLD.net_amount_per_unit, OLD.currency, OLD.status, OLD.fk_billable, OLD.fk_bill, OLD.unit_count, OLD.amount_multiplier
+		OLD.pk, OLD.fk_provider, OLD.fk_encounter, OLD.date_to_bill, OLD.description, OLD.net_amount_per_unit, OLD.currency, OLD.status, OLD.fk_billable, OLD.fk_bill, OLD.unit_count, OLD.amount_multiplier
 	);
 	return NEW;
 END;</pre>
@@ -38249,16 +41558,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_branded_drug (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description, preparation, atc_code, is_fake, fk_data_source, external_code, external_code_type
+		pk, description, preparation, atc_code, is_fake, fk_data_source, external_code, external_code_type
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.preparation, OLD.atc_code, OLD.is_fake, OLD.fk_data_source, OLD.external_code, OLD.external_code_type
+		OLD.pk, OLD.description, OLD.preparation, OLD.atc_code, OLD.is_fake, OLD.fk_data_source, OLD.external_code, OLD.external_code_type
 	);
 	return NEW;
 END;</pre>
@@ -38271,16 +41591,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_clin_aux_note (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk
 	);
 	return NEW;
 END;</pre>
@@ -38293,16 +41624,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_clin_diag (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_narrative, laterality, is_chronic, is_active, is_definite, clinically_relevant
+		pk, fk_narrative, laterality, is_chronic, is_active, is_definite, clinically_relevant
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_narrative, OLD.laterality, OLD.is_chronic, OLD.is_active, OLD.is_definite, OLD.clinically_relevant
+		OLD.pk, OLD.fk_narrative, OLD.laterality, OLD.is_chronic, OLD.is_active, OLD.is_definite, OLD.clinically_relevant
 	);
 	return NEW;
 END;</pre>
@@ -38315,16 +41657,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_clin_item_type (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, type, code
+		pk, type, code
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.type, OLD.code
+		OLD.pk, OLD.type, OLD.code
 	);
 	return NEW;
 END;</pre>
@@ -38359,16 +41712,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_clin_narrative (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk
 	);
 	return NEW;
 END;</pre>
@@ -38403,16 +41767,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_consumable_substance (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description, atc_code, amount, unit
+		pk, description, atc_code, amount, unit
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.atc_code, OLD.amount, OLD.unit
+		OLD.pk, OLD.description, OLD.atc_code, OLD.amount, OLD.unit
 	);
 	return NEW;
 END;</pre>
@@ -38447,16 +41822,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_data_source (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, name_long, name_short, version, description, source, lang
+		pk, name_long, name_short, version, description, source, lang
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.name_long, OLD.name_short, OLD.version, OLD.description, OLD.source, OLD.lang
+		OLD.pk, OLD.name_long, OLD.name_short, OLD.version, OLD.description, OLD.source, OLD.lang
 	);
 	return NEW;
 END;</pre>
@@ -38469,16 +41855,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_doc_desc (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_doc, text
+		pk, fk_doc, text
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_doc, OLD.text
+		OLD.pk, OLD.fk_doc, OLD.text
 	);
 	return NEW;
 END;</pre>
@@ -38491,16 +41888,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_doc_med (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_encounter, fk_episode, fk_type, comment, clin_when, ext_ref
+		pk, fk_encounter, fk_episode, fk_type, comment, clin_when, ext_ref, fk_org_unit
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_encounter, OLD.fk_episode, OLD.fk_type, OLD.comment, OLD.clin_when, OLD.ext_ref
+		OLD.pk, OLD.fk_encounter, OLD.fk_episode, OLD.fk_type, OLD.comment, OLD.clin_when, OLD.ext_ref, OLD.fk_org_unit
 	);
 	return NEW;
 END;</pre>
@@ -38513,16 +41921,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_encounter (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_patient, fk_type, fk_location, source_time_zone, reason_for_encounter, assessment_of_encounter, started, last_affirmed
+		pk, fk_patient, fk_type, fk_location, source_time_zone, reason_for_encounter, assessment_of_encounter, started, last_affirmed
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_patient, OLD.fk_type, OLD.fk_location, OLD.source_time_zone, OLD.reason_for_encounter, OLD.assessment_of_encounter, OLD.started, OLD.last_affirmed
+		OLD.pk, OLD.fk_patient, OLD.fk_type, OLD.fk_location, OLD.source_time_zone, OLD.reason_for_encounter, OLD.assessment_of_encounter, OLD.started, OLD.last_affirmed
 	);
 	return NEW;
 END;</pre>
@@ -38535,16 +41954,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_episode (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_health_issue, description, is_open, fk_encounter, diagnostic_certainty_classification, summary
+		pk, fk_health_issue, description, is_open, fk_encounter, diagnostic_certainty_classification, summary
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_health_issue, OLD.description, OLD.is_open, OLD.fk_encounter, OLD.diagnostic_certainty_classification, OLD.summary
+		OLD.pk, OLD.fk_health_issue, OLD.description, OLD.is_open, OLD.fk_encounter, OLD.diagnostic_certainty_classification, OLD.summary
 	);
 	return NEW;
 END;</pre>
@@ -38557,16 +41987,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_external_care (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_encounter, fk_health_issue, issue, fk_org_unit, provider, comment
+		pk, fk_encounter, fk_health_issue, issue, fk_org_unit, provider, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_encounter, OLD.fk_health_issue, OLD.issue, OLD.fk_org_unit, OLD.provider, OLD.comment
+		OLD.pk, OLD.fk_encounter, OLD.fk_health_issue, OLD.issue, OLD.fk_org_unit, OLD.provider, OLD.comment
 	);
 	return NEW;
 END;</pre>
@@ -38579,16 +42020,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_family_history (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_relation_type, age_noted, age_of_death, contributed_to_death, name_relative, dob_relative, comment
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_relation_type, age_noted, age_of_death, contributed_to_death, name_relative, dob_relative, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_relation_type, OLD.age_noted, OLD.age_of_death, OLD.contributed_to_death, OLD.name_relative, OLD.dob_relative, OLD.comment
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_relation_type, OLD.age_noted, OLD.age_of_death, OLD.contributed_to_death, OLD.name_relative, OLD.dob_relative, OLD.comment
 	);
 	return NEW;
 END;</pre>
@@ -38601,16 +42053,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_fhx_relation_type (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description, is_genetic
+		pk, description, is_genetic
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.is_genetic
+		OLD.pk, OLD.description, OLD.is_genetic
 	);
 	return NEW;
 END;</pre>
@@ -38623,16 +42086,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_form_data (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_instance, fk_form_field, value
+		pk, fk_instance, fk_form_field, value
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_instance, OLD.fk_form_field, OLD.value
+		OLD.pk, OLD.fk_instance, OLD.fk_form_field, OLD.value
 	);
 	return NEW;
 END;</pre>
@@ -38667,16 +42141,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_form_instances (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_form_def, form_name
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_form_def, form_name
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_form_def, OLD.form_name
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_form_def, OLD.form_name
 	);
 	return NEW;
 END;</pre>
@@ -38689,16 +42174,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_gender_label (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, tag, label, sort_weight, comment
+		pk, tag, label, sort_weight, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.tag, OLD.label, OLD.sort_weight, OLD.comment
+		OLD.pk, OLD.tag, OLD.label, OLD.sort_weight, OLD.comment
 	);
 	return NEW;
 END;</pre>
@@ -38711,16 +42207,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_health_issue (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description, laterality, age_noted, is_active, clinically_relevant, is_confidential, is_cause_of_death, fk_encounter, grouping, diagnostic_certainty_classification, summary
+		pk, description, laterality, age_noted, is_active, clinically_relevant, is_confidential, is_cause_of_death, fk_encounter, grouping, diagnostic_certainty_classification, summary
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.laterality, OLD.age_noted, OLD.is_active, OLD.clinically_relevant, OLD.is_confidential, OLD.is_cause_of_death, OLD.fk_encounter, OLD.grouping, OLD.diagnostic_certainty_classification, OLD.summary
+		OLD.pk, OLD.description, OLD.laterality, OLD.age_noted, OLD.is_active, OLD.clinically_relevant, OLD.is_confidential, OLD.is_cause_of_death, OLD.fk_encounter, OLD.grouping, OLD.diagnostic_certainty_classification, OLD.summary
 	);
 	return NEW;
 END;</pre>
@@ -38733,16 +42240,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_hospital_stay (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, discharge, fk_org_unit
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, discharge, fk_org_unit
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.discharge, OLD.fk_org_unit
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.discharge, OLD.fk_org_unit
 	);
 	return NEW;
 END;</pre>
@@ -38777,16 +42295,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_identity (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, deleted, pupic, gender, dob, fk_marital_status, cob, deceased, title, tob, emergency_contact, fk_emergency_contact, comment, fk_primary_provider, dob_is_estimated
+		pk, deleted, gender, dob, fk_marital_status, cob, deceased, title, tob, emergency_contact, fk_emergency_contact, comment, fk_primary_provider, dob_is_estimated
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.deleted, OLD.pupic, OLD.gender, OLD.dob, OLD.fk_marital_status, OLD.cob, OLD.deceased, OLD.title, OLD.tob, OLD.emergency_contact, OLD.fk_emergency_contact, OLD.comment, OLD.fk_primary_provider, OLD.dob_is_estimated
+		OLD.pk, OLD.deleted, OLD.gender, OLD.dob, OLD.fk_marital_status, OLD.cob, OLD.deceased, OLD.title, OLD.tob, OLD.emergency_contact, OLD.fk_emergency_contact, OLD.comment, OLD.fk_primary_provider, OLD.dob_is_estimated
 	);
 	return NEW;
 END;</pre>
@@ -38799,16 +42328,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_identity_tag (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_identity, fk_tag, comment
+		pk, fk_identity, fk_tag, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_identity, OLD.fk_tag, OLD.comment
+		OLD.pk, OLD.fk_identity, OLD.fk_tag, OLD.comment
 	);
 	return NEW;
 END;</pre>
@@ -38821,16 +42361,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_inbox_item_category (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description, is_user
+		pk, description, is_user
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.is_user
+		OLD.pk, OLD.description, OLD.is_user
 	);
 	return NEW;
 END;</pre>
@@ -38843,16 +42394,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_inbox_item_type (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_inbox_item_category, description, is_user
+		pk, fk_inbox_item_category, description, is_user
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_inbox_item_category, OLD.description, OLD.is_user
+		OLD.pk, OLD.fk_inbox_item_category, OLD.description, OLD.is_user
 	);
 	return NEW;
 END;</pre>
@@ -38865,16 +42427,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_incoming_data_unmatchable (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_patient_candidates, request_id, firstnames, lastnames, dob, postcode, other_info, type, data, gender, requestor, external_data_id, fk_identity_disambiguated
+		pk, fk_patient_candidates, request_id, firstnames, lastnames, dob, postcode, other_info, type, data, gender, requestor, external_data_id, fk_identity_disambiguated
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_patient_candidates, OLD.request_id, OLD.firstnames, OLD.lastnames, OLD.dob, OLD.postcode, OLD.other_info, OLD.type, OLD.data, OLD.gender, OLD.requestor, OLD.external_data_id, OLD.fk_identity_disambiguated
+		OLD.pk, OLD.fk_patient_candidates, OLD.request_id, OLD.firstnames, OLD.lastnames, OLD.dob, OLD.postcode, OLD.other_info, OLD.type, OLD.data, OLD.gender, OLD.requestor, OLD.external_data_id, OLD.fk_identity_disambiguated
 	);
 	return NEW;
 END;</pre>
@@ -38887,16 +42460,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_incoming_data_unmatched (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_patient_candidates, request_id, firstnames, lastnames, dob, postcode, other_info, type, data, gender, requestor, external_data_id, fk_identity_disambiguated, comment, fk_provider_disambiguated
+		pk, fk_patient_candidates, request_id, firstnames, lastnames, dob, postcode, other_info, type, data, gender, requestor, external_data_id, fk_identity_disambiguated, comment, fk_provider_disambiguated
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_patient_candidates, OLD.request_id, OLD.firstnames, OLD.lastnames, OLD.dob, OLD.postcode, OLD.other_info, OLD.type, OLD.data, OLD.gender, OLD.requestor, OLD.external_data_id, OLD.fk_identity_disambiguated, OLD.comment, OLD.fk_provider_disambiguated
+		OLD.pk, OLD.fk_patient_candidates, OLD.request_id, OLD.firstnames, OLD.lastnames, OLD.dob, OLD.postcode, OLD.other_info, OLD.type, OLD.data, OLD.gender, OLD.requestor, OLD.external_data_id, OLD.fk_identity_disambiguated, OLD.comment, OLD.fk_provider_disambiguated
 	);
 	return NEW;
 END;</pre>
@@ -38909,16 +42493,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lab_request (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_test_org, request_id, fk_requestor, lab_request_id, lab_rxd_when, results_reported_when, request_status, is_pending, diagnostic_service_section, ordered_service, note_test_org
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_test_org, request_id, fk_requestor, lab_request_id, lab_rxd_when, results_reported_when, request_status, is_pending, diagnostic_service_section, ordered_service, note_test_org
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_test_org, OLD.request_id, OLD.fk_requestor, OLD.lab_request_id, OLD.lab_rxd_when, OLD.results_reported_when, OLD.request_status, OLD.is_pending, OLD.diagnostic_service_section, OLD.ordered_service, OLD.note_test_org
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_test_org, OLD.request_id, OLD.fk_requestor, OLD.lab_request_id, OLD.lab_rxd_when, OLD.results_reported_when, OLD.request_status, OLD.is_pending, OLD.diagnostic_service_section, OLD.ordered_service, OLD.note_test_org
 	);
 	return NEW;
 END;</pre>
@@ -38931,16 +42526,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lab_test_gnr (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, id_test
+		id, id_test
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.id_test
+		OLD.id, OLD.id_test
 	);
 	return NEW;
 END;</pre>
@@ -38953,16 +42559,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_code2aoe (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
+		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
+		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
 	);
 	return NEW;
 END;</pre>
@@ -38975,16 +42592,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_code2episode (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
+		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
+		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
 	);
 	return NEW;
 END;</pre>
@@ -38997,16 +42625,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_code2fhx (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
+		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
+		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
 	);
 	return NEW;
 END;</pre>
@@ -39019,16 +42658,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_code2h_issue (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
+		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
+		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
 	);
 	return NEW;
 END;</pre>
@@ -39041,16 +42691,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_code2narrative (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
+		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
+		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
 	);
 	return NEW;
 END;</pre>
@@ -39063,16 +42724,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_code2procedure (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
+		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
+		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
 	);
 	return NEW;
 END;</pre>
@@ -39085,16 +42757,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_code2rfe (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
+		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
+		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
 	);
 	return NEW;
 END;</pre>
@@ -39107,16 +42790,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_code2tst_pnl (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
+		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
+		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
 	);
 	return NEW;
 END;</pre>
@@ -39129,16 +42823,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_constraint2vacc_course (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_vaccination_course, fk_constraint
+		pk, fk_vaccination_course, fk_constraint
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_vaccination_course, OLD.fk_constraint
+		OLD.pk, OLD.fk_vaccination_course, OLD.fk_constraint
 	);
 	return NEW;
 END;</pre>
@@ -39151,16 +42856,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_identity2ext_id (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, id_identity, external_id, fk_origin, comment
+		id, id_identity, external_id, fk_origin, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.id_identity, OLD.external_id, OLD.fk_origin, OLD.comment
+		OLD.id, OLD.id_identity, OLD.external_id, OLD.fk_origin, OLD.comment
 	);
 	return NEW;
 END;</pre>
@@ -39195,16 +42911,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_job2person (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_identity, fk_occupation, activities
+		pk, fk_identity, fk_occupation, activities
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_identity, OLD.fk_occupation, OLD.activities
+		OLD.pk, OLD.fk_identity, OLD.fk_occupation, OLD.activities
 	);
 	return NEW;
 END;</pre>
@@ -39217,16 +42944,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_org_unit2comm (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_org_unit, url, fk_type, is_confidential, comment
+		pk, fk_org_unit, url, fk_type, is_confidential, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_org_unit, OLD.url, OLD.fk_type, OLD.is_confidential, OLD.comment
+		OLD.pk, OLD.fk_org_unit, OLD.url, OLD.fk_type, OLD.is_confidential, OLD.comment
 	);
 	return NEW;
 END;</pre>
@@ -39239,16 +42977,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_org_unit2ext_id (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_org_unit, external_id, fk_type, comment
+		pk, fk_org_unit, external_id, fk_type, comment
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_org_unit, OLD.external_id, OLD.fk_type, OLD.comment
+		OLD.pk, OLD.fk_org_unit, OLD.external_id, OLD.fk_type, OLD.comment
 	);
 	return NEW;
 END;</pre>
@@ -39261,16 +43010,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_pat2vaccination_course (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_patient, fk_course
+		pk, fk_patient, fk_course
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_patient, OLD.fk_course
+		OLD.pk, OLD.fk_patient, OLD.fk_course
 	);
 	return NEW;
 END;</pre>
@@ -39283,16 +43043,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_person2relative (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, id_identity, id_relative, id_relation_type, started, ended
+		id, id_identity, id_relative, id_relation_type, started, ended
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.id_identity, OLD.id_relative, OLD.id_relation_type, OLD.started, OLD.ended
+		OLD.id, OLD.id_identity, OLD.id_relative, OLD.id_relation_type, OLD.started, OLD.ended
 	);
 	return NEW;
 END;</pre>
@@ -39305,16 +43076,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_substance2brand (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_brand, fk_substance
+		pk, fk_brand, fk_substance
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_brand, OLD.fk_substance
+		OLD.pk, OLD.fk_brand, OLD.fk_substance
 	);
 	return NEW;
 END;</pre>
@@ -39327,16 +43109,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_tst2norm (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, id_test, id_norm
+		id, id_test, id_norm
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.id_test, OLD.id_norm
+		OLD.id, OLD.id_test, OLD.id_norm
 	);
 	return NEW;
 END;</pre>
@@ -39349,16 +43142,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_type2item (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_type, fk_item
+		pk, fk_type, fk_item
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_type, OLD.fk_item
+		OLD.pk, OLD.fk_type, OLD.fk_item
 	);
 	return NEW;
 END;</pre>
@@ -39371,16 +43175,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_vaccination_course2schedule (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_course, fk_schedule
+		pk, fk_course, fk_schedule
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_course, OLD.fk_schedule
+		OLD.pk, OLD.fk_course, OLD.fk_schedule
 	);
 	return NEW;
 END;</pre>
@@ -39393,16 +43208,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_lnk_vaccine2inds (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, fk_vaccine, fk_indication
+		id, fk_vaccine, fk_indication
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.fk_vaccine, OLD.fk_indication
+		OLD.id, OLD.fk_vaccine, OLD.fk_indication
 	);
 	return NEW;
 END;</pre>
@@ -39415,16 +43241,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_message_inbox (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_staff, fk_inbox_item_type, comment, data, importance, fk_patient, ufk_context, due_date, expiry_date
+		pk, fk_staff, fk_inbox_item_type, comment, data, importance, fk_patient, ufk_context, due_date, expiry_date
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_staff, OLD.fk_inbox_item_type, OLD.comment, OLD.data, OLD.importance, OLD.fk_patient, OLD.ufk_context, OLD.due_date, OLD.expiry_date
+		OLD.pk, OLD.fk_staff, OLD.fk_inbox_item_type, OLD.comment, OLD.data, OLD.importance, OLD.fk_patient, OLD.ufk_context, OLD.due_date, OLD.expiry_date
 	);
 	return NEW;
 END;</pre>
@@ -39437,16 +43274,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_occupation (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, name
+		id, name
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.name
+		OLD.id, OLD.name
 	);
 	return NEW;
 END;</pre>
@@ -39481,16 +43329,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_org (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description, fk_category, fk_data_source
+		pk, description, fk_category, fk_data_source
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.fk_category, OLD.fk_data_source
+		OLD.pk, OLD.description, OLD.fk_category, OLD.fk_data_source
 	);
 	return NEW;
 END;</pre>
@@ -39503,16 +43362,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_org_unit (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description, fk_org, fk_address, fk_category
+		pk, description, fk_org, fk_address, fk_category
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.fk_org, OLD.fk_address, OLD.fk_category
+		OLD.pk, OLD.description, OLD.fk_org, OLD.fk_address, OLD.fk_category
 	);
 	return NEW;
 END;</pre>
@@ -39525,16 +43395,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_paperwork_templates (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_template_type, instance_type, name_short, name_long, external_version, gnumed_revision, engine, in_use, filename, data, edit_after_substitution
+		pk, fk_template_type, instance_type, name_short, name_long, external_version, gnumed_revision, engine, in_use, filename, data, edit_after_substitution
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_template_type, OLD.instance_type, OLD.name_short, OLD.name_long, OLD.external_version, OLD.gnumed_revision, OLD.engine, OLD.in_use, OLD.filename, OLD.data, OLD.edit_after_substitution
+		OLD.pk, OLD.fk_template_type, OLD.instance_type, OLD.name_short, OLD.name_long, OLD.external_version, OLD.gnumed_revision, OLD.engine, OLD.in_use, OLD.filename, OLD.data, OLD.edit_after_substitution
 	);
 	return NEW;
 END;</pre>
@@ -39547,16 +43428,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_patient (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_identity, edc
+		pk, fk_identity, edc
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_identity, OLD.edc
+		OLD.pk, OLD.fk_identity, OLD.edc
 	);
 	return NEW;
 END;</pre>
@@ -39569,16 +43461,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_prax_geb_paid (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_fall, paid_amount, paid_when, paid_with
+		pk, fk_fall, paid_amount, paid_when, paid_with
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_fall, OLD.paid_amount, OLD.paid_when, OLD.paid_with
+		OLD.pk, OLD.fk_fall, OLD.paid_amount, OLD.paid_when, OLD.paid_with
 	);
 	return NEW;
 END;</pre>
@@ -39591,16 +43494,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_praxis_branch (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_org_unit
+		pk, fk_org_unit
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_org_unit
+		OLD.pk, OLD.fk_org_unit
 	);
 	return NEW;
 END;</pre>
@@ -39613,16 +43527,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_procedure (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_hospital_stay, clin_end, is_ongoing, fk_org_unit
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_hospital_stay, clin_end, is_ongoing, fk_org_unit
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_hospital_stay, OLD.clin_end, OLD.is_ongoing, OLD.fk_org_unit
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_hospital_stay, OLD.clin_end, OLD.is_ongoing, OLD.fk_org_unit
 	);
 	return NEW;
 END;</pre>
@@ -39657,16 +43582,60 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_referral (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, id, fk_referee, fk_form
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, id, fk_referee, fk_form
+	) VALUES (
+		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.id, OLD.fk_referee, OLD.fk_form
+	);
+	return NEW;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-upd-region">ft_upd_region()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        
+        <pre>
+DECLARE
+	_is_allowed_updater boolean;
+BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
+	NEW.row_version := OLD.row_version + 1;
+	NEW.modified_when := CURRENT_TIMESTAMP;
+	NEW.modified_by := SESSION_USER;
+	INSERT INTO audit.log_region (
+		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
+		pk, code, country, name
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.id, OLD.fk_referee, OLD.fk_form
+		OLD.pk, OLD.code, OLD.country, OLD.name
 	);
 	return NEW;
 END;</pre>
@@ -39679,16 +43648,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_relation_types (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, inverse, biological, biol_verified, description
+		id, inverse, biological, biol_verified, description
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.inverse, OLD.biological, OLD.biol_verified, OLD.description
+		OLD.id, OLD.inverse, OLD.biological, OLD.biol_verified, OLD.description
 	);
 	return NEW;
 END;</pre>
@@ -39701,16 +43681,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_report_query (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, label, cmd
+		pk, label, cmd
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.label, OLD.cmd
+		OLD.pk, OLD.label, OLD.cmd
 	);
 	return NEW;
 END;</pre>
@@ -39723,16 +43714,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_staff (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_identity, db_user, short_alias, comment, is_active
+		pk, fk_identity, db_user, short_alias, comment, is_active
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_identity, OLD.db_user, OLD.short_alias, OLD.comment, OLD.is_active
+		OLD.pk, OLD.fk_identity, OLD.db_user, OLD.short_alias, OLD.comment, OLD.is_active
 	);
 	return NEW;
 END;</pre>
@@ -39761,44 +43763,33 @@ END;</pre>
 	
 		<hr>
 		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-upd-state">ft_upd_state()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-BEGIN
-	NEW.row_version := OLD.row_version + 1;
-	NEW.modified_when := CURRENT_TIMESTAMP;
-	NEW.modified_by := SESSION_USER;
-	INSERT INTO audit.log_state (
-		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, code, country, name
-	) VALUES (
-		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.code, OLD.country, OLD.name
-	);
-	return NEW;
-END;</pre>
-	
-		<hr>
-		<h2>Function:
 			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-upd-street">ft_upd_street()</a>
 		</h2>
 <h3>Returns: trigger</h3>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_street (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, id_urb, name, postcode, suburb, lat_lon
+		id, id_urb, name, postcode, suburb, lat_lon
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.id_urb, OLD.name, OLD.postcode, OLD.suburb, OLD.lat_lon
+		OLD.id, OLD.id_urb, OLD.name, OLD.postcode, OLD.suburb, OLD.lat_lon
 	);
 	return NEW;
 END;</pre>
@@ -39833,16 +43824,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_substance_intake (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_substance, preparation, schedule, aim, duration, intake_is_approved_of, is_long_term, discontinued, discontinue_reason, fk_drug_component
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_substance, preparation, schedule, aim, duration, intake_is_approved_of, is_long_term, discontinued, discontinue_reason, fk_drug_component, comment_on_start, harmful_use_type
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_substance, OLD.preparation, OLD.schedule, OLD.aim, OLD.duration, OLD.intake_is_approved_of, OLD.is_long_term, OLD.discontinued, OLD.discontinue_reason, OLD.fk_drug_component
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_substance, OLD.preparation, OLD.schedule, OLD.aim, OLD.duration, OLD.intake_is_approved_of, OLD.is_long_term, OLD.discontinued, OLD.discontinue_reason, OLD.fk_drug_component, OLD.comment_on_start, OLD.harmful_use_type
 	);
 	return NEW;
 END;</pre>
@@ -39855,16 +43857,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_suppressed_hint (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_encounter, fk_hint, suppressed_by, suppressed_when, rationale, md5_sum
+		pk, fk_encounter, fk_hint, suppressed_by, suppressed_when, rationale, md5_sum
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_encounter, OLD.fk_hint, OLD.suppressed_by, OLD.suppressed_when, OLD.rationale, OLD.md5_sum
+		OLD.pk, OLD.fk_encounter, OLD.fk_hint, OLD.suppressed_by, OLD.suppressed_when, OLD.rationale, OLD.md5_sum
 	);
 	return NEW;
 END;</pre>
@@ -39877,16 +43890,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_tag_image (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description, filename, image
+		pk, description, filename, image
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.filename, OLD.image
+		OLD.pk, OLD.description, OLD.filename, OLD.image
 	);
 	return NEW;
 END;</pre>
@@ -39899,16 +43923,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_test_org (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_org_unit, fk_adm_contact, fk_med_contact, comment, contact
+		pk, fk_org_unit, fk_adm_contact, fk_med_contact, comment, contact
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_org_unit, OLD.fk_adm_contact, OLD.fk_med_contact, OLD.comment, OLD.contact
+		OLD.pk, OLD.fk_org_unit, OLD.fk_adm_contact, OLD.fk_med_contact, OLD.comment, OLD.contact
 	);
 	return NEW;
 END;</pre>
@@ -39921,16 +43956,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_test_panel (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description, comment, fk_test_types
+		pk, description, comment, fk_test_types
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.comment, OLD.fk_test_types
+		OLD.pk, OLD.description, OLD.comment, OLD.fk_test_types
 	);
 	return NEW;
 END;</pre>
@@ -39943,16 +43989,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_test_result (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_type, val_num, val_alpha, val_unit, val_normal_min, val_normal_max, val_normal_range, val_target_min, val_target_max, val_target_range, abnormality_indicator, norm_ref_group, note_test_org, material, material_detail, fk_intended_reviewer, fk_request, status, source_data, val_grouping
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_type, val_num, val_alpha, val_unit, val_normal_min, val_normal_max, val_normal_range, val_target_min, val_target_max, val_target_range, abnormality_indicator, norm_ref_group, note_test_org, material, material_detail, fk_intended_reviewer, fk_request, status, source_data, val_grouping
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_type, OLD.val_num, OLD.val_alpha, OLD.val_unit, OLD.val_normal_min, OLD.val_normal_max, OLD.val_normal_range, OLD.val_target_min, OLD.val_target_max, OLD.val_target_range, OLD.abnormality_indicator, OLD.norm_ref_group, OLD.note_test_org, OLD.material, OLD.material_detail, OLD.fk_intended_reviewer, OLD.fk_request, OL [...]
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_type, OLD.val_num, OLD.val_alpha, OLD.val_unit, OLD.val_normal_min, OLD.val_normal_max, OLD.val_normal_range, OLD.val_target_min, OLD.val_target_max, OLD.val_target_range, OLD.abnormality_indicator, OLD.norm_ref_group, OLD.note_test_org, OLD.material, OLD.material_detail, OLD.fk_intended_reviewer, OLD.fk_request, OLD.status, OLD.source_data, OLD.val_grouping
 	);
 	return NEW;
 END;</pre>
@@ -39965,16 +44022,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_test_type (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_test_org, name, comment, reference_unit, loinc, abbrev, fk_meta_test_type
+		pk, fk_test_org, name, comment, reference_unit, loinc, abbrev, fk_meta_test_type
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_test_org, OLD.name, OLD.comment, OLD.reference_unit, OLD.loinc, OLD.abbrev, OLD.fk_meta_test_type
+		OLD.pk, OLD.fk_test_org, OLD.name, OLD.comment, OLD.reference_unit, OLD.loinc, OLD.abbrev, OLD.fk_meta_test_type
 	);
 	return NEW;
 END;</pre>
@@ -39987,16 +44055,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_urb (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, id_state, postcode, lat_lon, name
+		id, fk_region, postcode, lat_lon, name
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.id_state, OLD.postcode, OLD.lat_lon, OLD.name
+		OLD.id, OLD.fk_region, OLD.postcode, OLD.lat_lon, OLD.name
 	);
 	return NEW;
 END;</pre>
@@ -40009,16 +44088,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_vacc_indication (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, description, atcs_single_indication, atcs_combi_indication
+		id, description, atcs_single_indication, atcs_combi_indication
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.description, OLD.atcs_single_indication, OLD.atcs_combi_indication
+		OLD.id, OLD.description, OLD.atcs_single_indication, OLD.atcs_combi_indication
 	);
 	return NEW;
 END;</pre>
@@ -40031,16 +44121,27 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_vacc_route (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, abbreviation, description
+		id, abbreviation, description
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.abbreviation, OLD.description
+		OLD.id, OLD.abbreviation, OLD.description
 	);
 	return NEW;
 END;</pre>
@@ -40053,243 +44154,10141 @@ END;</pre>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
+DECLARE
+	_is_allowed_updater boolean;
 BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
 	NEW.row_version := OLD.row_version + 1;
 	NEW.modified_when := CURRENT_TIMESTAMP;
 	NEW.modified_by := SESSION_USER;
 	INSERT INTO audit.log_vaccination (
 		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_provider, fk_vaccine, site, batch_no, reaction
+		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_provider, fk_vaccine, site, batch_no, reaction
+	) VALUES (
+		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
+		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_provider, OLD.fk_vaccine, OLD.site, OLD.batch_no, OLD.reaction
+	);
+	return NEW;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-upd-vaccination-course">ft_upd_vaccination_course()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        
+        <pre>
+DECLARE
+	_is_allowed_updater boolean;
+BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
+	NEW.row_version := OLD.row_version + 1;
+	NEW.modified_when := CURRENT_TIMESTAMP;
+	NEW.modified_by := SESSION_USER;
+	INSERT INTO audit.log_vaccination_course (
+		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
+		pk, fk_recommended_by, fk_indication, is_active, comment
+	) VALUES (
+		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
+		OLD.pk, OLD.fk_recommended_by, OLD.fk_indication, OLD.is_active, OLD.comment
+	);
+	return NEW;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-upd-vaccination-course-constraint">ft_upd_vaccination_course_constraint()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        
+        <pre>
+DECLARE
+	_is_allowed_updater boolean;
+BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
+	NEW.row_version := OLD.row_version + 1;
+	NEW.modified_when := CURRENT_TIMESTAMP;
+	NEW.modified_by := SESSION_USER;
+	INSERT INTO audit.log_vaccination_course_constraint (
+		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
+		pk, description
+	) VALUES (
+		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
+		OLD.pk, OLD.description
+	);
+	return NEW;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-upd-vaccination-definition">ft_upd_vaccination_definition()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        
+        <pre>
+DECLARE
+	_is_allowed_updater boolean;
+BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
+	NEW.row_version := OLD.row_version + 1;
+	NEW.modified_when := CURRENT_TIMESTAMP;
+	NEW.modified_by := SESSION_USER;
+	INSERT INTO audit.log_vaccination_definition (
+		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
+		id, fk_course, is_booster, seq_no, min_age_due, max_age_due, min_interval, comment
+	) VALUES (
+		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
+		OLD.id, OLD.fk_course, OLD.is_booster, OLD.seq_no, OLD.min_age_due, OLD.max_age_due, OLD.min_interval, OLD.comment
+	);
+	return NEW;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-upd-vaccination-schedule">ft_upd_vaccination_schedule()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        
+        <pre>
+DECLARE
+	_is_allowed_updater boolean;
+BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
+	NEW.row_version := OLD.row_version + 1;
+	NEW.modified_when := CURRENT_TIMESTAMP;
+	NEW.modified_by := SESSION_USER;
+	INSERT INTO audit.log_vaccination_schedule (
+		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
+		pk, name, comment
+	) VALUES (
+		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
+		OLD.pk, OLD.name, OLD.comment
+	);
+	return NEW;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-upd-vaccine">ft_upd_vaccine()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        
+        <pre>
+DECLARE
+	_is_allowed_updater boolean;
+BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
+	NEW.row_version := OLD.row_version + 1;
+	NEW.modified_when := CURRENT_TIMESTAMP;
+	NEW.modified_by := SESSION_USER;
+	INSERT INTO audit.log_vaccine (
+		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
+		pk, id_route, is_live, min_age, max_age, comment, fk_brand
+	) VALUES (
+		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
+		OLD.pk, OLD.id_route, OLD.is_live, OLD.min_age, OLD.max_age, OLD.comment, OLD.fk_brand
+	);
+	return NEW;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-upd-vaccine-batches">ft_upd_vaccine_batches()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        
+        <pre>
+DECLARE
+	_is_allowed_updater boolean;
+BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
+	NEW.row_version := OLD.row_version + 1;
+	NEW.modified_when := CURRENT_TIMESTAMP;
+	NEW.modified_by := SESSION_USER;
+	INSERT INTO audit.log_vaccine_batches (
+		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
+		pk, fk_vaccine, batch_no
+	) VALUES (
+		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
+		OLD.pk, OLD.fk_vaccine, OLD.batch_no
+	);
+	return NEW;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-upd-waiting-list">ft_upd_waiting_list()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        
+        <pre>
+DECLARE
+	_is_allowed_updater boolean;
+BEGIN
+	-- is the session user allowed to update data ?
+	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
+	IF _is_allowed_updater IS FALSE THEN
+		RAISE EXCEPTION
+			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
+			USING ERRCODE = 'integrity_constraint_violation'
+		;
+		return NEW;
+	END IF;
+	NEW.row_version := OLD.row_version + 1;
+	NEW.modified_when := CURRENT_TIMESTAMP;
+	NEW.modified_by := SESSION_USER;
+	INSERT INTO audit.log_waiting_list (
+		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
+		pk, fk_patient, registered, urgency, list_position, comment, area
+	) VALUES (
+		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
+		OLD.pk, OLD.fk_patient, OLD.registered, OLD.urgency, OLD.list_position, OLD.comment, OLD.area
+	);
+	return NEW;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-upd-xlnk-identity">ft_upd_xlnk_identity()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        
+        <pre>
+BEGIN
+	NEW.row_version := OLD.row_version + 1;
+	NEW.modified_when := CURRENT_TIMESTAMP;
+	NEW.modified_by := SESSION_USER;
+	INSERT INTO audit.log_xlnk_identity (
+		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
+		pk_audit, row_version, modified_when, modified_by, pk, xfk_identity, pupic, data
 	) VALUES (
 		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_provider, OLD.fk_vaccine, OLD.site, OLD.batch_no, OLD.reaction
+		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.xfk_identity, OLD.pupic, OLD.data
 	);
 	return NEW;
 END;</pre>
 	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-upd-vaccination-course">ft_upd_vaccination_course()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-BEGIN
-	NEW.row_version := OLD.row_version + 1;
-	NEW.modified_when := CURRENT_TIMESTAMP;
-	NEW.modified_by := SESSION_USER;
-	INSERT INTO audit.log_vaccination_course (
-		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_recommended_by, fk_indication, is_active, comment
-	) VALUES (
-		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_recommended_by, OLD.fk_indication, OLD.is_active, OLD.comment
-	);
-	return NEW;
-END;</pre>
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.register-table-for-auditing-name-name">register_table_for_auditing(name, name)</a>
+		</h2>
+<h3>Returns: boolean</h3>
+<h3>Language: PLPGSQL</h3>
+        <p>sanity-checking convenience function for registering a table for auditing</p>
+        <pre>
+DECLARE
+	_schema alias for $1;
+	_table alias for $2;
+BEGIN
+	-- does table exist ?
+	perform 1 from pg_class where
+		relname = _table
+			and
+		relnamespace = (select oid from pg_namespace where nspname = _schema)
+	;
+	if not found then
+		raise exception 'audit.register_table_for_auditing(): table [%.%] does not exist', _schema, _table;
+		return false;
+	end if;
+	-- already queued for auditing ?
+	perform 1 from audit.audited_tables where
+		table_name = _table
+			and
+		schema = _schema;
+	if found then
+		return true;
+	end if;
+	-- add definition
+	insert into audit.audited_tables (
+		schema, table_name
+	) values (
+		_schema, _table
+	);
+	return true;
+END;</pre>
+	
+
+<!-- billbill -->
+
+		
+		<hr>
+		<h1>Schema bill</h1>
+		
+			<p>Holds everything related to billing.</p>
+		
+
+		
+		
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#bill.schema">bill</a>.<a name="bill.table.bill">bill</a>
+		</h2>
+        
+         <p>actual bills</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>bill.bill Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				DEFAULT "current_user"()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>invoice_id</td>
+            	<td>text</td>
+                <td><i>
+				
+					
+
+					
+                       UNIQUE
+                    
+				
+
+				
+				
+				</i>
+				<br><br>the ID of the bill
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>close_date</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>cannot add further bill_items after this date if not NULL
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>apply_vat</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>whether or not to apply VAT on the invoice
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.identity">dem.identity.pk</a>
+                  
+                
+                </td>
+            	<td>fk_receiver_identity</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				
+				
+				</i>
+				<br><br>link to the receiver as a GNUmed identity, if known
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.lnk-person-org-address">dem.lnk_person_org_address.id</a>
+                  
+                
+                </td>
+            	<td>fk_receiver_address</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				
+				
+				</i>
+				<br><br>links the address of the receiver of the invoice
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#blobs.table.doc-med">blobs.doc_med.pk</a>
+                  
+                
+                </td>
+            	<td>fk_doc</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				
+				
+				</i>
+				<br><br>links to the document which contains the invoice PDF
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>comment</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>arbitrary comments on bills
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table bill.bill Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>bill.bill Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>bill_bill_sane_apply_vat</td>
+                <td>CHECK (((apply_vat IS NOT NULL) OR ((apply_vat IS NULL) AND (fk_doc IS NULL))))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>bill_bill_sane_comment</td>
+                <td>CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>bill_bill_sane_invoice_id</td>
+                <td>CHECK ((gm.is_null_or_blank_string(invoice_id) IS FALSE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>bill_bill_sane_recv_adr</td>
+                <td>CHECK (((fk_receiver_address IS NOT NULL) OR (close_date IS NULL)))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#bill.table.bill-item">bill.bill_item</a></li>
+			</ul>
+		
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#bill.schema">Schema bill</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#bill.schema">bill</a>.<a name="bill.table.bill-item">bill_item</a>
+		</h2>
+        
+         <p>items patients currently *are* billed for</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>bill.bill_item Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				DEFAULT "current_user"()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.pk</a>
+                  
+                
+                </td>
+            	<td>fk_provider</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>by whom or on whose behalf did the billable activity happen
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  
+                
+                </td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>the encounter during which the billable action for this item took place
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>date_to_bill</td>
+            	<td>date</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>The date the bill item was caused. If NULL, use .fk_encounter -> .started
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>description</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>Can be used to further explain the bill item over and above .fk_billable.description.
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>net_amount_per_unit</td>
+            	<td>numeric</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>How much to charge for one unit of this bill item.
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>currency</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>Which currency to charge in. Must not be NULL if .net_amount_per_unit is not NULL.
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>status</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				DEFAULT 'new'::text
+				</i>
+				<br><br>the status of this item
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#ref.table.billable">ref.billable.pk</a>
+                  
+                
+                </td>
+            	<td>fk_billable</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>Links to the billable item this bill item stands for.
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#bill.table.bill">bill.bill.pk</a>
+                  
+                
+                </td>
+            	<td>fk_bill</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				
+				
+				</i>
+				<br><br>Links to the bill this bill item is on if any.
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>unit_count</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT 1
+				</i>
+				<br><br>The number of times this item is to be billed. 0 can be used for informative items.
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>amount_multiplier</td>
+            	<td>numeric</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT 1
+				</i>
+				<br><br>A multiplier to apply to .net_amount_per_unit. Can be used for discounts, rebates, or increases. Must be > 0.
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table bill.bill_item Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>bill.bill_item Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>bill_bill_item_sane_count</td>
+                <td>CHECK ((unit_count > (-1)))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>bill_bill_item_sane_currency</td>
+                <td>CHECK ((gm.is_null_or_blank_string(currency) IS FALSE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>bill_bill_item_sane_desc</td>
+                <td>CHECK ((gm.is_null_or_non_empty_string(description) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>bill_bill_item_sane_multiplier</td>
+                <td>CHECK ((amount_multiplier > (0)::numeric))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>valid_stati</td>
+                <td>CHECK ((status = ANY (ARRAY['new'::text, 'transferred'::text])))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+       idx_bill_bill_item_fk_bill fk_bill
+    
+       idx_bill_bill_item_fk_billable fk_billable
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#bill.schema">Schema bill</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#bill.schema">bill</a>.<a name="bill.table.lnk-enc-type2billable">lnk_enc_type2billable</a>
+		</h2>
+        
+         <p>actual bills</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>bill.lnk_enc_type2billable Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.encounter-type">clin.encounter_type.pk</a>
+                  
+                
+                </td>
+            	<td>fk_encounter_type</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>Links to encounter type this billable is associated with.
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#ref.table.billable">ref.billable.pk</a>
+                  
+                
+                </td>
+            	<td>fk_billable</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>Links to the billable item the encounter type is associated with.
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+       idx_lnk_enc_type2billable_fk_billable fk_billable
+    
+       idx_lnk_enc_type2billable_fk_encounter_type fk_encounter_type
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#bill.schema">Schema bill</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#bill.schema">bill</a>.<a name="bill.view.v-bill-items">v_bill_items</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>bill.v_bill_items Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_bill_item</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>billable_code</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>billable_description</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>item_detail</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>date_to_bill</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>net_amount_per_unit</td>
+            	<td>numeric</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>unit_count</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>amount_multiplier</td>
+            	<td>numeric</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>total_amount</td>
+            	<td>numeric</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>vat</td>
+            	<td>numeric</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>currency</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>raw_date_to_bill</td>
+            	<td>date</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>billable_amount</td>
+            	<td>numeric</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>vat_multiplier</td>
+            	<td>numeric</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>billable_currency</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>billable_comment</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>billable_active</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>billable_discountable</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>catalog_long</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>catalog_short</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>catalog_version</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>catalog_language</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_encounter_type</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_provider</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_encounter_to_bill</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_bill</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_billable</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_data_source</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>xmin_bill_item</td>
+            	<td>xid</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT b_bi.pk AS pk_bill_item
+,
+    r_b.code AS billable_code
+,
+    r_b.term AS billable_description
+,
+    b_bi.description AS item_detail
+,
+    COALESCE
+(
+     (b_bi.date_to_bill)::timestamp with time zone
+     , c_enc.started
+) AS date_to_bill
+,
+    b_bi.net_amount_per_unit
+,
+    b_bi.unit_count
+,
+    b_bi.amount_multiplier
+,
+    
+(
+     (
+           (b_bi.unit_count)::numeric * b_bi.net_amount_per_unit
+     ) * b_bi.amount_multiplier
+) AS total_amount
+,
+    
+(
+     (
+           (
+                 (b_bi.unit_count)::numeric * b_bi.net_amount_per_unit
+           ) * b_bi.amount_multiplier
+     ) * r_b.vat_multiplier
+) AS vat
+,
+    b_bi.currency
+,
+    b_bi.date_to_bill AS raw_date_to_bill
+,
+    r_b.amount AS billable_amount
+,
+    r_b.vat_multiplier
+,
+    r_b.currency AS billable_currency
+,
+    r_b.comment AS billable_comment
+,
+    r_b.active AS billable_active
+,
+    r_b.discountable AS billable_discountable
+,
+    r_ds.name_long AS catalog_long
+,
+    r_ds.name_short AS catalog_short
+,
+    r_ds.version AS catalog_version
+,
+    r_ds.lang AS catalog_language
+,
+    c_enc.fk_patient AS pk_patient
+,
+    c_enc.fk_type AS pk_encounter_type
+,
+    b_bi.fk_provider AS pk_provider
+,
+    b_bi.fk_encounter AS pk_encounter_to_bill
+,
+    b_bi.fk_bill AS pk_bill
+,
+    r_b.pk AS pk_billable
+,
+    r_b.fk_data_source AS pk_data_source
+,
+    b_bi.xmin AS xmin_bill_item
+   
+FROM (
+     (
+           (bill.bill_item b_bi
+     
+              JOIN ref.billable r_b 
+                ON (
+                       (b_bi.fk_billable = r_b.pk)
+                 )
+           )
+     
+   LEFT JOIN ref.data_source r_ds 
+          ON (
+                 (r_b.fk_data_source = r_ds.pk)
+           )
+     )
+     
+LEFT JOIN clin.encounter c_enc 
+    ON (
+           (b_bi.fk_encounter = c_enc.pk)
+     )
+);</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#bill.schema">Schema bill</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#bill.schema">bill</a>.<a name="bill.view.v-bills">v_bills</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>bill.v_bills Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_bill</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>invoice_id</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_receiver_identity</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>total_amount</td>
+            	<td>numeric</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>total_vat</td>
+            	<td>numeric</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>total_amount_with_vat</td>
+            	<td>numeric</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>percent_vat</td>
+            	<td>numeric</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>currency</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>close_date</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>apply_vat</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>comment</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_receiver_address</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_doc</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_bill_items</td>
+            	<td>integer[]</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>xmin_bill</td>
+            	<td>xid</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT b_b.pk AS pk_bill
+,
+    b_b.invoice_id
+,
+    b_b.fk_receiver_identity AS pk_receiver_identity
+,
+    
+(
+SELECT round
+     (sum
+           (v_bill_items.total_amount)
+           , 2
+     ) AS round
+           
+  FROM bill.v_bill_items
+          
+ WHERE (v_bill_items.pk_bill = b_b.pk)
+) AS total_amount
+,
+    
+(
+SELECT round
+     (sum
+           (v_bill_items.vat)
+           , 2
+     ) AS round
+           
+  FROM bill.v_bill_items
+          
+ WHERE (v_bill_items.pk_bill = b_b.pk)
+) AS total_vat
+,
+    
+(
+SELECT round
+     (sum
+           (
+                 (v_bill_items.total_amount + v_bill_items.vat)
+           )
+           , 2
+     ) AS round
+           
+  FROM bill.v_bill_items
+          
+ WHERE (v_bill_items.pk_bill = b_b.pk)
+) AS total_amount_with_vat
+,
+    
+(
+SELECT (v_bill_items.vat_multiplier * 
+           (100)::numeric
+     )
+           
+  FROM bill.v_bill_items
+          
+ WHERE (v_bill_items.pk_bill = b_b.pk)
+         LIMIT 1
+) AS percent_vat
+,
+    
+(
+SELECT v_bill_items.currency
+           
+  FROM bill.v_bill_items
+          
+ WHERE (v_bill_items.pk_bill = b_b.pk)
+         LIMIT 1
+) AS currency
+,
+    b_b.close_date
+,
+    b_b.apply_vat
+,
+    b_b.comment
+,
+    b_b.fk_receiver_address AS pk_receiver_address
+,
+    b_b.fk_doc AS pk_doc
+,
+    
+(
+SELECT encounter.fk_patient
+           
+  FROM clin.encounter
+          
+ WHERE (encounter.pk = 
+           (
+            SELECT bill_item.fk_encounter
+                   
+              FROM bill.bill_item
+                  
+             WHERE (bill_item.fk_bill = b_b.pk)
+                 LIMIT 1
+           )
+     )
+) AS pk_patient
+,
+    
+(
+SELECT array_agg
+     (sorted_values.pk_bill_item) AS array_agg
+           
+  FROM (
+      SELECT b_vbi.pk_bill_item
+                   
+        FROM bill.v_bill_items b_vbi
+                  
+       WHERE (b_vbi.pk_bill = b_b.pk)
+                  
+    ORDER BY b_vbi.date_to_bill
+           , b_vbi.billable_code
+     ) sorted_values
+) AS pk_bill_items
+,
+    b_b.xmin AS xmin_bill
+   
+FROM bill.bill b_b;</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#bill.schema">Schema bill</a>
+    </p>
+	
+
+	<!-- We've gone through the table structure, now lets take a look at user functions -->
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#bill.schema">bill</a>.<a name="bill.function.get-bill-receiver-identity-integer">get_bill_receiver_identity(integer)</a>
+		</h2>
+<h3>Returns: integer</h3>
+<h3>Language: SQL</h3>
+        
+        <pre>
+select
+	value
+from (
+	select
+		id.pk_id,
+		id.value::integer
+	from
+		dem.v_external_ids4identity id
+			join dem.identity d_i on (id.value = d_i.pk::text)
+	where
+		id.pk_type = (select pk from dem.enum_ext_id_types where name = 'bill receiver' and issuer = 'GNUmed')
+			and
+		id.pk_identity = $1
+	union all
+	select
+		0,
+		$1
+) me
+limit 1;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#bill.schema">bill</a>.<a name="bill.function.trf-prevent-empty-bills">trf_prevent_empty_bills()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        <p>Prevent bills to become void of items due to deletions/updates of bill items.</p>
+        <pre>
+DECLARE
+	_item_count integer;
+	_msg text;
+BEGIN
+	if TG_OP = 'UPDATE' then
+		if OLD.fk_bill IS NULL then
+			return NULL;
+		end if;
+		if OLD.fk_bill IS NOT DISTINCT FROM NEW.fk_bill then
+			return NULL;
+		end if;
+	else
+		if OLD.fk_bill is NULL then
+			return NULL;
+		end if;
+	end if;
+	-- we now either:
+	--	DELETE with .fk_bill NOT NULL
+	-- or:
+	--	UPDATE with an .fk_bill change (including towards fk_bill = NULL)
+	-- let us check whether the (previous) bill still exists
+	-- at all or whether we are deleting the bill (and thereby
+	-- setting our .fk_bill to NULL)
+	-- only works at or below REPEATABLE READ after deletion of bill
+	perform 1 from bill.bill where pk = OLD.fk_bill;
+	if FOUND is FALSE then
+		return NULL;
+	end if;
+	select count(1) into _item_count
+	from bill.bill_item
+	where
+		fk_bill = OLD.fk_bill
+			and
+		pk != OLD.pk;
+	if _item_count > 0 then
+		return NULL;
+	end if;
+	_msg := '[bill.trf_prevent_empty_bills]: cannot remove (by '
+			|| '<' || TG_OP || '>'
+			||') the only item (bill.bill_item.pk='
+			|| coalesce(OLD.pk::text, '<NULL>'::text)
+			|| ') from bill (bill.bill_item.fk_bill=bill.bill.pk='
+			|| coalesce(OLD.fk_bill::text, '<NULL>'::text)
+			|| ') ';
+	raise exception unique_violation using message = _msg;
+	return NULL;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#bill.schema">bill</a>.<a name="bill.function.trf-prevent-mislinked-bills">trf_prevent_mislinked_bills()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        <p>Prevent bills to link to invoices of another patient.</p>
+        <pre>
+DECLARE
+	_doc_patient integer;
+	_bill_patient integer;
+	_msg text;
+BEGIN
+	if NEW.fk_doc IS NULL then
+		return NEW;
+	end if;
+	if TG_OP = 'UPDATE' then
+		if OLD.fk_doc IS NOT DISTINCT FROM NEW.fk_doc then
+			return NEW;
+		end if;
+	end if;
+	-- we now either:
+	--	INSERT with .fk_doc NOT NULL
+	-- or:
+	--	UPDATE with an .fk_bill change to a NON-NULL value
+	select pk_patient into _doc_patient
+	from blobs.v_doc_med
+	where
+		pk_doc = NEW.fk_doc;
+	select pk_patient into _bill_patient
+	from bill.v_bills
+	where
+		pk_bill = NEW.pk;
+	if _doc_patient = _bill_patient then
+		return NEW;
+	end if;
+	_msg := '[bill.trf_prevent_mislinked_bills]: patient mismatch between '
+		|| 'bill (pk=' || NEW.pk || ', patient=' || _bill_patient || ') '
+		|| 'and invoice (pk=' || NEW.fk_doc || ', patient=' || _doc_patient || ')';
+	raise exception integrity_constraint_violation using message = _msg;
+	return NULL;
+END;</pre>
+	
+
+<!-- blobsblobs -->
+
+		
+		<hr>
+		<h1>Schema blobs</h1>
+		
+
+		
+		
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.table.doc-desc">doc_desc</a>
+		</h2>
+        
+         <p>A textual description of the content such
+	 as a result summary. Several of these may
+	 belong to one document object.</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>blobs.doc_desc Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				DEFAULT "current_user"()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#blobs.table.doc-med">blobs.doc_med.pk</a>
+                  
+                
+                  
+                
+                </td>
+            	<td>fk_doc</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+					
+
+					
+                       UNIQUE#1
+                    
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>text</td>
+            	<td>text</td>
+                <td><i>
+				
+					
+
+					
+                       UNIQUE#1
+                    
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table blobs.doc_desc Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>blobs.doc_desc Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+       idx_doc_desc_fk_doc fk_doc
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.table.doc-med">doc_med</a>
+		</h2>
+        
+         <p>a medical document object possibly containing several
+	 data objects such as several pages of a paper document</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>blobs.doc_med Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				DEFAULT "current_user"()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  
+                
+                </td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>the encounter in which this document was entered into the system
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
+                  
+                
+                </td>
+            	<td>fk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>the episode this document pertains to, this may not be the only
+	 one applicable to the document (think discharge letters), see also
+	 lnk_doc_med2episode
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#blobs.table.doc-type">blobs.doc_type.pk</a>
+                  
+                
+                </td>
+            	<td>fk_type</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>semantic type of document (not type of file or mime
+	 type), such as "referral letter", "discharge summary", etc.
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>comment</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>additional short comment such as "abdominal", "ward 3,
+	 Dr. Stein", etc.
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				<br><br>date of document content creation (such as exam date),
+	 NOT date of document creation or date of import; may
+	 be imprecise such as "7/99"
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>ext_ref</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>external reference string of physical document,
+	 original paper copy can be found with this
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.org-unit">dem.org_unit.pk</a>
+                  
+                
+                </td>
+            	<td>fk_org_unit</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				
+				
+				</i>
+				<br><br>Optional link to the org unit this document originates from.\n
+Note that the document may contain data from several units but\n
+there will always be one "sender".
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table blobs.doc_med Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>blobs.doc_med Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#bill.table.bill">bill.bill</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#blobs.table.doc-desc">blobs.doc_desc</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#blobs.table.doc-obj">blobs.doc_obj</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#blobs.table.lnk-doc2hospital-stay">blobs.lnk_doc2hospital_stay</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#blobs.table.lnk-doc-med2episode">blobs.lnk_doc_med2episode</a></li>
+			</ul>
+		
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.table.doc-obj">doc_obj</a>
+		</h2>
+        
+         <p>possibly several of these form a medical document
+	 such as multiple scanned pages/images</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>blobs.doc_obj Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#blobs.table.doc-med">blobs.doc_med.pk</a>
+                  
+                
+                </td>
+            	<td>fk_doc</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>seq_idx</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>index of this object in the sequence
+	 of objects for this document
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>comment</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>optional tiny comment for this
+	 object, such as "page 1"
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.pk</a>
+                  
+                
+                </td>
+            	<td>fk_intended_reviewer</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>who is *supposed* to review this item
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>data</td>
+            	<td>bytea</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>actual binary object data;
+
+	 here is why we use bytea:
+
+== --------------------------------------------------
+
+To: leon at oss.minimetria.com
+
+Cc: pgsql-sql at postgresql.org
+
+Subject: Re: [SQL] Recommendation on bytea or blob for binary data like images 
+
+Date: Fri, 02 Sep 2005 16:33:09 -0400
+
+Message-ID: <17794.1125693189 at sss.pgh.pa.us>
+
+From: Tom Lane <tgl at sss.pgh.pa.us>
+
+List-Archive: <http://archives.postgresql.org/pgsql-sql>
+
+List-Help: <mailto:majordomo at postgresql.org?body=help>
+
+List-ID: <pgsql-sql.postgresql.org>
+
+
+
+leon at oss.minimetria.com writes:
+
+> Hi, I"d like to know what the official recommendation is on which binary
+
+> datatype to use for common small-binary size use.
+
+
+
+If bytea will work for you, it"s definitely the thing to use.  The only
+
+real drawback to bytea is that there"s currently no API to read and
+
+write bytea values in a streaming fashion.  If your objects are small
+
+enough that you can load and store them as units, bytea is fine.
+
+
+
+BLOBs, on the other hand, have a number of drawbacks --- hard to dump,
+
+impossible to secure, etc.
+
+
+
+			regards, tom lane
+
+== --------------------------------------------------
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>filename</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>the filename from when the data was imported - if any, can be NULL,
+	 useful for re-export since legacy devices/applications might expect
+	 particular file names and not use mime types for file detection
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>blobs.doc_obj Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>doc_obj_filename_check</td>
+                <td>CHECK ((btrim(COALESCE(filename, 'NULL'::text)) <> ''::text))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#blobs.table.reviewed-doc-objs">blobs.reviewed_doc_objs</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.export-item">clin.export_item</a></li>
+			</ul>
+		
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.table.doc-type">doc_type</a>
+		</h2>
+        
+         <p>this table enumerates the document types known to the system</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>blobs.doc_type Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>name</td>
+            	<td>text</td>
+                <td><i>
+				
+					
+
+					
+                       UNIQUE
+                    
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>the name/label of the document type
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#blobs.table.doc-med">blobs.doc_med</a></li>
+			</ul>
+		
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.table.lnk-doc2hospital-stay">lnk_doc2hospital_stay</a>
+		</h2>
+        
+         <p>links documents to any hospital stay they might pertain to</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>blobs.lnk_doc2hospital_stay Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT "current_user"()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.hospital-stay">clin.hospital_stay.pk</a>
+                  
+                
+                </td>
+            	<td>fk_stay</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#blobs.table.doc-med">blobs.doc_med.pk</a>
+                  
+                
+                  
+                
+                </td>
+            	<td>fk_document</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+					
+
+					
+                       UNIQUE
+                    
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table blobs.lnk_doc2hospital_stay Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>blobs.lnk_doc2hospital_stay Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.table.lnk-doc-med2episode">lnk_doc_med2episode</a>
+		</h2>
+        
+         <p>this allows linking documents to episodes,
+	 each document can apply to several episodes
+	 but only once each</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>blobs.lnk_doc_med2episode Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT "current_user"()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
+                  
+                
+                  
+                
+                </td>
+            	<td>fk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+					
+
+					
+                       UNIQUE#1
+                    
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#blobs.table.doc-med">blobs.doc_med.pk</a>
+                  
+                
+                  
+                
+                </td>
+            	<td>fk_doc_med</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+					
+
+					
+                       UNIQUE#1
+                    
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table blobs.lnk_doc_med2episode Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>blobs.lnk_doc_med2episode Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.table.reviewed-doc-objs">reviewed_doc_objs</a>
+		</h2>
+        
+         <p>review table for documents (per object such as a page)</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>blobs.reviewed_doc_objs Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT "current_user"()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>integer</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				DEFAULT nextval('clin.review_root_pk_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#blobs.table.doc-obj">blobs.doc_obj.pk</a>
+                  
+                
+                  
+                
+                </td>
+            	<td>fk_reviewed_row</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+					
+
+					
+                       UNIQUE#1
+                    
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>fk_reviewer</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+                       UNIQUE#1
+                    
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>is_technically_abnormal</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>clinically_relevant</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>comment</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table blobs.reviewed_doc_objs Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#clin.table.review-root">review_root</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>blobs.reviewed_doc_objs Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-doc-desc">v_doc_desc</a>
+		</h2>
+        
+         <p>aggregates some document data descriptions</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>blobs.v_doc_desc Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_doc</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>description</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_doc_desc</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT vdm.pk_patient
+,
+    dd.fk_doc AS pk_doc
+,
+    dd.text AS description
+,
+    vdm.pk_encounter
+,
+    vdm.pk_episode
+,
+    vdm.pk_health_issue
+,
+    dd.pk AS pk_doc_desc
+   
+FROM blobs.doc_desc dd
+,
+    blobs.v_doc_med vdm
+  
+WHERE (dd.fk_doc = vdm.pk_doc);</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-doc-med">v_doc_med</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>blobs.v_doc_med Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_doc</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>l10n_type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>ext_ref</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>comment</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>episode</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>health_issue</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>unit</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>organization</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_type</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_org_unit</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_org</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>xmin_doc_med</td>
+            	<td>xid</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT c_enc.fk_patient AS pk_patient
+,
+    b_dm.pk AS pk_doc
+,
+    b_dm.clin_when
+,
+    b_dt.name AS type
+,
+    _
+(b_dt.name) AS l10n_type
+,
+    b_dm.ext_ref
+,
+    b_dm.comment
+,
+    c_epi.description AS episode
+,
+    c_hi.description AS health_issue
+,
+    c_epi.is_open AS episode_open
+,
+    d_ou.description AS unit
+,
+    d_o.description AS organization
+,
+    b_dm.fk_type AS pk_type
+,
+    b_dm.fk_encounter AS pk_encounter
+,
+    b_dm.fk_episode AS pk_episode
+,
+    c_epi.fk_health_issue AS pk_health_issue
+,
+    b_dm.fk_org_unit AS pk_org_unit
+,
+    d_ou.fk_org AS pk_org
+,
+    b_dm.modified_when
+,
+    b_dm.modified_by
+,
+    b_dm.xmin AS xmin_doc_med
+   
+FROM (
+     (
+           (
+                 (
+                       (
+                             (blobs.doc_med b_dm
+     
+                                JOIN blobs.doc_type b_dt 
+                                  ON (
+                                         (b_dm.fk_type = b_dt.pk)
+                                   )
+                             )
+     
+                          JOIN clin.encounter c_enc 
+                            ON (
+                                   (b_dm.fk_encounter = c_enc.pk)
+                             )
+                       )
+     
+                    JOIN clin.episode c_epi 
+                      ON (
+                             (b_dm.fk_episode = c_epi.pk)
+                       )
+                 )
+     
+         LEFT JOIN clin.health_issue c_hi 
+                ON (
+                       (c_hi.pk = c_epi.fk_health_issue)
+                 )
+           )
+     
+   LEFT JOIN dem.org_unit d_ou 
+          ON (
+                 (b_dm.fk_org_unit = d_ou.pk)
+           )
+     )
+     
+LEFT JOIN dem.org d_o 
+    ON (
+           (d_ou.fk_org = d_o.pk)
+     )
+);</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-doc-med-journal">v_doc_med_journal</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>blobs.v_doc_med_journal Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>soap_cat</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>narrative</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>src_pk</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>src_table</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>health_issue</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>issue_laterality</td>
+            	<td>character varying(2)</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>episode</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>encounter_type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>encounter_l10n_type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT c_enc.fk_patient AS pk_patient
+,
+    b_dm.modified_when
+,
+    b_dm.clin_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = b_dm.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (b_dm.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    NULL::text AS soap_cat
+,
+    
+('"'::text || 
+     (
+           (
+                 (
+                       (
+                             (
+                                   (
+                                         (
+                                               (
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (
+                                                                             (
+                                                                                   (_
+                                                                                         (b_dt.name) || '" '::text
+                                                                                   ) || _
+                                                                                   ('with'::text)
+                                                                             ) || ' '::text
+                                                                       ) || 
+                                                                       (
+                                                                        SELECT count
+                                                                             (1) AS count
+           
+                                                                          FROM blobs.doc_obj b_do
+          
+                                                                         WHERE (b_do.fk_doc = b_dm.pk)
+                                                                       )
+                                                                 ) || ' '::text
+                                                           ) || _
+                                                           ('part(s)'::text
+                                                     )
+                                               ) || '
+'::text
+                                         ) || ' '::text
+                                   ) || to_char
+                                   (b_dm.clin_when
+                                         ,'YYYY-MM-DD HH24:MI'::text
+                                   )
+                             ) || '
+'::text
+                       ) || COALESCE
+                       (
+                             (
+                                   (' ['::text || b_dm.ext_ref) || ']'::text
+                             )
+                             ,''::text
+                       )
+                 ) || COALESCE
+                 (
+                       (
+                             (
+                                   (
+                                         (
+                                               (' @ '::text || d_ou.description) || ' '::text
+                                         ) || _
+                                         ('of'::text)
+                                   ) || ' '::text
+                             ) || d_o.description
+                       )
+                       ,''::text
+                 )
+           ) || '
+'::text
+     ) || COALESCE
+     (
+           (' '::text || b_dm.comment)
+           ,''::text
+     )
+)
+)      AS narrative
+,     
+    b_dm.fk_encounter AS pk_encounter
+,     
+    b_dm.fk_episode AS pk_episode
+,     
+    c_epi.fk_health_issue AS pk_health_issue
+,     
+    b_dm.pk AS src_pk
+,     
+    'blobs.doc_med'::text AS src_table
+,     
+    b_dm.row_version
+,     
+    c_hi.description AS health_issue
+,     
+    c_hi.laterality AS issue_laterality
+,     
+    c_hi.is_active AS issue_active
+,     
+    c_hi.clinically_relevant AS issue_clinically_relevant
+,     
+    c_hi.is_confidential AS issue_confidential
+,     
+    c_epi.description AS episode
+,     
+    c_epi.is_open AS episode_open
+,     
+    c_enc.started AS encounter_started
+,     
+    c_enc.last_affirmed AS encounter_last_affirmed
+,     
+    c_ety.description AS encounter_type
+,     
+    _
+(     c_ety.description) AS encounter_l10n_type
+   
+FROM   (
+(
+     (
+           (
+                 (
+                       (
+                             (blobs.doc_med b_dm
+     
+                                JOIN clin.encounter c_enc 
+                                  ON (
+                                         (b_dm.fk_encounter = c_enc.pk)
+                                   )
+                             )
+     
+                          JOIN clin.encounter_type c_ety 
+                            ON (
+                                   (c_enc.fk_type = c_ety.pk)
+                             )
+                       )
+     
+                    JOIN blobs.doc_type b_dt 
+                      ON (
+                             (b_dm.fk_type = b_dt.pk)
+                       )
+                 )
+     
+              JOIN clin.episode c_epi 
+                ON (
+                       (b_dm.fk_episode = c_epi.pk)
+                 )
+           )
+     
+   LEFT JOIN clin.health_issue c_hi 
+          ON (
+                 (c_epi.fk_health_issue = c_hi.pk)
+           )
+     )
+     
+LEFT JOIN dem.org_unit d_ou 
+    ON (
+           (b_dm.fk_org_unit = d_ou.pk)
+     )
+)
+     
+LEFT JOIN dem.org d_o 
+ON (
+     (d_ou.fk_org = d_o.pk)
+)
+)     ;</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-doc-type">v_doc_type</a>
+		</h2>
+        
+         <p>list active document types, those that are activated for use</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>blobs.v_doc_type Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_doc_type</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>l10n_type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>is_user_defined</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>is_in_use</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>xmin_doc_type</td>
+            	<td>xid</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT dt.pk AS pk_doc_type
+,
+    dt.name AS type
+,
+    _
+(dt.name) AS l10n_type
+,
+    
+(NOT 
+     (EXISTS 
+           (
+            SELECT 1
+           
+              FROM ref.document_type
+          
+             WHERE (document_type.description = dt.name)
+           )
+     )
+) AS is_user_defined
+,
+    
+(EXISTS 
+     (
+      SELECT 1
+           
+        FROM blobs.doc_med
+          
+       WHERE (doc_med.fk_type = dt.pk)
+     )
+) AS is_in_use
+,
+    dt.xmin AS xmin_doc_type
+   
+FROM blobs.doc_type dt;</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-latest-mugshot">v_latest_mugshot</a>
+		</h2>
+        
+         <p>shows the latest picture of the patient, currently the highest
+	 seq_idx of the newest document of type "patient photograph"</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>blobs.v_latest_mugshot Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>doc_comment</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>date_taken</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>ext_ref</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>obj_seq_idx</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>obj_comment</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_doc</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_obj</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>image</td>
+            	<td>bytea</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT vo4d.pk_patient
+,
+    vo4d.doc_comment
+,
+    vo4d.date_generated AS date_taken
+,
+    vo4d.ext_ref
+,
+    vo4d.seq_idx AS obj_seq_idx
+,
+    vo4d.obj_comment
+,
+    vo4d.pk_doc
+,
+    vo4d.pk_obj
+,
+    bdo.data AS image
+   
+FROM blobs.v_obj4doc_no_data vo4d
+,
+    blobs.doc_obj bdo
+  
+WHERE (
+     (
+           (vo4d.type = 'patient photograph'::text)
+         AND (vo4d.seq_idx = 
+                 (
+                  SELECT max
+                       (vo4d1.seq_idx) AS max
+           
+                    FROM blobs.v_obj4doc_no_data vo4d1
+          
+                   WHERE (
+                             (vo4d1.pk_patient = vo4d.pk_patient)
+                           AND (vo4d1.type = 'patient photograph'::text)
+                       )
+          
+                GROUP BY vo4d1.date_generated
+          
+                ORDER BY vo4d1.date_generated DESC
+         LIMIT 1
+                 )
+           )
+     )
+   AND (bdo.pk = vo4d.pk_obj)
+);</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-obj4doc-no-data">v_obj4doc_no_data</a>
+		</h2>
+        
+         <p>denormalized metadata for blobs.doc_obj but without the data itself</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>blobs.v_obj4doc_no_data Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_obj</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>seq_idx</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>size</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>date_generated</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>l10n_type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>ext_ref</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>episode</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>doc_comment</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>obj_comment</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>filename</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_intended_reviewer</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>reviewed</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>reviewed_by_you</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>reviewed_by_intended_reviewer</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_doc</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_type</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>xmin_doc_obj</td>
+            	<td>xid</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT b_vdm.pk_patient
+,
+    b_do.pk AS pk_obj
+,
+    b_do.seq_idx
+,
+    octet_length
+(COALESCE
+     (b_do.data
+           ,'\x'::bytea
+     )
+) AS size
+,
+    b_vdm.clin_when AS date_generated
+,
+    b_vdm.type
+,
+    b_vdm.l10n_type
+,
+    b_vdm.ext_ref
+,
+    b_vdm.episode
+,
+    b_vdm.comment AS doc_comment
+,
+    b_do.comment AS obj_comment
+,
+    b_do.filename
+,
+    b_do.fk_intended_reviewer AS pk_intended_reviewer
+,
+    
+(EXISTS 
+     (
+      SELECT 1
+           
+        FROM blobs.reviewed_doc_objs
+          
+       WHERE (reviewed_doc_objs.fk_reviewed_row = b_do.pk)
+     )
+) AS reviewed
+,
+    
+(EXISTS 
+     (
+      SELECT 1
+           
+        FROM blobs.reviewed_doc_objs
+          
+       WHERE (
+                 (reviewed_doc_objs.fk_reviewed_row = b_do.pk)
+               AND (reviewed_doc_objs.fk_reviewer = 
+                       (
+                        SELECT staff.pk
+                   
+                          FROM dem.staff
+                  
+                         WHERE (staff.db_user = "current_user"
+                                   ()
+                             )
+                       )
+                 )
+           )
+     )
+) AS reviewed_by_you
+,
+    
+(EXISTS 
+     (
+      SELECT 1
+           
+        FROM blobs.reviewed_doc_objs
+          
+       WHERE (
+                 (reviewed_doc_objs.fk_reviewed_row = b_do.pk)
+               AND (reviewed_doc_objs.fk_reviewer = b_do.fk_intended_reviewer)
+           )
+     )
+) AS reviewed_by_intended_reviewer
+,
+    b_vdm.pk_doc
+,
+    b_vdm.pk_type
+,
+    b_vdm.pk_encounter
+,
+    b_vdm.pk_episode
+,
+    b_vdm.pk_health_issue
+,
+    b_do.xmin AS xmin_doc_obj
+   
+FROM (blobs.v_doc_med b_vdm
+     
+  JOIN blobs.doc_obj b_do 
+    ON (
+           (b_do.fk_doc = b_vdm.pk_doc)
+     )
+)
+  
+WHERE (b_vdm.pk_doc = b_do.fk_doc);</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-reviewed-doc-objects">v_reviewed_doc_objects</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>blobs.v_reviewed_doc_objects Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_doc_obj</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>reviewer</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>is_technically_abnormal</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>clinically_relevant</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>is_review_by_responsible_reviewer</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>is_your_review</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>comment</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>reviewed_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_review_root</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_reviewer</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT rdo.fk_reviewed_row AS pk_doc_obj
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.pk = rdo.fk_reviewer)
+     )
+     , (
+           ('<#'::text || rdo.fk_reviewer) || '>'::text
+     )
+) AS reviewer
+,
+    rdo.is_technically_abnormal
+,
+    rdo.clinically_relevant
+,
+    
+(EXISTS 
+     (
+      SELECT 1
+           
+        FROM blobs.doc_obj
+          
+       WHERE (
+                 (doc_obj.pk = rdo.fk_reviewed_row)
+               AND (doc_obj.fk_intended_reviewer = rdo.fk_reviewer)
+           )
+     )
+) AS is_review_by_responsible_reviewer
+,
+    
+(EXISTS 
+     (
+      SELECT 1
+           
+        FROM dem.staff
+          
+       WHERE (
+                 (staff.pk = rdo.fk_reviewer)
+               AND (staff.db_user = "current_user"
+                       ()
+                 )
+           )
+     )
+) AS is_your_review
+,
+    rdo.comment
+,
+    rdo.modified_when AS reviewed_when
+,
+    rdo.modified_by
+,
+    rdo.pk AS pk_review_root
+,
+    rdo.fk_reviewer AS pk_reviewer
+,
+    
+(
+SELECT v_obj4doc_no_data.pk_patient
+           
+  FROM blobs.v_obj4doc_no_data
+          
+ WHERE (v_obj4doc_no_data.pk_obj = rdo.fk_reviewed_row)
+) AS pk_patient
+,
+    
+(
+SELECT v_obj4doc_no_data.pk_encounter
+           
+  FROM blobs.v_obj4doc_no_data
+          
+ WHERE (v_obj4doc_no_data.pk_obj = rdo.fk_reviewed_row)
+) AS pk_encounter
+,
+    
+(
+SELECT v_obj4doc_no_data.pk_episode
+           
+  FROM blobs.v_obj4doc_no_data
+          
+ WHERE (v_obj4doc_no_data.pk_obj = rdo.fk_reviewed_row)
+) AS pk_episode
+,
+    
+(
+SELECT v_obj4doc_no_data.pk_health_issue
+           
+  FROM blobs.v_obj4doc_no_data
+          
+ WHERE (v_obj4doc_no_data.pk_obj = rdo.fk_reviewed_row)
+) AS pk_health_issue
+   
+FROM blobs.reviewed_doc_objs rdo;</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-unreviewed-docs">v_unreviewed_docs</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>blobs.v_unreviewed_docs Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_doc</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_intended_reviewer</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT DISTINCT 
+ON (b_do.fk_doc) b_do.fk_doc AS pk_doc
+,
+    min
+(b_do.fk_intended_reviewer) AS pk_intended_reviewer
+,
+    min
+(c_e.fk_patient) AS pk_patient
+   
+FROM (
+     (blobs.doc_obj b_do
+     
+        JOIN blobs.doc_med b_dm 
+          ON (
+                 (b_dm.pk = b_do.fk_doc)
+           )
+     )
+     
+  JOIN clin.encounter c_e 
+    ON (
+           (b_dm.fk_encounter = c_e.pk)
+     )
+)
+  
+WHERE (NOT 
+     (EXISTS 
+           (
+            SELECT 1
+           
+              FROM blobs.reviewed_doc_objs b_rdo
+          
+             WHERE (b_rdo.fk_reviewed_row = b_do.pk)
+           )
+     )
+)
+  
+GROUP BY b_do.fk_doc;</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-unreviewed-docs-inbox">v_unreviewed_docs_inbox</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>blobs.v_unreviewed_docs_inbox Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>received_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>provider</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>importance</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>category</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>l10n_category</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>l10n_type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>comment</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_context</td>
+            	<td>integer[]</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>data</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_inbox_message</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_staff</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_category</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_type</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>is_virtual</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>due_date</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>expiry_date</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>is_overdue</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>is_expired</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>interval_due</td>
+            	<td>interval</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>xmin_message_inbox</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT now
+() AS received_when
+,
+    '<system>'::text AS modified_by
+,
+    NULL::text AS provider
+,
+    0 AS importance
+,
+    'clinical'::text AS category
+,
+    _
+('clinical'::text) AS l10n_category
+,
+    'review docs'::text AS type
+,
+    _
+('review docs'::text) AS l10n_type
+,
+    
+(
+SELECT (
+           (
+                 (
+                       (
+                             (
+                                   (b_vuds.no_of_docs || ' '::text) || _
+                                   ('unreviewed documents for patient'::text)
+                             ) || ' '::text
+                       ) || d_n.lastnames
+                 ) || 
+              ', '::text
+           ) || d_n.firstnames
+     )
+) AS comment
+,
+    NULL::integer[] AS pk_context
+,
+    NULL::text AS data
+,
+    NULL::integer AS pk_inbox_message
+,
+    
+(
+SELECT staff.pk
+           
+  FROM dem.staff
+          
+ WHERE (staff.db_user = "current_user"
+           ()
+     )
+) AS pk_staff
+,
+    
+(
+SELECT v_inbox_item_type.pk_category
+           
+  FROM dem.v_inbox_item_type
+          
+ WHERE (v_inbox_item_type.type = 'review docs'::text)
+) AS pk_category
+,
+    
+(
+SELECT v_inbox_item_type.pk_type
+           
+  FROM dem.v_inbox_item_type
+          
+ WHERE (v_inbox_item_type.type = 'review docs'::text)
+) AS pk_type
+,
+    b_vuds.pk_patient
+,
+    true AS is_virtual
+,
+    
+(now
+     () - '01:00:00'::interval
+) AS due_date
+,
+    NULL::timestamp with time zone AS expiry_date
+,
+    true AS is_overdue
+,
+    false AS is_expired
+,
+    '01:00:00'::interval AS interval_due
+,
+    NULL::integer AS xmin_message_inbox
+   
+FROM (blobs.v_unreviewed_docs_summary b_vuds
+     
+  JOIN dem.names d_n 
+    ON (
+           (b_vuds.pk_patient = d_n.id_identity)
+     )
+)
+  
+WHERE (d_n.active IS TRUE);</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-unreviewed-docs-summary">v_unreviewed_docs_summary</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>blobs.v_unreviewed_docs_summary Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>no_of_docs</td>
+            	<td>bigint</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT b_vud.pk_patient
+,
+    count
+(1) AS no_of_docs
+   
+FROM blobs.v_unreviewed_docs b_vud
+  
+GROUP BY b_vud.pk_patient;</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+    </p>
+	
+
+	<!-- We've gone through the table structure, now lets take a look at user functions -->
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.function.delete-document-integer-integer">delete_document(integer, integer)</a>
+		</h2>
+<h3>Returns: boolean</h3>
+<h3>Language: PLPGSQL</h3>
+        
+        <pre>
+DECLARE
+	_pk_doc alias for $1;
+	_pk_encounter alias for $2;
+	_del_note text;
+	_doc_row record;
+	_obj_row record;
+	tmp text;
+BEGIN
+	select * into _doc_row from blobs.doc_med where pk = _pk_doc;
+	_del_note := _('Deletion of document') || E':
+'
+		|| ' '
+			|| to_char(_doc_row.clin_when, 'YYYY-MM-DD HH24:MI')
+			|| ' "' || (select _(dt.name) from blobs.doc_type dt where pk = _doc_row.fk_type) || '"'
+			|| coalesce(' (' || _doc_row.ext_ref || ')', '')
+		|| coalesce(E'
+ ' || _doc_row.comment, '')
+	;
+	FOR _obj_row IN select * from blobs.doc_obj where fk_doc = _pk_doc order by seq_idx LOOP
+		_del_note := _del_note || E'
+'
+			|| ' #' || coalesce(_obj_row.seq_idx, '-1') || ': "' || coalesce(_obj_row.comment, '') || E'"
+'
+			|| ' ' || coalesce(_obj_row.filename, '') || E'
+';
+	end LOOP;
+	insert into clin.clin_narrative
+		(fk_encounter, fk_episode, narrative, soap_cat)
+	values (
+		_pk_encounter,
+		_doc_row.fk_episode,
+		_del_note,
+		NULL
+	);
+	-- should auto-cascade:
+	--delete from blobs.doc_obj where fk_doc = _pk_doc;
+	-- should auto-NULL:
+	--bill.bill.fk_doc
+	delete from blobs.doc_med where pk = _pk_doc;
+	return True;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.function.delete-document-part-integer-integer">delete_document_part(integer, integer)</a>
+		</h2>
+<h3>Returns: boolean</h3>
+<h3>Language: PLPGSQL</h3>
+        
+        <pre>
+DECLARE
+	_pk_doc_part alias for $1;
+	_pk_encounter alias for $2;
+	_del_note text;
+	_doc_row record;
+	_obj_row record;
+	tmp text;
+BEGIN
+	select * into _obj_row from blobs.doc_obj where pk = _pk_doc_part;
+	select * into _doc_row from blobs.doc_med where pk = _obj_row.fk_doc;
+	_del_note := _('Deletion of part from document') || E':
+'
+		|| ' '
+			|| to_char(_doc_row.clin_when, 'YYYY-MM-DD HH24:MI')
+			|| ' "' || (select _(dt.name) from blobs.doc_type dt where pk = _doc_row.fk_type) || '"'
+			|| coalesce(' (' || _doc_row.ext_ref || ')', '')
+		|| coalesce(E'
+ ' || _doc_row.comment, '')
+		|| E'
+'
+		|| ' #' || coalesce(_obj_row.seq_idx, '-1') || ': "' || coalesce(_obj_row.comment, '') || E'"
+'
+		|| ' ' || coalesce(_obj_row.filename, '') || E'
+'
+	;
+	insert into clin.clin_narrative
+		(fk_encounter, fk_episode, narrative, soap_cat)
+	values (
+		_pk_encounter,
+		_doc_row.fk_episode,
+		_del_note,
+		NULL
+	);
+	delete from blobs.doc_obj where pk = _pk_doc_part;
+	return True;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.function.trf-do-not-duplicate-primary-episode-in-link-table">trf_do_not_duplicate_primary_episode_in_link_table()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        <p>This trigger function is called before a lnk_doc_med2episode
+	 row is inserted or updated. It makes sure the episode does
+	 not duplicate the primary episode for this document listed
+	 in doc_med. If it does the insert/update is skipped.</p>
+        <pre>
+BEGIN
+	-- if already in doc_med
+	perform 1 from blobs.doc_med dm where dm.fk_episode = NEW.fk_episode and dm.pk = NEW.fk_doc_med;
+	if FOUND then
+		-- skip the insert/update
+		return null;
+	end if;
+	return NEW;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.function.trf-mark-unreviewed-on-doc-obj-update">trf_mark_unreviewed_on_doc_obj_update()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        
+        <pre>
+BEGIN
+	if (NEW.data != OLD.data) or ((NEW.data != OLD.data) is NULL) then
+		delete from blobs.reviewed_doc_objs where fk_reviewed_row = OLD.pk;
+	end if;
+	return NEW;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.function.trf-remove-primary-episode-from-link-table">trf_remove_primary_episode_from_link_table()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        <p>This trigger function is called when a doc_med row
+	 is inserted or updated. It makes sure the primary
+	 episode listed in doc_med is not duplicated in
+	 lnk_doc_med2episode for the same document. If it
+	 exists in the latter it is removed from there.</p>
+        <pre>
+BEGIN
+	-- if update
+	if TG_OP = 'UPDATE' then
+		-- and no change
+		if NEW.fk_episode = OLD.fk_episode then
+			-- then do nothing
+			return NEW;
+		end if;
+	end if;
+	-- if already in link table
+	perform 1 from blobs.lnk_doc_med2episode ldm2e where ldm2e.fk_episode = NEW.fk_episode and ldm2e.fk_doc_med = NEW.pk;
+	if FOUND then
+		-- delete from link table
+		delete from blobs.lnk_doc_med2episode where fk_episode = NEW.fk_episode and fk_doc_med = NEW.pk;
+	end if;
+	return NEW;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.function.trf-set-intended-reviewer">trf_set_intended_reviewer()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        <p>Set the default on blobs.doc_obj.fk_intended_reviewer.</p>
+        <pre>
+DECLARE
+	_pk_patient integer;
+	_pk_provider integer;
+BEGIN
+	-- explicitely set ?
+	if NEW.fk_intended_reviewer is not NULL then
+		return NEW;
+	end if;
+	-- find patient via document
+	select
+		fk_patient into _pk_patient
+	from
+		clin.encounter
+	where
+		clin.encounter.pk = (
+			select fk_encounter from blobs.doc_med where pk = NEW.fk_doc
+		);
+	-- does patient have primary provider ?
+	select
+		fk_primary_provider into _pk_provider
+	from
+		dem.identity
+	where
+		dem.identity.pk = _pk_patient;
+	if _pk_provider is not NULL then
+		NEW.fk_intended_reviewer := _pk_provider;
+		return NEW;
+	end if;
+	-- else use CURRENT_USER
+	select
+		pk into _pk_provider
+	from
+		dem.staff
+	where
+		dem.staff.db_user = current_user;
+	NEW.fk_intended_reviewer := _pk_provider;
+	return NEW;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.function.trf-verify-page-number">trf_verify_page_number()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        
+        <pre>
+declare
+	msg text;
+begin
+	if NEW.seq_idx is NULL then
+		return NEW;
+	end if;
+	perform 1 from blobs.doc_obj where pk <> NEW.pk and fk_doc = NEW.fk_doc and seq_idx = NEW.seq_idx;
+	if FOUND then
+		msg := '[blobs.trf_verify_page_number]: uniqueness violation: seq_idx [' || NEW.seq_idx || '] already exists for fk_doc [' || NEW.fk_doc || ']';
+		raise exception '%', msg;
+	end if;
+	return NEW;
+end;</pre>
+	
+
+<!-- cfgcfg -->
+
+		
+		<hr>
+		<h1>Schema cfg</h1>
+		
+			<p>This schema holds all the configuration data.</p>
+		
+
+		
+		
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.cfg-data">cfg_data</a>
+		</h2>
+        
+         <p>stores opaque configuration data, either text or binary,
+	 note that it will be difficult to share such options
+	 among different types of clients</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>cfg.cfg_data Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#cfg.table.cfg-item">cfg.cfg_item.pk</a>
+                  
+                
+                </td>
+            	<td>fk_item</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>value</td>
+            	<td>bytea</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.cfg-item">cfg_item</a>
+		</h2>
+        
+         <p>this table holds all "instances" of cfg.cfg_template</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>cfg.cfg_item Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#cfg.table.cfg-template">cfg.cfg_template.pk</a>
+                  
+                
+                  
+                
+                </td>
+            	<td>fk_template</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+					
+
+					
+                       UNIQUE#1
+                    
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>this points to the class of this option, think of this as a base object, this also defines the data type
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>owner</td>
+            	<td>name</td>
+                <td><i>
+				
+					
+
+					
+                       UNIQUE#1
+                    
+				
+
+				NOT NULL
+				DEFAULT "current_user"()
+				</i>
+				<br><br>the database level user this option belongs to; this
+	 is the "role" of the user from the perspective of
+	 the database; can be "default" at the application
+	 level to indicate that it does not care
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>workplace</td>
+            	<td>text</td>
+                <td><i>
+				
+					
+
+					
+                       UNIQUE#1
+                    
+				
+
+				
+				
+				</i>
+				<br><br>- the logical workplace this option pertains to
+	 - can be a hostname but should be a logical rather
+	   than a physical identifier as machines get moved,
+	   workplaces do not, kind of like a "role" for the
+	   machine
+	 - associate this with a physical workplace through
+	   a local config file or environment variable
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>cookie</td>
+            	<td>text</td>
+                <td><i>
+				
+					
+
+					
+                       UNIQUE#1
+                    
+				
+
+				
+				
+				</i>
+				<br><br>an arbitrary, opaque entity the client code can use
+	 to associate this config item with even finer grained
+	 context; could be the pertinent patient ID for patient
+	 specific options
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#cfg.table.cfg-data">cfg.cfg_data</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#cfg.table.cfg-numeric">cfg.cfg_numeric</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#cfg.table.cfg-str-array">cfg.cfg_str_array</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#cfg.table.cfg-string">cfg.cfg_string</a></li>
+			</ul>
+		
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.cfg-numeric">cfg_numeric</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>cfg.cfg_numeric Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#cfg.table.cfg-item">cfg.cfg_item.pk</a>
+                  
+                
+                </td>
+            	<td>fk_item</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>value</td>
+            	<td>numeric</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.cfg-str-array">cfg_str_array</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>cfg.cfg_str_array Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#cfg.table.cfg-item">cfg.cfg_item.pk</a>
+                  
+                
+                </td>
+            	<td>fk_item</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>value</td>
+            	<td>text[]</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.cfg-string">cfg_string</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>cfg.cfg_string Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#cfg.table.cfg-item">cfg.cfg_item.pk</a>
+                  
+                
+                </td>
+            	<td>fk_item</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>value</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.cfg-template">cfg_template</a>
+		</h2>
+        
+         <p>meta definition of config items</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>cfg.cfg_template Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>name</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT 'must set this !'::text
+				</i>
+				<br><br>the name of the option; this MUST be set to something meaningful
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#cfg.table.cfg-type-enum">cfg.cfg_type_enum.name</a>
+                  
+                
+                </td>
+            	<td>type</td>
+            	<td>text</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>type of the value
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>cfg_group</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT 'xxxDEFAULTxxx'::text
+				</i>
+				<br><br>just for logical grouping of options according to task sets to facilitate better config management
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>description</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT 'programmer is an avid Camel Book Reader'::text
+				</i>
+				<br><br>arbitrary description (user visible)
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#cfg.table.cfg-item">cfg.cfg_item</a></li>
+			</ul>
+		
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.cfg-type-enum">cfg_type_enum</a>
+		</h2>
+        
+         <p>enumeration of config option data types</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>cfg.cfg_type_enum Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>name</td>
+            	<td>text</td>
+                <td><i>
+				
+					
+
+					
+                       UNIQUE
+                    
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#cfg.table.cfg-template">cfg.cfg_template</a></li>
+			</ul>
+		
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.config">config</a>
+		</h2>
+        
+         <p>maps a service name to a database location
+	 for a particular user, includes user
+	 credentials for that database</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>cfg.config Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>id</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>profile</td>
+            	<td>character(25)</td>
+                <td><i>
+				
+
+				
+				DEFAULT 'default'::bpchar
+				</i>
+				<br><br>allows multiple profiles per user/
+	 pseudo user, one user may have different
+	 configuration profiles depending on role,
+	 need and location
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>username</td>
+            	<td>character(25)</td>
+                <td><i>
+				
+
+				
+				DEFAULT "current_user"()
+				</i>
+				<br><br>user name as used within the GNUmed system
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>ddb</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>which GNUmed service are we mapping to a database here
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>db</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>how to reach the database host for this service
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>crypt_pwd</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>password for user and database, encrypted
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>crypt_algo</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>encryption algorithm used for password encryption
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pwd_hash</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>hash of the unencrypted password
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>hash_algo</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>algorithm used for password hashing
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.db-logon-banner">db_logon_banner</a>
+		</h2>
+        
+         <p>Stores a banner to show when clients log on.</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>cfg.db_logon_banner Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>message</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>The actual message to show.
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>singularizer</td>
+            	<td>boolean</td>
+                <td><i>
+				
+					
+
+					
+                       UNIQUE
+                    
+				
+
+				
+				DEFAULT true
+				</i>
+				<br><br>Makes sure there only ever is one such banner at any given time.
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>cfg.db_logon_banner Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>db_logon_banner_message_check</td>
+                <td>CHECK ((btrim(message) <> ''::text))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>db_logon_banner_singularizer_check</td>
+                <td>CHECK ((singularizer IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.report-query">report_query</a>
+		</h2>
+        
+         <p>This table stores SQL commands to be used in frontend report style queries.</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>cfg.report_query Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				DEFAULT "current_user"()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>label</td>
+            	<td>text</td>
+                <td><i>
+				
+					
+
+					
+                       UNIQUE
+                    
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>cmd</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table cfg.report_query Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>cfg.report_query Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>report_query_cmd_check</td>
+                <td>CHECK ((btrim(COALESCE(cmd, 'NULL'::text)) <> ''::text))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>report_query_label_check</td>
+                <td>CHECK ((btrim(COALESCE(label, 'NULL'::text)) <> ''::text))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.view.v-cfg-options">v_cfg_options</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>cfg.v_cfg_options Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>option</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>description</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>owner</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>workplace</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>cookie</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>group</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_cfg_template</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_cfg_item</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT cfg_t.name AS option
+,
+    cfg_t.description
+,
+    cfg_i.owner
+,
+    cfg_i.workplace
+,
+    cfg_i.cookie
+,
+    cfg_t.type
+,
+    cfg_t.cfg_group AS "group"
+,
+    cfg_t.pk AS pk_cfg_template
+,
+    cfg_i.pk AS pk_cfg_item
+   
+FROM cfg.cfg_template cfg_t
+,
+    cfg.cfg_item cfg_i
+  
+WHERE (cfg_i.fk_template = cfg_t.pk);</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.view.v-cfg-opts-data">v_cfg_opts_data</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>cfg.v_cfg_opts_data Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>option</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>value</td>
+            	<td>bytea</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>description</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>owner</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>workplace</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>cookie</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>group</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_cfg_template</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_cfg_item</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT cfg_t.name AS option
+,
+    cfg_v.value
+,
+    cfg_t.description
+,
+    cfg_i.owner
+,
+    cfg_i.workplace
+,
+    cfg_i.cookie
+,
+    cfg_t.cfg_group AS "group"
+,
+    cfg_t.pk AS pk_cfg_template
+,
+    cfg_i.pk AS pk_cfg_item
+   
+FROM cfg.cfg_template cfg_t
+,
+    cfg.cfg_item cfg_i
+,
+    cfg.cfg_data cfg_v
+  
+WHERE (
+     (cfg_i.fk_template = cfg_t.pk)
+   AND (cfg_v.fk_item = cfg_i.pk)
+);</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.view.v-cfg-opts-numeric">v_cfg_opts_numeric</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>cfg.v_cfg_opts_numeric Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>option</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>value</td>
+            	<td>numeric</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>description</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>owner</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>workplace</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>cookie</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>group</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_cfg_template</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_cfg_item</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT cfg_t.name AS option
+,
+    cfg_v.value
+,
+    cfg_t.description
+,
+    cfg_i.owner
+,
+    cfg_i.workplace
+,
+    cfg_i.cookie
+,
+    cfg_t.cfg_group AS "group"
+,
+    cfg_t.pk AS pk_cfg_template
+,
+    cfg_i.pk AS pk_cfg_item
+   
+FROM cfg.cfg_template cfg_t
+,
+    cfg.cfg_item cfg_i
+,
+    cfg.cfg_numeric cfg_v
+  
+WHERE (
+     (cfg_i.fk_template = cfg_t.pk)
+   AND (cfg_v.fk_item = cfg_i.pk)
+);</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.view.v-cfg-opts-str-array">v_cfg_opts_str_array</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>cfg.v_cfg_opts_str_array Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>option</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>value</td>
+            	<td>text[]</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>description</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>owner</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>workplace</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>cookie</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>group</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_cfg_template</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_cfg_item</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT cfg_t.name AS option
+,
+    cfg_v.value
+,
+    cfg_t.description
+,
+    cfg_i.owner
+,
+    cfg_i.workplace
+,
+    cfg_i.cookie
+,
+    cfg_t.cfg_group AS "group"
+,
+    cfg_t.pk AS pk_cfg_template
+,
+    cfg_i.pk AS pk_cfg_item
+   
+FROM cfg.cfg_template cfg_t
+,
+    cfg.cfg_item cfg_i
+,
+    cfg.cfg_str_array cfg_v
+  
+WHERE (
+     (cfg_i.fk_template = cfg_t.pk)
+   AND (cfg_v.fk_item = cfg_i.pk)
+);</pre>
 	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-upd-vaccination-course-constraint">ft_upd_vaccination_course_constraint()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-BEGIN
-	NEW.row_version := OLD.row_version + 1;
-	NEW.modified_when := CURRENT_TIMESTAMP;
-	NEW.modified_by := SESSION_USER;
-	INSERT INTO audit.log_vaccination_course_constraint (
-		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, description
-	) VALUES (
-		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description
-	);
-	return NEW;
-END;</pre>
+
+	<!-- List off permissions -->
 	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-upd-vaccination-definition">ft_upd_vaccination_definition()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-BEGIN
-	NEW.row_version := OLD.row_version + 1;
-	NEW.modified_when := CURRENT_TIMESTAMP;
-	NEW.modified_by := SESSION_USER;
-	INSERT INTO audit.log_vaccination_definition (
-		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, id, fk_course, is_booster, seq_no, min_age_due, max_age_due, min_interval, comment
-	) VALUES (
-		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.fk_course, OLD.is_booster, OLD.seq_no, OLD.min_age_due, OLD.max_age_due, OLD.min_interval, OLD.comment
-	);
-	return NEW;
-END;</pre>
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+    </p>
 	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-upd-vaccination-schedule">ft_upd_vaccination_schedule()</a>
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.view.v-cfg-opts-string">v_cfg_opts_string</a>
 		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
         
-        <pre>
-BEGIN
-	NEW.row_version := OLD.row_version + 1;
-	NEW.modified_when := CURRENT_TIMESTAMP;
-	NEW.modified_by := SESSION_USER;
-	INSERT INTO audit.log_vaccination_schedule (
-		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, name, comment
-	) VALUES (
-		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.name, OLD.comment
-	);
-	return NEW;
-END;</pre>
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>cfg.v_cfg_opts_string Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>option</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>value</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>description</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>owner</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>workplace</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>cookie</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>group</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_cfg_template</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_cfg_item</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
 	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-upd-vaccine">ft_upd_vaccine()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-BEGIN
-	NEW.row_version := OLD.row_version + 1;
-	NEW.modified_when := CURRENT_TIMESTAMP;
-	NEW.modified_by := SESSION_USER;
-	INSERT INTO audit.log_vaccine (
-		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, id_route, is_live, min_age, max_age, comment, fk_brand
-	) VALUES (
-		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.id_route, OLD.is_live, OLD.min_age, OLD.max_age, OLD.comment, OLD.fk_brand
-	);
-	return NEW;
-END;</pre>
+	<pre>
+SELECT cfg_t.name AS option
+,
+    cfg_v.value
+,
+    cfg_t.description
+,
+    cfg_i.owner
+,
+    cfg_i.workplace
+,
+    cfg_i.cookie
+,
+    cfg_t.cfg_group AS "group"
+,
+    cfg_t.pk AS pk_cfg_template
+,
+    cfg_i.pk AS pk_cfg_item
+   
+FROM cfg.cfg_template cfg_t
+,
+    cfg.cfg_item cfg_i
+,
+    cfg.cfg_string cfg_v
+  
+WHERE (
+     (cfg_i.fk_template = cfg_t.pk)
+   AND (cfg_v.fk_item = cfg_i.pk)
+);</pre>
 	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-upd-vaccine-batches">ft_upd_vaccine_batches()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-BEGIN
-	NEW.row_version := OLD.row_version + 1;
-	NEW.modified_when := CURRENT_TIMESTAMP;
-	NEW.modified_by := SESSION_USER;
-	INSERT INTO audit.log_vaccine_batches (
-		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_vaccine, batch_no
-	) VALUES (
-		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_vaccine, OLD.batch_no
-	);
-	return NEW;
-END;</pre>
+
+	<!-- List off permissions -->
 	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-upd-waiting-list">ft_upd_waiting_list()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-BEGIN
-	NEW.row_version := OLD.row_version + 1;
-	NEW.modified_when := CURRENT_TIMESTAMP;
-	NEW.modified_by := SESSION_USER;
-	INSERT INTO audit.log_waiting_list (
-		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, fk_patient, registered, urgency, list_position, comment, area
-	) VALUES (
-		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_patient, OLD.registered, OLD.urgency, OLD.list_position, OLD.comment, OLD.area
-	);
-	return NEW;
-END;</pre>
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+    </p>
+	
+
+	<!-- We've gone through the table structure, now lets take a look at user functions -->
 	
 		<hr>
 		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.ft-upd-xlnk-identity">ft_upd_xlnk_identity()</a>
+			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.function.create-cfg-item-text-text-text-text-text">create_cfg_item(text, text, text, text, text)</a>
 		</h2>
-<h3>Returns: trigger</h3>
+<h3>Returns: integer</h3>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
-BEGIN
-	NEW.row_version := OLD.row_version + 1;
-	NEW.modified_when := CURRENT_TIMESTAMP;
-	NEW.modified_by := SESSION_USER;
-	INSERT INTO audit.log_xlnk_identity (
-		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
-		pk_audit, row_version, modified_when, modified_by, pk, xfk_identity, pupic, data
-	) VALUES (
-		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
-		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.xfk_identity, OLD.pupic, OLD.data
+declare
+	_option alias for $1;
+	_val_type alias for $2;
+	_workplace alias for $3;
+	_cookie alias for $4;
+	_owner alias for $5;
+	real_owner text;
+	pk_template integer;
+	pk_item integer;
+begin
+	-- check template
+	select into pk_template pk from cfg.cfg_template where name = _option and type = _val_type;
+	if not FOUND then
+		insert into cfg.cfg_template (name, type) values (_option, _val_type);
+		select into pk_template currval('cfg.cfg_template_pk_seq');
+	end if;
+	if _owner is null then
+		select into real_owner CURRENT_USER;
+	else
+		real_owner := _owner;
+	end if;
+	-- check item
+	if _cookie is NULL then
+		select into pk_item pk from cfg.cfg_item where
+			fk_template = pk_template and
+			owner = real_owner and
+			workplace = _workplace and
+			cookie is null;
+	else
+		select into pk_item pk from cfg.cfg_item where
+			fk_template = pk_template and
+			owner = real_owner and
+			workplace = _workplace and
+			cookie = _cookie;
+	end if;
+	if FOUND then
+		return pk_item;
+	end if;
+	insert into cfg.cfg_item (
+		fk_template, workplace, cookie, owner
+	) values (
+		pk_template,
+		_workplace,
+		_cookie,
+		real_owner
 	);
-	return NEW;
-END;</pre>
+	select into pk_item currval('cfg.cfg_item_pk_seq');
+	return pk_item;
+end;</pre>
 	
 		<hr>
 		<h2>Function:
-			<a href="gnumed-entire_schema.html#audit.schema">audit</a>.<a name="audit.function.register-table-for-auditing-name-name">register_table_for_auditing(name, name)</a>
+			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.function.set-option-text-anyelement-text-text-text">set_option(text, anyelement, text, text, text)</a>
 		</h2>
 <h3>Returns: boolean</h3>
 <h3>Language: PLPGSQL</h3>
-        <p>sanity-checking convenience function for registering a table for auditing</p>
+        <p>set option, owner = NULL means CURRENT_USER</p>
         <pre>
-DECLARE
-	_schema alias for $1;
-	_table alias for $2;
-BEGIN
-	-- does table exist ?
-	perform 1 from pg_class where
-		relname = _table
-			and
-		relnamespace = (select oid from pg_namespace where nspname = _schema)
-	;
-	if not found then
-		raise exception 'audit.register_table_for_auditing(): table [%.%] does not exist', _schema, _table;
-		return false;
+declare
+	_option alias for $1;
+	_value alias for $2;
+	_workplace alias for $3;
+	_cookie alias for $4;
+	_owner alias for $5;
+	val_type text;
+	pk_item integer;
+	rows integer;
+	cmd text;
+begin
+	-- determine data type
+	if _value is of (text, char, varchar, name) then
+		val_type := 'string';
+	elsif _value is of (smallint, integer, bigint, numeric, boolean) then
+		val_type := 'numeric';
+	elsif _value is of (bytea) then
+		val_type := 'data';
+	elsif _value is of (text[]) then
+		val_type := 'str_array';
+	else
+		raise exception 'cfg.set_option(text, any, text, text, text): invalid type of value';
 	end if;
-	-- already queued for auditing ?
-	perform 1 from audit.audited_tables where
-		table_name = _table
-			and
-		schema = _schema;
-	if found then
-		return true;
+	-- create template/item if need be
+	select into pk_item cfg.create_cfg_item(_option, val_type, _workplace, _cookie, _owner);
+	-- set item value
+	cmd := 'select 1 from cfg.cfg_' || val_type || ' where fk_item=' || pk_item || ';';
+	execute cmd;
+	get diagnostics rows = row_count;
+	found := rows <> 0;
+	if FOUND then
+		if val_type = 'str_array' then
+			cmd := 'update cfg.cfg_str_array set value=''{"' || array_to_string(_value, '","') || '"}'' where fk_item=' || pk_item || ';';
+		elsif val_type = 'data' then
+			cmd := 'update cfg.cfg_data set value=''' || encode(_value, 'escape') || ''' where fk_item=' || pk_item || ';';
+		else
+			cmd := 'update cfg.cfg_' || val_type || ' set value=' || quote_literal(_value) || ' where fk_item=' || pk_item || ';';
+		end if;
+		execute cmd;
+		return True;
 	end if;
-	-- add definition
-	insert into audit.audited_tables (
-		schema, table_name
-	) values (
-		_schema, _table
-	);
-	return true;
-END;</pre>
+	if val_type = 'str_array' then
+		cmd := 'insert into cfg.cfg_str_array(fk_item, value) values (' || pk_item || ', ''{"' || array_to_string(_value, '","') || '"}'');';
+	elsif val_type = 'data' then
+		cmd := 'insert into cfg.cfg_data(fk_item, value) values (' || pk_item || ', ''' || encode(_value, 'escape') || ''');';
+	else
+		cmd := 'insert into cfg.cfg_' || val_type || ' (fk_item, value) values (' || pk_item || ', ' || quote_literal(_value) || ');';
+	end if;
+	execute cmd;
+	return True;
+end;</pre>
 	
 
-<!-- billbill -->
+<!-- clinclin -->
 
 		
 		<hr>
-		<h1>Schema bill</h1>
-		
-			<p>Holds everything related to billing.</p>
+		<h1>Schema clin</h1>
 		
 
 		
@@ -40297,15 +54296,13 @@ END;</pre>
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#bill.schema">bill</a>.<a name="bill.table.bill">bill</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.-enum-allergy-type">_enum_allergy_type</a>
 		</h2>
         
-         <p>actual bills</p>
-        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>bill.bill Structure</caption>
+                <caption>clin._enum_allergy_type Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -40316,70 +54313,6 @@ END;</pre>
             <tr class="tr0">
 				<td>
                 
-                </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>row_version</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT now()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>modified_by</td>
-            	<td>name</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT "current_user"()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
                   
                 
                 </td>
@@ -40406,7 +54339,7 @@ END;</pre>
                   
                 
                 </td>
-            	<td>invoice_id</td>
+            	<td>value</td>
             	<td>text</td>
                 <td><i>
 				
@@ -40417,130 +54350,10 @@ END;</pre>
                     
 				
 
-				
-				
-				</i>
-				<br><br>the ID of the bill
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>close_date</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				<br><br>cannot add further bill_items after this date if not NULL
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>apply_vat</td>
-            	<td>boolean</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				<br><br>whether or not to apply VAT on the invoice
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.identity">dem.identity.pk</a>
-                  
-                
-                </td>
-            	<td>fk_receiver_identity</td>
-            	<td>integer</td>
-                <td><i>
-				
-					
-
-					
-				
-
-				
-				
-				</i>
-				<br><br>link to the receiver as a GNUmed identity, if known
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.lnk-person-org-address">dem.lnk_person_org_address.id</a>
-                  
-                
-                </td>
-            	<td>fk_receiver_address</td>
-            	<td>integer</td>
-                <td><i>
-				
-					
-
-					
-				
-
-				
-				
-				</i>
-				<br><br>links the address of the receiver of the invoice
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                  
-                  <a href="gnumed-entire_schema.html#blobs.table.doc-med">blobs.doc_med.pk</a>
-                  
-                
-                </td>
-            	<td>fk_doc</td>
-            	<td>integer</td>
-                <td><i>
-				
-					
-
-					
-				
-
-				
+				NOT NULL
 				
 				</i>
-				<br><br>links to the document which contains the invoice PDF
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>comment</td>
-            	<td>text</td>
-                <td><i>
 				
-
-				
-				
-				</i>
-				<br><br>arbitrary comments on bills
 				</td>
 			 </tr>
             
@@ -40548,13 +54361,6 @@ END;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table bill.bill Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
 
 		
 		
@@ -40562,43 +54368,13 @@ END;</pre>
 
         <!-- Constraint List -->
 		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>bill.bill Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>bill_bill_sane_apply_vat</td>
-                <td>CHECK (((apply_vat IS NOT NULL) OR ((apply_vat IS NULL) AND (fk_doc IS NULL))))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>bill_bill_sane_comment</td>
-                <td>CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>bill_bill_sane_invoice_id</td>
-                <td>CHECK ((gm.is_null_or_blank_string(invoice_id) IS FALSE))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>bill_bill_sane_recv_adr</td>
-                <td>CHECK (((fk_receiver_address IS NOT NULL) OR (close_date IS NULL)))</td>
-            </tr>
-			
-		</table>
-		
 
         <!-- Foreign Key Discovery -->
 		
 			<p>Tables referencing this one via Foreign Key Constraints:</p>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#bill.table.bill-item">bill.bill_item</a></li>
+				<li><a href="gnumed-entire_schema.html#clin.table.allergy">clin.allergy</a></li>
 			</ul>
 		
 		
@@ -40614,21 +54390,21 @@ END;</pre>
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#bill.schema">Schema bill</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#bill.schema">bill</a>.<a name="bill.table.bill-item">bill_item</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.allergy">allergy</a>
 		</h2>
         
-         <p>items patients currently *are* billed for</p>
+         <p>patient allergy details</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>bill.bill_item Structure</caption>
+                <caption>clin.allergy Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -40687,11 +54463,19 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -40703,35 +54487,44 @@ END;</pre>
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>pk_item</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
+				NOT NULL
+				DEFAULT nextval('clin_root_item_pk_item_seq'::regclass)
+				</i>
 				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
 				
+
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.pk</a>
+                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
                   
                 
                 </td>
-            	<td>fk_provider</td>
+            	<td>fk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -40743,19 +54536,19 @@ END;</pre>
 				NOT NULL
 				
 				</i>
-				<br><br>by whom or on whose behalf did the billable activity happen
+				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
                   
                 
                 </td>
-            	<td>fk_encounter</td>
+            	<td>fk_episode</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -40767,39 +54560,62 @@ END;</pre>
 				NOT NULL
 				
 				</i>
-				<br><br>the encounter during which the billable action for this item took place
+				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>date_to_bill</td>
-            	<td>date</td>
+            	<td>narrative</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>The date the bill item was caused. If NULL, use .fk_encounter -> .started
+				<br><br>used as field "reaction"
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>description</td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
 
 				
+				DEFAULT 'o'::text
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
 				
 				</i>
-				<br><br>Can be used to further explain the bill item over and above .fk_billable.description.
+				
 				</td>
 			 </tr>
             
@@ -40807,15 +54623,15 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>net_amount_per_unit</td>
-            	<td>numeric</td>
+            	<td>substance</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				NOT NULL
 				
 				</i>
-				<br><br>How much to charge for one unit of this bill item.
+				<br><br>real-world name of substance the patient reacted to, brand name if drug
 				</td>
 			 </tr>
             
@@ -40823,15 +54639,19 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>currency</td>
+            	<td>substance_code</td>
             	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>Which currency to charge in. Must not be NULL if .net_amount_per_unit is not NULL.
+				<br><br>data source specific opaque product code; must provide a link
+	 to a unique product/substance in the database in use; should follow
+	 the parseable convention of "<source>::<source version>::<identifier>",
+	 e.g. "MIMS::2003-1::190" for Zantac; it is left as an exercise to the
+	 application to know what to do with this information
 				</td>
 			 </tr>
             
@@ -40839,51 +54659,59 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>status</td>
+            	<td>generics</td>
             	<td>text</td>
                 <td><i>
 				
 
 				
-				DEFAULT 'new'::text
+				
 				</i>
-				<br><br>the status of this item
+				<br><br>names of generic compounds if drug; brand names change/disappear, generic names do not
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#ref.table.billable">ref.billable.pk</a>
-                  
-                
                 </td>
-            	<td>fk_billable</td>
-            	<td>integer</td>
+            	<td>allergene</td>
+            	<td>text</td>
                 <td><i>
 				
-					
 
-					
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>Links to the billable item this bill item stands for.
+				<br><br>name of allergenic ingredient in substance if known
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
+                </td>
+            	<td>atc_code</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>ATC code of allergene or substance if approprate, applicable for penicilline, not so for cat fur
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
                   
-                  <a href="gnumed-entire_schema.html#bill.table.bill">bill.bill.pk</a>
+                  <a href="gnumed-entire_schema.html#clin.table.-enum-allergy-type">clin._enum_allergy_type.pk</a>
                   
                 
                 </td>
-            	<td>fk_bill</td>
+            	<td>fk_type</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -40892,42 +54720,46 @@ END;</pre>
 					
 				
 
-				
+				NOT NULL
 				
 				</i>
-				<br><br>Links to the bill this bill item is on if any.
+				<br><br>allergy/sensitivity
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>unit_count</td>
-            	<td>integer</td>
+            	<td>generic_specific</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT 1
+				
+				DEFAULT false
 				</i>
-				<br><br>The number of times this item is to be billed. 0 can be used for informative items.
+				<br><br>only meaningful for *drug*/*generic* reactions:
+	 1) true: applies to one in "generics" forming "substance",
+			  if more than one generic listed in "generics" then
+			  "allergene" *must* contain the generic in question;
+	 2) false: applies to drug class of "substance";
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>amount_multiplier</td>
-            	<td>numeric</td>
+            	<td>definite</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT 1
+				
+				DEFAULT false
 				</i>
-				<br><br>A multiplier to apply to .net_amount_per_unit. Can be used for discounts, rebates, or increases. Must be > 0.
+				<br><br>true: definite, false: not definite
 				</td>
 			 </tr>
             
@@ -40935,10 +54767,10 @@ END;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table bill.bill_item Inherits
+        <p>Table clin.allergy Inherits
         
             
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+           <a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin_root_item</a>, 
         
         </p>
 		
@@ -40951,35 +54783,20 @@ END;</pre>
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>bill.bill_item Constraints</caption>
+            <caption>clin.allergy Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
-				<td>bill_bill_item_sane_count</td>
-                <td>CHECK ((unit_count > (-1)))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>bill_bill_item_sane_currency</td>
-                <td>CHECK ((gm.is_null_or_blank_string(currency) IS FALSE))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>bill_bill_item_sane_desc</td>
-                <td>CHECK ((gm.is_null_or_non_empty_string(description) IS TRUE))</td>
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
             </tr>
 			
             <tr class="tr1">
-				<td>bill_bill_item_sane_multiplier</td>
-                <td>CHECK ((amount_multiplier > (0)::numeric))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>valid_stati</td>
-                <td>CHECK ((status = ANY (ARRAY['new'::text, 'transferred'::text])))</td>
+				<td>clin_root_item_sane_soap_cat</td>
+                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
             </tr>
 			
 		</table>
@@ -40990,9 +54807,9 @@ END;</pre>
 
     <!-- Indexes -->
     
-       idx_bill_bill_item_fk_bill fk_bill
+       idx_clin_allergy_fk_encounter fk_encounter
     
-       idx_bill_bill_item_fk_billable fk_billable
+       idx_clin_allergy_fk_episode fk_episode
     
 
 	<!-- View Definition -->
@@ -41003,27 +54820,97 @@ END;</pre>
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#bill.schema">Schema bill</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#bill.schema">bill</a>.<a name="bill.table.lnk-enc-type2billable">lnk_enc_type2billable</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.allergy-state">allergy_state</a>
 		</h2>
         
-         <p>actual bills</p>
-        
 
 
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>bill.lnk_enc_type2billable Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.allergy_state Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				DEFAULT "current_user"()
+				</i>
+				
+				</td>
+			 </tr>
             
             <tr class="tr0">
 				<td>
@@ -41051,24 +54938,53 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.encounter-type">clin.encounter_type.pk</a>
-                  
-                
                 </td>
-            	<td>fk_encounter_type</td>
+            	<td>has_allergy</td>
             	<td>integer</td>
                 <td><i>
 				
-					
 
-					
+				
+				
+				</i>
+				<br><br>patient allergenic state:
+	 - null: unknown, not asked, no data available
+	 - -1: unknown, asked, no data obtained
+	 - 0:  known, asked, has no known allergies
+	 - 1:  known, asked, does have allergies
+	
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>comment</td>
+            	<td>text</td>
+                <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>Links to encounter type this billable is associated with.
+				<br><br>A comment on the state, such as "patient says no allergies but I think he is holding back some".
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>last_confirmed</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>When was the state of allergies last confirmed. Must be not NULL if has_allergy is not NULL.
 				</td>
 			 </tr>
             
@@ -41076,11 +54992,11 @@ END;</pre>
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#ref.table.billable">ref.billable.pk</a>
+                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
                   
                 
                 </td>
-            	<td>fk_billable</td>
+            	<td>fk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -41092,7 +55008,7 @@ END;</pre>
 				NOT NULL
 				
 				</i>
-				<br><br>Links to the billable item the encounter type is associated with.
+				
 				</td>
 			 </tr>
             
@@ -41100,6 +55016,13 @@ END;</pre>
 
         <!-- Inherits -->
 		
+        <p>Table clin.allergy_state Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
 
 		
 		
@@ -41107,16 +55030,37 @@ END;</pre>
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.allergy_state Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>allergy_state_check</td>
+                <td>CHECK (((has_allergy IS NULL) OR ((has_allergy IS NOT NULL) AND (last_confirmed IS NOT NULL))))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>allergy_state_has_allergy_check</td>
+                <td>CHECK ((has_allergy = ANY (ARRAY[NULL::integer, 0, 1])))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
 
     <!-- Indexes -->
     
-       idx_lnk_enc_type2billable_fk_billable fk_billable
-    
-       idx_lnk_enc_type2billable_fk_encounter_type fk_encounter_type
-    
 
 	<!-- View Definition -->
 	
@@ -41126,19 +55070,21 @@ END;</pre>
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#bill.schema">Schema bill</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
-		<h2>View:
+		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#bill.schema">bill</a>.<a name="bill.view.v-bill-items">v_bill_items</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.clin-aux-note">clin_aux_note</a>
 		</h2>
         
+         <p>Other tables link to this if they need more free text fields.</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>bill.v_bill_items Structure</caption>
+                <caption>clin.clin_aux_note Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -41150,13 +55096,13 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_bill_item</td>
+            	<td>pk_audit</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -41166,12 +55112,12 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>billable_code</td>
-            	<td>text</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -41182,13 +55128,13 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>billable_description</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -41197,14 +55143,22 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
-            	<td>item_detail</td>
-            	<td>text</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
+					
 
+					
 				
-				
+
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -41214,13 +55168,13 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>date_to_bill</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_item</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('clin_root_item_pk_item_seq'::regclass)
 				</i>
 				
 				</td>
@@ -41230,13 +55184,13 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>net_amount_per_unit</td>
-            	<td>numeric</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -41245,13 +55199,21 @@ END;</pre>
             <tr class="tr0">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  
+                
                 </td>
-            	<td>unit_count</td>
+            	<td>fk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
+					
 
+					
 				
+
+				NOT NULL
 				
 				</i>
 				
@@ -41261,13 +55223,21 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
+                  
+                
                 </td>
-            	<td>amount_multiplier</td>
-            	<td>numeric</td>
+            	<td>fk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
 
+					
 				
+
+				NOT NULL
 				
 				</i>
 				
@@ -41278,8 +55248,8 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>total_amount</td>
-            	<td>numeric</td>
+            	<td>narrative</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -41294,8 +55264,8 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>vat</td>
-            	<td>numeric</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -41309,11 +55279,18 @@ END;</pre>
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>currency</td>
-            	<td>text</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
+
+					
+				
 
 				
 				
@@ -41322,33 +55299,98 @@ END;</pre>
 				</td>
 			 </tr>
             
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table clin.clin_aux_note Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin_root_item</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.clin_aux_note Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
             <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>raw_date_to_bill</td>
-            	<td>date</td>
-                <td><i>
-				
+				<td>clin_root_item_sane_soap_cat</td>
+                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
+            </tr>
+			
+		</table>
+		
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+       idx_clin_clin_aux_note_fk_encounter fk_encounter
+    
+       idx_clin_clin_aux_note_fk_episode fk_episode
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.clin-diag">clin_diag</a>
+		</h2>
+        
+         <p>stores additional detail on those clin.clin_narrative
+	 rows where soap_cat=a that are true diagnoses,
+	 true diagnoses DO have a code from one of the coding systems</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.clin_diag Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>billable_amount</td>
-            	<td>numeric</td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -41358,12 +55400,12 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>vat_multiplier</td>
-            	<td>numeric</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -41374,13 +55416,13 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>billable_currency</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -41389,14 +55431,22 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
-            	<td>billable_comment</td>
-            	<td>text</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
+					
 
+					
 				
-				
+
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -41405,11 +55455,18 @@ END;</pre>
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>billable_active</td>
-            	<td>boolean</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
+
+					
+				
 
 				
 				
@@ -41421,13 +55478,29 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.clin-narrative">clin.clin_narrative.pk</a>
+                  
+                
+                  
+                
                 </td>
-            	<td>billable_discountable</td>
-            	<td>boolean</td>
+            	<td>fk_narrative</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
+
+					
+				
+					
 
+					
+                       UNIQUE
+                    
 				
+
+				NOT NULL
 				
 				</i>
 				
@@ -41438,13 +55511,13 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>catalog_long</td>
-            	<td>text</td>
+            	<td>laterality</td>
+            	<td>character(1)</td>
                 <td><i>
 				
 
 				
-				
+				DEFAULT NULL::bpchar
 				</i>
 				
 				</td>
@@ -41454,15 +55527,18 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>catalog_short</td>
-            	<td>text</td>
+            	<td>is_chronic</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT false
 				</i>
-				
+				<br><br>whether this diagnosis is chronic, eg. no complete
+	 cure is to be expected, regardless of whether it is
+	 *active* right now (think of active/non-active phases
+	 of Multiple Sclerosis which is sure chronic)
 				</td>
 			 </tr>
             
@@ -41470,15 +55546,15 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>catalog_version</td>
-            	<td>text</td>
+            	<td>is_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT true
 				</i>
-				
+				<br><br>whether diagnosis is currently active or dormant
 				</td>
 			 </tr>
             
@@ -41486,13 +55562,13 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>catalog_language</td>
-            	<td>text</td>
+            	<td>is_definite</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT false
 				</i>
 				
 				</td>
@@ -41502,45 +55578,113 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT true
 				</i>
-				
+				<br><br>whether this diagnosis is considered clinically
+	 relevant, eg. significant;
+	 currently active diagnoses are considered to
+	 always be relevant, while inactive ones may
+	 or may not be
 				</td>
 			 </tr>
             
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table clin.clin_diag Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.clin_diag Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
             <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>pk_encounter_type</td>
-            	<td>integer</td>
-                <td><i>
-				
+				<td>clin_diag_laterality_check</td>
+                <td>CHECK (((laterality = ANY (ARRAY['l'::bpchar, 'r'::bpchar, 'b'::bpchar, '?'::bpchar])) OR (laterality IS NULL)))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>if_active_then_relevant</td>
+                <td>CHECK (((is_active = false) OR ((is_active = true) AND (clinically_relevant = true))))</td>
+            </tr>
+			
+		</table>
+		
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.clin-item-type">clin_item_type</a>
+		</h2>
+        
+         <p>stores arbitrary types for tagging clinical items</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.clin_item_type Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_provider</td>
+            	<td>pk_audit</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -41550,12 +55694,12 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_encounter_to_bill</td>
+            	<td>row_version</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -41566,13 +55710,13 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_bill</td>
-            	<td>integer</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -41581,14 +55725,22 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
-            	<td>pk_billable</td>
-            	<td>integer</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
+					
 
+					
 				
-				
+
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -41597,11 +55749,18 @@ END;</pre>
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>pk_data_source</td>
-            	<td>integer</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
+
+					
+				
 
 				
 				
@@ -41613,16 +55772,48 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>xmin_bill_item</td>
-            	<td>xid</td>
+            	<td>type</td>
+            	<td>text</td>
                 <td><i>
 				
+					
 
+					
+                       UNIQUE
+                    
 				
-				
+
+				NOT NULL
+				DEFAULT 'history'::text
 				</i>
+				<br><br>the full name of the item type such as "family history"
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>code</td>
+            	<td>text</td>
+                <td><i>
+				
+					
+
+					
+                       UNIQUE
+                    
 				
+
+				NOT NULL
+				DEFAULT 'Hx'::text
+				</i>
+				<br><br>shorthand for the type, eg "FHx"
 				</td>
 			 </tr>
             
@@ -41630,103 +55821,75 @@ END;</pre>
 
         <!-- Inherits -->
 		
+        <p>Table clin.clin_item_type Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
 
 		
+		
+		
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.clin_item_type Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-type2item">clin.lnk_type2item</a></li>
+			</ul>
+		
+		
 
     <!-- Indexes -->
     
 
 	<!-- View Definition -->
 	
-	<pre>
-SELECT b_bi.pk AS pk_bill_item
-, r_b.code AS billable_code
-, r_b.term AS billable_description
-, b_bi.description AS item_detail
-, COALESCE
-(
-     (b_bi.date_to_bill)::timestamp with time zone
-     , c_enc.started
-) AS date_to_bill
-, b_bi.net_amount_per_unit
-, b_bi.unit_count
-, b_bi.amount_multiplier
-, (
-     (
-           (b_bi.unit_count)::numeric * b_bi.net_amount_per_unit
-     ) * b_bi.amount_multiplier
-) AS total_amount
-, (
-     (
-           (
-                 (b_bi.unit_count)::numeric * b_bi.net_amount_per_unit
-           ) * b_bi.amount_multiplier
-     ) * r_b.vat_multiplier
-) AS vat
-, b_bi.currency
-, b_bi.date_to_bill AS raw_date_to_bill
-, r_b.amount AS billable_amount
-, r_b.vat_multiplier
-, r_b.currency AS billable_currency
-, r_b.comment AS billable_comment
-, r_b.active AS billable_active
-, r_b.discountable AS billable_discountable
-, r_ds.name_long AS catalog_long
-, r_ds.name_short AS catalog_short
-, r_ds.version AS catalog_version
-, r_ds.lang AS catalog_language
-, c_enc.fk_patient AS pk_patient
-, c_enc.fk_type AS pk_encounter_type
-, b_bi.fk_provider AS pk_provider
-, b_bi.fk_encounter AS pk_encounter_to_bill
-, b_bi.fk_bill AS pk_bill
-, r_b.pk AS pk_billable
-, r_b.fk_data_source AS pk_data_source
-, b_bi.xmin AS xmin_bill_item 
-FROM (
-     (
-           (bill.bill_item b_bi 
-              JOIN ref.billable r_b 
-                ON (
-                       (b_bi.fk_billable = r_b.pk)
-                 )
-           )
-   LEFT JOIN ref.data_source r_ds 
-          ON (
-                 (r_b.fk_data_source = r_ds.pk)
-           )
-     )
-LEFT JOIN clin.encounter c_enc 
-    ON (
-           (b_bi.fk_encounter = c_enc.pk)
-     )
-);</pre>
-	
 
 	<!-- List off permissions -->
 	
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#bill.schema">Schema bill</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
-		<h2>View:
+		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#bill.schema">bill</a>.<a name="bill.view.v-bills">v_bills</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.clin-narrative">clin_narrative</a>
 		</h2>
         
+         <p>Used to store clinical free text *not* associated
+	 with any other table. Used to implement a simple
+	 SOAP structure. Also other tags can be associated
+	 via link tables.</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>bill.v_bills Structure</caption>
+                <caption>clin.clin_narrative Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -41738,13 +55901,13 @@ LEFT JOIN clin.encounter c_enc
 				<td>
                 
                 </td>
-            	<td>pk_bill</td>
+            	<td>pk_audit</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -41754,12 +55917,12 @@ LEFT JOIN clin.encounter c_enc
 				<td>
                 
                 </td>
-            	<td>invoice_id</td>
-            	<td>text</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -41770,13 +55933,13 @@ LEFT JOIN clin.encounter c_enc
 				<td>
                 
                 </td>
-            	<td>pk_receiver_identity</td>
-            	<td>integer</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -41785,46 +55948,22 @@ LEFT JOIN clin.encounter c_enc
             <tr class="tr1">
 				<td>
                 
-                </td>
-            	<td>total_amount</td>
-            	<td>numeric</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
                 
                 </td>
-            	<td>total_vat</td>
-            	<td>numeric</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
+					
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>total_amount_with_vat</td>
-            	<td>numeric</td>
-                <td><i>
+					
 				
 
-				
-				
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -41834,13 +55973,13 @@ LEFT JOIN clin.encounter c_enc
 				<td>
                 
                 </td>
-            	<td>percent_vat</td>
-            	<td>numeric</td>
+            	<td>pk_item</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('clin_root_item_pk_item_seq'::regclass)
 				</i>
 				
 				</td>
@@ -41850,60 +55989,36 @@ LEFT JOIN clin.encounter c_enc
 				<td>
                 
                 </td>
-            	<td>currency</td>
-            	<td>text</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
-				
+				<br><br>when did the item reach clinical reality
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                </td>
-            	<td>close_date</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  
                 
                 </td>
-            	<td>apply_vat</td>
-            	<td>boolean</td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>comment</td>
-            	<td>text</td>
-                <td><i>
+					
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -41913,13 +56028,21 @@ LEFT JOIN clin.encounter c_enc
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
+                  
+                
                 </td>
-            	<td>pk_receiver_address</td>
+            	<td>fk_episode</td>
             	<td>integer</td>
                 <td><i>
 				
+					
 
+					
 				
+
+				NOT NULL
 				
 				</i>
 				
@@ -41930,8 +56053,8 @@ LEFT JOIN clin.encounter c_enc
 				<td>
                 
                 </td>
-            	<td>pk_doc</td>
-            	<td>integer</td>
+            	<td>narrative</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -41946,8 +56069,8 @@ LEFT JOIN clin.encounter c_enc
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -41961,291 +56084,123 @@ LEFT JOIN clin.encounter c_enc
             <tr class="tr0">
 				<td>
                 
-                </td>
-            	<td>pk_bill_items</td>
-            	<td>integer[]</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
+                  
                 
                 </td>
-            	<td>xmin_bill</td>
-            	<td>xid</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT b_b.pk AS pk_bill
-, b_b.invoice_id
-, b_b.fk_receiver_identity AS pk_receiver_identity
-, (
-SELECT round
-     (sum
-           (v_bill_items.total_amount)
-           , 2
-     ) AS round 
-  FROM bill.v_bill_items 
- WHERE (v_bill_items.pk_bill = b_b.pk)
-) AS total_amount
-, (
-SELECT round
-     (sum
-           (v_bill_items.vat)
-           , 2
-     ) AS round 
-  FROM bill.v_bill_items 
- WHERE (v_bill_items.pk_bill = b_b.pk)
-) AS total_vat
-, (
-SELECT round
-     (sum
-           (
-                 (v_bill_items.total_amount + v_bill_items.vat)
-           )
-           , 2
-     ) AS round 
-  FROM bill.v_bill_items 
- WHERE (v_bill_items.pk_bill = b_b.pk)
-) AS total_amount_with_vat
-, (
-SELECT (v_bill_items.vat_multiplier * 
-           (100)::numeric
-     )
-  FROM bill.v_bill_items 
- WHERE (v_bill_items.pk_bill = b_b.pk) LIMIT 1
-) AS percent_vat
-, (
-SELECT v_bill_items.currency 
-  FROM bill.v_bill_items 
- WHERE (v_bill_items.pk_bill = b_b.pk) LIMIT 1
-) AS currency
-, b_b.close_date
-, b_b.apply_vat
-, b_b.comment
-, b_b.fk_receiver_address AS pk_receiver_address
-, b_b.fk_doc AS pk_doc
-, (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
- WHERE (encounter.pk = 
-           (
-            SELECT bill_item.fk_encounter 
-              FROM bill.bill_item 
-             WHERE (bill_item.fk_bill = b_b.pk) LIMIT 1
-           )
-     )
-) AS pk_patient
-, (
-SELECT array_agg
-     (sorted_values.pk_bill_item) AS array_agg 
-  FROM (
-      SELECT b_vbi.pk_bill_item 
-        FROM bill.v_bill_items b_vbi 
-       WHERE (b_vbi.pk_bill = b_b.pk)
-    ORDER BY b_vbi.date_to_bill
-           , b_vbi.billable_code
-     ) sorted_values
-) AS pk_bill_items
-, b_b.xmin AS xmin_bill 
-FROM bill.bill b_b;</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#bill.schema">Schema bill</a>
-    </p>
-	
-
-	<!-- We've gone through the table structure, now lets take a look at user functions -->
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#bill.schema">bill</a>.<a name="bill.function.get-bill-receiver-identity-integer">get_bill_receiver_identity(integer)</a>
-		</h2>
-<h3>Returns: integer</h3>
-<h3>Language: SQL</h3>
-        
-        <pre>
-select
-	value
-from (
-	select
-		id.pk_id,
-		id.value::integer
-	from
-		dem.v_external_ids4identity id
-			join dem.identity d_i on (id.value = d_i.pk::text)
-	where
-		id.pk_type = (select pk from dem.enum_ext_id_types where name = 'bill receiver' and issuer = 'GNUmed')
-			and
-		id.pk_identity = $1
-	union all
-	select
-		0,
-		$1
-) me
-limit 1;</pre>
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#bill.schema">bill</a>.<a name="bill.function.trf-prevent-empty-bills">trf_prevent_empty_bills()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        <p>Prevent bills to become void of items due to deletions/updates of bill items.</p>
-        <pre>
-DECLARE
-	_item_count integer;
-	_msg text;
-BEGIN
-	if TG_OP = 'UPDATE' then
-		if OLD.fk_bill IS NULL then
-			return NULL;
-		end if;
-		if OLD.fk_bill IS NOT DISTINCT FROM NEW.fk_bill then
-			return NULL;
-		end if;
-	else
-		if OLD.fk_bill is NULL then
-			return NULL;
-		end if;
-	end if;
-	-- we now either:
-	--	DELETE with .fk_bill NOT NULL
-	-- or:
-	--	UPDATE with an .fk_bill change (including towards fk_bill = NULL)
-	-- let us check whether the (previous) bill still exists
-	-- at all or whether we are deleting the bill (and thereby
-	-- setting our .fk_bill to NULL)
-	-- only works at or below REPEATABLE READ after deletion of bill
-	perform 1 from bill.bill where pk = OLD.fk_bill;
-	if FOUND is FALSE then
-		return NULL;
-	end if;
-	select count(1) into _item_count
-	from bill.bill_item
-	where
-		fk_bill = OLD.fk_bill
-			and
-		pk != OLD.pk;
-	if _item_count > 0 then
-		return NULL;
-	end if;
-	_msg := '[bill.trf_prevent_empty_bills]: cannot remove (by '
-			|| '<' || TG_OP || '>'
-			||') the only item (bill.bill_item.pk='
-			|| coalesce(OLD.pk::text, '<NULL>'::text)
-			|| ') from bill (bill.bill_item.fk_bill=bill.bill.pk='
-			|| coalesce(OLD.fk_bill::text, '<NULL>'::text)
-			|| ') ';
-	raise exception unique_violation using message = _msg;
-	return NULL;
-END;</pre>
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#bill.schema">bill</a>.<a name="bill.function.trf-prevent-mislinked-bills">trf_prevent_mislinked_bills()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        <p>Prevent bills to link to invoices of another patient.</p>
-        <pre>
-DECLARE
-	_doc_patient integer;
-	_bill_patient integer;
-	_msg text;
-BEGIN
-	if NEW.fk_doc IS NULL then
-		return NEW;
-	end if;
-	if TG_OP = 'UPDATE' then
-		if OLD.fk_doc IS NOT DISTINCT FROM NEW.fk_doc then
-			return NEW;
-		end if;
-	end if;
-	-- we now either:
-	--	INSERT with .fk_doc NOT NULL
-	-- or:
-	--	UPDATE with an .fk_bill change to a NON-NULL value
-	select pk_patient into _doc_patient
-	from blobs.v_doc_med
-	where
-		pk_doc = NEW.fk_doc;
-	select pk_patient into _bill_patient
-	from bill.v_bills
-	where
-		pk_bill = NEW.pk;
-	if _doc_patient = _bill_patient then
-		return NEW;
-	end if;
-	_msg := '[bill.trf_prevent_mislinked_bills]: patient mismatch between '
-		|| 'bill (pk=' || NEW.pk || ', patient=' || _bill_patient || ') '
-		|| 'and invoice (pk=' || NEW.fk_doc || ', patient=' || _doc_patient || ')';
-	raise exception integrity_constraint_violation using message = _msg;
-	return NULL;
-END;</pre>
-	
+					
+				
 
-<!-- blobsblobs -->
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
 
+        <!-- Inherits -->
 		
-		<hr>
-		<h1>Schema blobs</h1>
+        <p>Table clin.clin_narrative Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin_root_item</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.clin_narrative Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>clin_root_item_sane_soap_cat</td>
+                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>narrative_neither_null_nor_empty</td>
+                <td>CHECK ((btrim(COALESCE(narrative, ''::text)) <> ''::text))</td>
+            </tr>
+			
+		</table>
 		
 
+        <!-- Foreign Key Discovery -->
+		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.clin-diag">clin.clin_diag</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2narrative">clin.lnk_code2narrative</a></li>
+			</ul>
 		
 		
+
+    <!-- Indexes -->
+    
+       idx_clin_clin_narrative_fk_encounter fk_encounter
+    
+       idx_clin_clin_narrative_fk_episode fk_episode
+    
+       idx_narrative_modified_by modified_by
+    
+       idx_narrative_soap_cat soap_cat) WHERE (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text])
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
+    </p>
+	
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.table.doc-desc">doc_desc</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.clin-root-item">clin_root_item</a>
 		</h2>
         
-         <p>A textual description of the content such
-	 as a result summary. Several of these may
-	 belong to one document object.</p>
+         <p>ancestor table for clinical items of any kind, basic
+	 unit of clinical information, do *not* store data in
+	 here directly, use child tables,
+	 contains all the clinical narrative aggregated for full
+	 text search, ancestor for all tables that want to store
+	 clinical free text</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>blobs.doc_desc Structure</caption>
+                <caption>clin.clin_root_item Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -42323,7 +56278,7 @@ END;</pre>
                   
                 
                 </td>
-            	<td>pk</td>
+            	<td>pk_item</td>
             	<td>serial</td>
                 <td><i>
 				
@@ -42336,21 +56291,39 @@ END;</pre>
 				
 				
 				</i>
-				
+				<br><br>the primary key, not named "id" or "pk" as usual since child
+	 tables will have "id"/"pk"-named primary keys already and
+	 we would get duplicate columns while inheriting from this
+	 table
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#blobs.table.doc-med">blobs.doc_med.pk</a>
-                  
+                </td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				<br><br>when this clinical item became known, can be different from
+	 when it was entered into the system (= audit.audit_fields.modified_when)
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
                 
                   
+                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  
                 
                 </td>
-            	<td>fk_doc</td>
+            	<td>fk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -42358,41 +56331,68 @@ END;</pre>
 
 					
 				
+
+				NOT NULL
+				
+				</i>
+				<br><br>the encounter this item belongs to
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
+                  
+                
+                </td>
+            	<td>fk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
 					
 
 					
-                       UNIQUE#1
-                    
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>the episode this item belongs to
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>text</td>
+            	<td>narrative</td>
             	<td>text</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
+				
+				
+				</i>
+				<br><br>each clinical item by default inherits a free text field for clinical narrative
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>soap_cat</td>
+            	<td>text</td>
+                <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>each clinical item must be either one of the S, O, A, P, U
+	 categories or NULL to indicate a non-clinical item, U meaning Unspecified-but-clinical
 				</td>
 			 </tr>
             
@@ -42400,7 +56400,7 @@ END;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table blobs.doc_desc Inherits
+        <p>Table clin.clin_root_item Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
@@ -42414,13 +56414,35 @@ END;</pre>
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.clin_root_item Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>clin_root_item_sane_soap_cat</td>
+                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
 
     <!-- Indexes -->
     
-       idx_doc_desc_fk_doc fk_doc
+       idx_cri_encounter fk_encounter
+    
+       idx_cri_episode fk_episode
     
 
 	<!-- View Definition -->
@@ -42431,22 +56453,21 @@ END;</pre>
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.table.doc-med">doc_med</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.encounter">encounter</a>
 		</h2>
         
-         <p>a medical document object possibly containing several
-	 data objects such as several pages of a paper document</p>
+         <p>a clinical encounter between a person and the health care system</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>blobs.doc_med Structure</caption>
+                <caption>clin.encounter Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -42505,11 +56526,19 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -42545,11 +56574,11 @@ END;</pre>
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  <a href="gnumed-entire_schema.html#clin.table.patient">clin.patient.fk_identity</a>
                   
                 
                 </td>
-            	<td>fk_encounter</td>
+            	<td>fk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -42561,7 +56590,7 @@ END;</pre>
 				NOT NULL
 				
 				</i>
-				<br><br>the encounter in which this document was entered into the system
+				<br><br>PK of subject of care, should be PUPIC, actually
 				</td>
 			 </tr>
             
@@ -42569,11 +56598,11 @@ END;</pre>
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
+                  <a href="gnumed-entire_schema.html#clin.table.encounter-type">clin.encounter_type.pk</a>
                   
                 
                 </td>
-            	<td>fk_episode</td>
+            	<td>fk_type</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -42583,11 +56612,9 @@ END;</pre>
 				
 
 				NOT NULL
-				
+				DEFAULT 1
 				</i>
-				<br><br>the episode this document pertains to, this may not be the only
-	 one applicable to the document (think discharge letters), see also
-	 lnk_doc_med2episode
+				<br><br>PK of type of this encounter
 				</td>
 			 </tr>
             
@@ -42595,11 +56622,11 @@ END;</pre>
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#blobs.table.doc-type">blobs.doc_type.pk</a>
+                  <a href="gnumed-entire_schema.html#dem.table.org-unit">dem.org_unit.pk</a>
                   
                 
                 </td>
-            	<td>fk_type</td>
+            	<td>fk_location</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -42611,8 +56638,7 @@ END;</pre>
 				NOT NULL
 				
 				</i>
-				<br><br>semantic type of document (not type of file or mime
-	 type), such as "referral letter", "discharge summary", etc.
+				<br><br>PK of location *of care*, e.g. where the provider is at
 				</td>
 			 </tr>
             
@@ -42620,7 +56646,24 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>comment</td>
+            	<td>source_time_zone</td>
+            	<td>interval</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>time zone of location, used to approximate source time
+	 zone for all timestamps in this encounter
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>reason_for_encounter</td>
             	<td>text</td>
                 <td><i>
 				
@@ -42628,8 +56671,28 @@ END;</pre>
 				
 				
 				</i>
-				<br><br>additional short comment such as "abdominal", "ward 3,
-	 Dr. Stein", etc.
+				<br><br>the RFE for the encounter as related by either
+	 the patient or the provider (say, in a chart
+	 review)
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>assessment_of_encounter</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>the Assessment of Encounter (eg consultation summary)
+	 as determined by the provider, may simply be a
+	 concatenation of soAp narrative, this assessment
+	 should go across all problems
 				</td>
 			 </tr>
             
@@ -42637,7 +56700,7 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
+            	<td>started</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
@@ -42645,26 +56708,256 @@ END;</pre>
 				NOT NULL
 				DEFAULT now()
 				</i>
-				<br><br>date of document content creation (such as exam date),
-	 NOT date of document creation or date of import; may
-	 be imprecise such as "7/99"
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>last_affirmed</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				
 				</td>
 			 </tr>
             
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table clin.encounter Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.encounter Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>clin_enc_sane_duration</td>
+                <td>CHECK ((last_affirmed >= started))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>encounter_assessment_of_encounter_check</td>
+                <td>CHECK ((btrim(COALESCE(assessment_of_encounter, 'xxxDEFAULTxxx'::text)) <> ''::text))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>encounter_reason_for_encounter_check</td>
+                <td>CHECK ((btrim(COALESCE(reason_for_encounter, 'xxxDEFAULTxxx'::text)) <> ''::text))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#au.table.referral">au.referral</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#bill.table.bill-item">bill.bill_item</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#blobs.table.doc-med">blobs.doc_med</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.allergy">clin.allergy</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.allergy-state">clin.allergy_state</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.clin-aux-note">clin.clin_aux_note</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.clin-narrative">clin.clin_narrative</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin.clin_root_item</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.episode">clin.episode</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.external-care">clin.external_care</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.family-history">clin.family_history</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.form-instances">clin.form_instances</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.health-issue">clin.health_issue</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.hospital-stay">clin.hospital_stay</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lab-request">clin.lab_request</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2aoe">clin.lnk_code2aoe</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2rfe">clin.lnk_code2rfe</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.procedure">clin.procedure</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.substance-intake">clin.substance_intake</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.suppressed-hint">clin.suppressed_hint</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.test-result">clin.test_result</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.vaccination">clin.vaccination</a></li>
+			</ul>
+		
+		
+
+    <!-- Indexes -->
+    
+       idx_clin_encounter_fk_location fk_location
+    
+       idx_encounter_affirmed last_affirmed
+    
+       idx_encounter_modified_by modified_by
+    
+       idx_encounter_started started
+    
+       idx_pat_per_encounter fk_patient
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.encounter-type">encounter_type</a>
+		</h2>
+        
+         <p>these are the types of encounter</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.encounter_type Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
             <tr class="tr0">
 				<td>
                 
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                
                 </td>
-            	<td>ext_ref</td>
+            	<td>description</td>
             	<td>text</td>
                 <td><i>
 				
+					
 
+					
+                       UNIQUE
+                    
 				
+
+				NOT NULL
 				
 				</i>
-				<br><br>external reference string of physical document,
-	 original paper copy can be found with this
+				
 				</td>
 			 </tr>
             
@@ -42672,13 +56965,6 @@ END;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table blobs.doc_med Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
 
 		
 		
@@ -42692,23 +56978,11 @@ END;</pre>
 			<p>Tables referencing this one via Foreign Key Constraints:</p>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#bill.table.bill">bill.bill</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#blobs.table.doc-desc">blobs.doc_desc</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#blobs.table.doc-obj">blobs.doc_obj</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#blobs.table.lnk-doc2hospital-stay">blobs.lnk_doc2hospital_stay</a></li>
+				<li><a href="gnumed-entire_schema.html#bill.table.lnk-enc-type2billable">bill.lnk_enc_type2billable</a></li>
 			</ul>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#blobs.table.lnk-doc-med2episode">blobs.lnk_doc_med2episode</a></li>
+				<li><a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter</a></li>
 			</ul>
 		
 		
@@ -42724,22 +56998,25 @@ END;</pre>
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.table.doc-obj">doc_obj</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.episode">episode</a>
 		</h2>
         
-         <p>possibly several of these form a medical document
-	 such as multiple scanned pages/images</p>
+         <p>Clinical episodes such as "Otitis media",
+	 "traffic accident 7/99", "Hepatitis B".
+	 This covers a range of time in which
+	 activity of illness was noted for the
+	 problem episode.description.</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>blobs.doc_obj Structure</caption>
+                <caption>clin.episode Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -42750,6 +57027,78 @@ END;</pre>
             <tr class="tr0">
 				<td>
                 
+                </td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				DEFAULT "current_user"()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
                   
                 
                 </td>
@@ -42774,11 +57123,11 @@ END;</pre>
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#blobs.table.doc-med">blobs.doc_med.pk</a>
+                  <a href="gnumed-entire_schema.html#clin.table.health-issue">clin.health_issue.pk</a>
                   
                 
                 </td>
-            	<td>fk_doc</td>
+            	<td>fk_health_issue</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -42787,10 +57136,10 @@ END;</pre>
 					
 				
 
-				NOT NULL
 				
-				</i>
 				
+				</i>
+				<br><br>health issue this episode belongs to
 				</td>
 			 </tr>
             
@@ -42798,16 +57147,15 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>seq_idx</td>
-            	<td>integer</td>
+            	<td>description</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
-				<br><br>index of this object in the sequence
-	 of objects for this document
+				<br><br>description/name of this episode
 				</td>
 			 </tr>
             
@@ -42815,16 +57163,17 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>is_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
 				
-				
+				DEFAULT true
 				</i>
-				<br><br>optional tiny comment for this
-	 object, such as "page 1"
+				<br><br>whether the episode is open (eg. there is activity for it),
+	 means open in a temporal sense as in "not closed yet";
+	 only one episode can be open per health issue
 				</td>
 			 </tr>
             
@@ -42832,11 +57181,11 @@ END;</pre>
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.pk</a>
+                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
                   
                 
                 </td>
-            	<td>fk_intended_reviewer</td>
+            	<td>fk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -42848,7 +57197,7 @@ END;</pre>
 				NOT NULL
 				
 				</i>
-				<br><br>who is *supposed* to review this item
+				<br><br>The encounter during which this episode was added (begun).
 				</td>
 			 </tr>
             
@@ -42856,67 +57205,19 @@ END;</pre>
 				<td>
                 
                 </td>
-            	<td>data</td>
-            	<td>bytea</td>
+            	<td>diagnostic_certainty_classification</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>actual binary object data;
-
-	 here is why we use bytea:
-
-== --------------------------------------------------
-
-To: leon at oss.minimetria.com
-
-Cc: pgsql-sql at postgresql.org
-
-Subject: Re: [SQL] Recommendation on bytea or blob for binary data like images 
-
-Date: Fri, 02 Sep 2005 16:33:09 -0400
-
-Message-ID: <17794.1125693189 at sss.pgh.pa.us>
-
-From: Tom Lane <tgl at sss.pgh.pa.us>
-
-List-Archive: <http://archives.postgresql.org/pgsql-sql>
-
-List-Help: <mailto:majordomo at postgresql.org?body=help>
-
-List-ID: <pgsql-sql.postgresql.org>
-
-
-
-leon at oss.minimetria.com writes:
-
-> Hi, I"d like to know what the official recommendation is on which binary
-
-> datatype to use for common small-binary size use.
-
-
-
-If bytea will work for you, it"s definitely the thing to use.  The only
-
-real drawback to bytea is that there"s currently no API to read and
-
-write bytea values in a streaming fashion.  If your objects are small
-
-enough that you can load and store them as units, bytea is fine.
-
-
-
-BLOBs, on the other hand, have a number of drawbacks --- hard to dump,
-
-impossible to secure, etc.
-
-
-
-			regards, tom lane
-
-== --------------------------------------------------
+				<br><br>The certainty at which this problem is believed to be a diagnosis:
+A: sign (Symptom)
+B: cluster of signs (Symptomkomplex)
+C: syndromic diagnosis (Bild einer Diagnose)
+D: proven diagnosis (diagnostisch gesichert)
 				</td>
 			 </tr>
             
@@ -42924,7 +57225,7 @@ impossible to secure, etc.
 				<td>
                 
                 </td>
-            	<td>filename</td>
+            	<td>summary</td>
             	<td>text</td>
                 <td><i>
 				
@@ -42932,9 +57233,7 @@ impossible to secure, etc.
 				
 				
 				</i>
-				<br><br>the filename from when the data was imported - if any, can be NULL,
-	 useful for re-export since legacy devices/applications might expect
-	 particular file names and not use mime types for file detection
+				<br><br>Used for tracking the summary of this episode.
 				</td>
 			 </tr>
             
@@ -42942,6 +57241,13 @@ impossible to secure, etc.
 
         <!-- Inherits -->
 		
+        <p>Table clin.episode Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
 
 		
 		
@@ -42951,15 +57257,30 @@ impossible to secure, etc.
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>blobs.doc_obj Constraints</caption>
+            <caption>clin.episode Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
-				<td>doc_obj_filename_check</td>
-                <td>CHECK ((btrim(COALESCE(filename, 'NULL'::text)) <> ''::text))</td>
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>episode_sane_summary</td>
+                <td>CHECK (gm.is_null_or_non_empty_string(summary))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>sane_description</td>
+                <td>CHECK ((gm.is_null_or_blank_string(description) IS FALSE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>valid_diagnostic_certainty_classification</td>
+                <td>CHECK ((diagnostic_certainty_classification = ANY (ARRAY['A'::text, 'B'::text, 'C'::text, 'D'::text, NULL::text])))</td>
             </tr>
 			
 		</table>
@@ -42970,17 +57291,87 @@ impossible to secure, etc.
 			<p>Tables referencing this one via Foreign Key Constraints:</p>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#blobs.table.reviewed-doc-objs">blobs.reviewed_doc_objs</a></li>
+				<li><a href="gnumed-entire_schema.html#au.table.referral">au.referral</a></li>
 			</ul>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.export-item">clin.export_item</a></li>
+				<li><a href="gnumed-entire_schema.html#blobs.table.doc-med">blobs.doc_med</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#blobs.table.lnk-doc-med2episode">blobs.lnk_doc_med2episode</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.allergy">clin.allergy</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.clin-aux-note">clin.clin_aux_note</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.clin-narrative">clin.clin_narrative</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin.clin_root_item</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.family-history">clin.family_history</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.form-instances">clin.form_instances</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.hospital-stay">clin.hospital_stay</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lab-request">clin.lab_request</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2episode">clin.lnk_code2episode</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-substance2episode">clin.lnk_substance2episode</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.procedure">clin.procedure</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.substance-intake">clin.substance_intake</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.test-result">clin.test_result</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.vaccination">clin.vaccination</a></li>
 			</ul>
 		
 		
 
     <!-- Indexes -->
     
+       idx_episode_fk_encounter fk_encounter
+    
+       idx_episode_issue fk_health_issue
+    
+       idx_episode_modified_by modified_by
+    
+       idx_episode_with_issue fk_health_issue) WHERE (fk_health_issue IS NOT NULL
+    
+       idx_episode_without_issue fk_health_issue) WHERE (fk_health_issue IS NULL
+    
 
 	<!-- View Definition -->
 	
@@ -42990,21 +57381,21 @@ impossible to secure, etc.
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.table.doc-type">doc_type</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.export-item">export_item</a>
 		</h2>
         
-         <p>this table enumerates the document types known to the system</p>
+         <p>A table to hold binary data for patients intended for export as print/mail/fax/removable media/...</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>blobs.doc_type Structure</caption>
+                <caption>clin.export_item Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -43040,93 +57431,46 @@ impossible to secure, etc.
                 
                   
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.patient">clin.patient.fk_identity</a>
+                  
+                
                 </td>
-            	<td>name</td>
-            	<td>text</td>
+            	<td>fk_identity</td>
+            	<td>integer</td>
                 <td><i>
 				
 					
 
 					
-                       UNIQUE
+                       UNIQUE#1
                     
 				
+					
 
-				NOT NULL
+					
+				
+
+				
 				
 				</i>
-				<br><br>the name/label of the document type
+				<br><br>the patient this item pertains to, DELETE does not cascade because we may have wanted to export data before deleting a patient ...
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#blobs.table.doc-med">blobs.doc_med</a></li>
-			</ul>
-		
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.table.lnk-doc2hospital-stay">lnk_doc2hospital_stay</a>
-		</h2>
-        
-         <p>links documents to any hospital stay they might pertain to</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>blobs.lnk_doc2hospital_stay Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
+            	<td>created_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
 				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				DEFAULT "current_user"()
 				</i>
-				
+				<br><br>who put this item here
 				</td>
 			 </tr>
             
@@ -43134,15 +57478,15 @@ impossible to secure, etc.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>created_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
 				NOT NULL
-				
+				DEFAULT statement_timestamp()
 				</i>
-				
+				<br><br>when was this item put here
 				</td>
 			 </tr>
             
@@ -43150,31 +57494,39 @@ impossible to secure, etc.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>designation</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
-				</i>
 				
+				
+				</i>
+				<br><br>the intended use for this item if any, say "print" for printing
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>description</td>
+            	<td>text</td>
                 <td><i>
 				
+					
 
-				NOT NULL
-				DEFAULT "current_user"()
-				</i>
+					
+                       UNIQUE#1
+                    
 				
+
+				
+				
+				</i>
+				<br><br>a unique-per-patient description of the item
 				</td>
 			 </tr>
             
@@ -43183,77 +57535,62 @@ impossible to secure, etc.
                 
                   
                 
+                  
+                  <a href="gnumed-entire_schema.html#blobs.table.doc-obj">blobs.doc_obj.pk</a>
+                  
+                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>fk_doc_obj</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
 					
 
 					
+                       UNIQUE
+                    
 				
+					
 
+					
 				
+
 				
-				</i>
 				
+				</i>
+				<br><br>points to a document object
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.hospital-stay">clin.hospital_stay.pk</a>
-                  
-                
                 </td>
-            	<td>fk_stay</td>
-            	<td>integer</td>
+            	<td>data</td>
+            	<td>bytea</td>
                 <td><i>
 				
-					
 
-					
 				
-
-				NOT NULL
 				
 				</i>
-				
+				<br><br>binary data representing the actual export item (unless fk_doc_obj points to a document object)
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#blobs.table.doc-med">blobs.doc_med.pk</a>
-                  
-                
-                  
-                
                 </td>
-            	<td>fk_document</td>
-            	<td>integer</td>
+            	<td>filename</td>
+            	<td>text</td>
                 <td><i>
 				
-					
-
-					
-				
-					
 
-					
-                       UNIQUE
-                    
 				
-
-				NOT NULL
 				
 				</i>
-				
+				<br><br>a filename, possibly from an import, if applicable, mainly used to please non-mime pseudo operating systems
 				</td>
 			 </tr>
             
@@ -43261,13 +57598,6 @@ impossible to secure, etc.
 
         <!-- Inherits -->
 		
-        <p>Table blobs.lnk_doc2hospital_stay Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
 
 		
 		
@@ -43275,6 +57605,56 @@ impossible to secure, etc.
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.export_item Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>clin_export_item_fk_obj_or_data</td>
+                <td>CHECK ((((data IS NULL) AND (fk_doc_obj IS NOT NULL)) OR ((data IS NOT NULL) AND (fk_doc_obj IS NULL))))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>clin_export_item_fk_obj_or_filename</td>
+                <td>CHECK ((((filename IS NULL) AND (fk_doc_obj IS NOT NULL)) OR ((filename IS NOT NULL) AND (fk_doc_obj IS NULL))))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>clin_export_item_fk_obj_or_fk_identity</td>
+                <td>CHECK ((((fk_identity IS NULL) AND (fk_doc_obj IS NOT NULL)) OR ((fk_identity IS NOT NULL) AND (fk_doc_obj IS NULL))))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>clin_export_item_sane_by</td>
+                <td>CHECK ((length((created_by)::text) > 0))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>clin_export_item_sane_data</td>
+                <td>CHECK (((data IS NULL) OR (length(data) > 0)))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>clin_export_item_sane_description</td>
+                <td>CHECK ((gm.is_null_or_blank_string(description) IS FALSE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>clin_export_item_sane_designation</td>
+                <td>CHECK ((gm.is_null_or_non_empty_string(designation) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>clin_export_item_sane_filename</td>
+                <td>CHECK ((gm.is_null_or_non_empty_string(filename) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
@@ -43290,23 +57670,21 @@ impossible to secure, etc.
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.table.lnk-doc-med2episode">lnk_doc_med2episode</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.external-care">external_care</a>
 		</h2>
         
-         <p>this allows linking documents to episodes,
-	 each document can apply to several episodes
-	 but only once each</p>
+         <p>lists external care situations for patients</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>blobs.lnk_doc_med2episode Structure</caption>
+                <caption>clin.external_care Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -43365,11 +57743,19 @@ impossible to secure, etc.
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -43405,13 +57791,11 @@ impossible to secure, etc.
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
-                  
-                
+                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
                   
                 
                 </td>
-            	<td>fk_episode</td>
+            	<td>fk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -43419,17 +57803,59 @@ impossible to secure, etc.
 
 					
 				
+
+				NOT NULL
+				
+				</i>
+				<br><br>the encounter during which this external care item was first documented
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.health-issue">clin.health_issue.pk</a>
+                  
+                
+                </td>
+            	<td>fk_health_issue</td>
+            	<td>integer</td>
+                <td><i>
+				
 					
 
 					
                        UNIQUE#1
                     
 				
+					
 
-				NOT NULL
+					
+				
+
+				
 				
 				</i>
+				<br><br>link to a health issue, if any
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>issue</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
 				
+				</i>
+				<br><br>description of the issue of external care
 				</td>
 			 </tr>
             
@@ -43437,31 +57863,63 @@ impossible to secure, etc.
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#blobs.table.doc-med">blobs.doc_med.pk</a>
-                  
                 
                   
+                  <a href="gnumed-entire_schema.html#dem.table.org-unit">dem.org_unit.pk</a>
+                  
                 
                 </td>
-            	<td>fk_doc_med</td>
+            	<td>fk_org_unit</td>
             	<td>integer</td>
                 <td><i>
 				
 					
 
 					
+                       UNIQUE#1
+                    
 				
 					
 
 					
-                       UNIQUE#1
-                    
 				
 
 				NOT NULL
 				
 				</i>
+				<br><br>link to the org unit where care is rendered
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>provider</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>name of actual provider at .fk_org_unit
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>comment</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
 				
+				</i>
+				<br><br>comment on the patient/provider relationship, say role/issues cared for/...
 				</td>
 			 </tr>
             
@@ -43469,7 +57927,7 @@ impossible to secure, etc.
 
         <!-- Inherits -->
 		
-        <p>Table blobs.lnk_doc_med2episode Inherits
+        <p>Table clin.external_care Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
@@ -43483,12 +57941,53 @@ impossible to secure, etc.
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.external_care Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>clin_ext_care_issue_xor_fk_issue</td>
+                <td>CHECK ((((fk_health_issue IS NULL) AND (issue IS NOT NULL)) OR ((fk_health_issue IS NOT NULL) AND (issue IS NULL))))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>clin_ext_care_sane_comment</td>
+                <td>CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>clin_ext_care_sane_issue</td>
+                <td>CHECK ((gm.is_null_or_non_empty_string(issue) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>clin_ext_care_sane_provider</td>
+                <td>CHECK ((gm.is_null_or_non_empty_string(provider) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
 
     <!-- Indexes -->
     
+       idx_external_care_fk_encounter fk_encounter
+    
+       idx_external_care_fk_health_issue fk_health_issue
+    
+       idx_external_care_fk_org_unit fk_org_unit
+    
 
 	<!-- View Definition -->
 	
@@ -43498,21 +57997,21 @@ impossible to secure, etc.
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.table.reviewed-doc-objs">reviewed_doc_objs</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.family-history">family_history</a>
 		</h2>
         
-         <p>review table for documents (per object such as a page)</p>
+         <p>This table stores family history items on persons not otherwise in the database.</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>blobs.reviewed_doc_objs Structure</caption>
+                <caption>clin.family_history Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -43571,11 +58070,19 @@ impossible to secure, etc.
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -43587,21 +58094,14 @@ impossible to secure, etc.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
+            	<td>pk_item</td>
             	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
-				
-				DEFAULT nextval('clin.review_root_pk_seq'::regclass)
+				NOT NULL
+				DEFAULT nextval('clin_root_item_pk_item_seq'::regclass)
 				</i>
 				
 				</td>
@@ -43610,32 +58110,16 @@ impossible to secure, etc.
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#blobs.table.doc-obj">blobs.doc_obj.pk</a>
-                  
-                
-                  
-                
                 </td>
-            	<td>fk_reviewed_row</td>
-            	<td>integer</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
-					
-
-					
-				
-					
-
-					
-                       UNIQUE#1
-                    
-				
 
 				NOT NULL
-				
+				DEFAULT now()
 				</i>
-				
+				<br><br>When the family history item became known to the patient (not the afflicted relative).
 				</td>
 			 </tr>
             
@@ -43643,39 +58127,47 @@ impossible to secure, etc.
 				<td>
                 
                   
+                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  
                 
                 </td>
-            	<td>fk_reviewer</td>
+            	<td>fk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
 					
 
 					
-                       UNIQUE#1
-                    
 				
 
 				NOT NULL
 				
 				</i>
-				
+				<br><br>encounter during which family history item became known
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
+                  
+                
                 </td>
-            	<td>is_technically_abnormal</td>
-            	<td>boolean</td>
+            	<td>fk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				
 				</i>
-				
+				<br><br>episode to which family history item is of importance
 				</td>
 			 </tr>
             
@@ -43683,15 +58175,15 @@ impossible to secure, etc.
 				<td>
                 
                 </td>
-            	<td>clinically_relevant</td>
-            	<td>boolean</td>
+            	<td>narrative</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
 				
-				</i>
 				
+				</i>
+				<br><br>the condition this relative suffered from
 				</td>
 			 </tr>
             
@@ -43699,7 +58191,7 @@ impossible to secure, etc.
 				<td>
                 
                 </td>
-            	<td>comment</td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -43711,69 +58203,21 @@ impossible to secure, etc.
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table blobs.reviewed_doc_objs Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#clin.table.review-root">review_root</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-doc-desc">v_doc_desc</a>
-		</h2>
-        
-         <p>aggregates some document data descriptions</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>blobs.v_doc_desc Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
+
+					
+				
 
 				
 				
@@ -43785,16 +58229,24 @@ impossible to secure, etc.
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.fhx-relation-type">clin.fhx_relation_type.pk</a>
+                  
+                
                 </td>
-            	<td>pk_doc</td>
+            	<td>fk_relation_type</td>
             	<td>integer</td>
                 <td><i>
 				
+					
 
+					
 				
+
+				NOT NULL
 				
 				</i>
-				
+				<br><br>foreign key to the type of relation the patient has to the afflicated relative
 				</td>
 			 </tr>
             
@@ -43802,7 +58254,7 @@ impossible to secure, etc.
 				<td>
                 
                 </td>
-            	<td>description</td>
+            	<td>age_noted</td>
             	<td>text</td>
                 <td><i>
 				
@@ -43810,7 +58262,7 @@ impossible to secure, etc.
 				
 				
 				</i>
-				
+				<br><br>age at which the condition was noted in the relative if known
 				</td>
 			 </tr>
             
@@ -43818,15 +58270,15 @@ impossible to secure, etc.
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>age_of_death</td>
+            	<td>interval</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>age at which the relative died if known
 				</td>
 			 </tr>
             
@@ -43834,15 +58286,15 @@ impossible to secure, etc.
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>contributed_to_death</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>whether the condition contributed to the death of the relative if known
 				</td>
 			 </tr>
             
@@ -43850,15 +58302,15 @@ impossible to secure, etc.
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
-            	<td>integer</td>
+            	<td>name_relative</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>name of the relative suffering the condition
 				</td>
 			 </tr>
             
@@ -43866,8 +58318,24 @@ impossible to secure, etc.
 				<td>
                 
                 </td>
-            	<td>pk_doc_desc</td>
-            	<td>integer</td>
+            	<td>dob_relative</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>date of birth of the relative if known
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -43882,51 +58350,101 @@ impossible to secure, etc.
 
         <!-- Inherits -->
 		
+        <p>Table clin.family_history Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin_root_item</a>, 
+        
+        </p>
+		
 
 		
+		
+		
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.family_history Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>c_family_history_sane_age_noted</td>
+                <td>CHECK ((gm.is_null_or_non_empty_string(age_noted) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>c_family_history_sane_condition</td>
+                <td>CHECK ((gm.is_null_or_blank_string(narrative) IS FALSE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>c_family_history_sane_name</td>
+                <td>CHECK ((gm.is_null_or_non_empty_string(name_relative) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>clin_root_item_sane_soap_cat</td>
+                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>narrative_neither_null_nor_empty</td>
+                <td>CHECK ((btrim(COALESCE(narrative, ''::text)) <> ''::text))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2fhx">clin.lnk_code2fhx</a></li>
+			</ul>
+		
+		
 
     <!-- Indexes -->
     
+       idx_clin_family_history_fk_encounter fk_encounter
+    
+       idx_clin_family_history_fk_episode fk_episode
+    
 
 	<!-- View Definition -->
 	
-	<pre>
-SELECT vdm.pk_patient
-, dd.fk_doc AS pk_doc
-, dd.text AS description
-, vdm.pk_encounter
-, vdm.pk_episode
-, vdm.pk_health_issue
-, dd.pk AS pk_doc_desc 
-FROM blobs.doc_desc dd
-, blobs.v_doc_med vdm 
-WHERE (dd.fk_doc = vdm.pk_doc);</pre>
-	
 
 	<!-- List off permissions -->
 	
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
-		<h2>View:
+		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-doc-med">v_doc_med</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.fhx-relation-type">fhx_relation_type</a>
 		</h2>
         
+         <p>Enumerates inter-person relations for family history linking.</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>blobs.v_doc_med Structure</caption>
+                <caption>clin.fhx_relation_type Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -43938,45 +58456,13 @@ WHERE (dd.fk_doc = vdm.pk_doc);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>pk_doc</td>
+            	<td>pk_audit</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -43986,12 +58472,12 @@ WHERE (dd.fk_doc = vdm.pk_doc);</pre>
 				<td>
                 
                 </td>
-            	<td>type</td>
-            	<td>text</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -44002,13 +58488,13 @@ WHERE (dd.fk_doc = vdm.pk_doc);</pre>
 				<td>
                 
                 </td>
-            	<td>l10n_type</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -44017,14 +58503,22 @@ WHERE (dd.fk_doc = vdm.pk_doc);</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
-            	<td>ext_ref</td>
-            	<td>text</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
+					
 
+					
 				
-				
+
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -44033,11 +58527,18 @@ WHERE (dd.fk_doc = vdm.pk_doc);</pre>
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>episode</td>
-            	<td>text</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
+
+					
+				
 
 				
 				
@@ -44049,107 +58550,221 @@ WHERE (dd.fk_doc = vdm.pk_doc);</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>comment</td>
+            	<td>description</td>
             	<td>text</td>
                 <td><i>
 				
+					
 
+					
+                       UNIQUE#1
+                    
 				
+
 				
-				</i>
 				
+				</i>
+				<br><br>Description of the relation type, specific or unspecific: sister, father, ..., maternal family, ...
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>episode_open</td>
+            	<td>is_genetic</td>
             	<td>boolean</td>
                 <td><i>
 				
+					
 
+					
+                       UNIQUE#1
+                    
 				
+
+				NOT NULL
 				
 				</i>
-				
+				<br><br>Whether or not this type of relation is biologic/genetic or not. Note that non-genetic relations may still pose a risk because of infectious diseases.
 				</td>
 			 </tr>
             
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table clin.fhx_relation_type Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.fhx_relation_type Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
             <tr class="tr1">
+				<td>c_fhx_relation_type_sane_desc</td>
+                <td>CHECK ((gm.is_null_or_blank_string(description) IS FALSE))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.family-history">clin.family_history</a></li>
+			</ul>
+		
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.form-data">form_data</a>
+		</h2>
+        
+         <p>holds the values used in form instances, for
+	 later re-use/validation</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.form_data Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_type</td>
+            	<td>pk_audit</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
+            	<td>row_version</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
-            	<td>pk_health_issue</td>
-            	<td>integer</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
+					
 
+					
 				
-				
+
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
+
+					
+				
 
 				
 				
@@ -44158,51 +58773,85 @@ WHERE (dd.fk_doc = vdm.pk_doc);</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.form-instances">clin.form_instances.pk</a>
+                  
+                
+                  
+                
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>fk_instance</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
+
+					
+				
+					
 
+					
+                       UNIQUE#1
+                    
 				
+
+				NOT NULL
 				
 				</i>
-				
+				<br><br>the form instance this value was used in
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#public.table.form-fields">public.form_fields.pk</a>
+                  
+                
+                  
+                
                 </td>
-            	<td>xmin_doc_med</td>
-            	<td>xid</td>
+            	<td>fk_form_field</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
+
+					
+				
+					
 
+					
+                       UNIQUE#1
+                    
 				
+
+				NOT NULL
 				
 				</i>
-				
+				<br><br>points to the definition of the field in the form
+	 which in turn defines the place holder in the
+	 template to replace with <value>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>health_issue</td>
+            	<td>value</td>
             	<td>text</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>the value to replace the place holder with
 				</td>
 			 </tr>
             
@@ -44210,11 +58859,35 @@ WHERE (dd.fk_doc = vdm.pk_doc);</pre>
 
         <!-- Inherits -->
 		
+        <p>Table clin.form_data Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
 
 		
+		
+		
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.form_data Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
@@ -44224,61 +58897,27 @@ WHERE (dd.fk_doc = vdm.pk_doc);</pre>
 
 	<!-- View Definition -->
 	
-	<pre>
-SELECT (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
- WHERE (encounter.pk = dm.fk_encounter)
-) AS pk_patient
-, dm.pk AS pk_doc
-, dm.clin_when
-, dt.name AS type
-, _
-(dt.name) AS l10n_type
-, dm.ext_ref
-, cle.description AS episode
-, dm.comment
-, cle.is_open AS episode_open
-, dm.fk_type AS pk_type
-, dm.fk_encounter AS pk_encounter
-, dm.fk_episode AS pk_episode
-, cle.fk_health_issue AS pk_health_issue
-, dm.modified_when
-, dm.modified_by
-, dm.xmin AS xmin_doc_med
-, chi.description AS health_issue 
-FROM blobs.doc_med dm
-, blobs.doc_type dt
-, (clin.episode cle 
-LEFT JOIN clin.health_issue chi 
-    ON (
-           (chi.pk = cle.fk_health_issue)
-     )
-)
-WHERE (
-     (dt.pk = dm.fk_type)
-   AND (cle.pk = dm.fk_episode)
-);</pre>
-	
 
 	<!-- List off permissions -->
 	
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
-		<h2>View:
+		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-doc-med-journal">v_doc_med_journal</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.form-instances">form_instances</a>
 		</h2>
         
+         <p>instances of forms, like a log of all processed forms</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>blobs.v_doc_med_journal Structure</caption>
+                <caption>clin.form_instances Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -44290,13 +58929,13 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
+            	<td>pk_audit</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -44306,12 +58945,12 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -44322,13 +58961,13 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
+            	<td>modified_when</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -44337,46 +58976,22 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
-                </td>
-            	<td>modified_by</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
                 
                 </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
+					
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>narrative</td>
-            	<td>text</td>
-                <td><i>
+					
 				
 
-				
-				
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -44386,13 +59001,13 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
+            	<td>pk_item</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('clin_root_item_pk_item_seq'::regclass)
 				</i>
 				
 				</td>
@@ -44402,13 +59017,13 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -44417,13 +59032,21 @@ WHERE (
             <tr class="tr0">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  
+                
                 </td>
-            	<td>pk_health_issue</td>
+            	<td>fk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
+					
 
+					
 				
+
+				NOT NULL
 				
 				</i>
 				
@@ -44433,157 +59056,40 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
+                  
+                
                 </td>
-            	<td>src_pk</td>
+            	<td>fk_episode</td>
             	<td>integer</td>
                 <td><i>
 				
+					
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>src_table</td>
-            	<td>text</td>
-                <td><i>
+					
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
- WHERE (encounter.pk = dm.fk_encounter)
-) AS pk_patient
-, dm.modified_when
-, dm.clin_when
-, COALESCE
-(
-     (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.db_user = dm.modified_by)
-     )
-     , (
-           ('<'::text || 
-                 (dm.modified_by)::text
-           ) || '>'::text
-     )
-) AS modified_by
-, NULL::text AS soap_cat
-, (
-     (
-           (
-                 (
-                       (
-                             (_
-                                   ('Document'::text) || ': '::text
-                             ) || _
-                             (dt.name)
-                       ) || COALESCE
-                       (
-                             (
-                                   (' "'::text || dm.ext_ref) || 
-                               '" ('::text)
-                                   , ' ('::text)
-                             ) || to_char
-                             (dm.clin_when
-                                   ,'YYYY-MM-DD HH24:MI'::text
-                             )
-                       ) || 
-               ')'::text
-           ) || COALESCE
-           (
-                 ('
- '::text || dm.comment)
-                 ,''::text
-           )
-     ) AS narrative
-     , dm.fk_encounter AS pk_encounter
-     , dm.fk_episode AS pk_episode
-     , (
-      SELECT episode.fk_health_issue 
-        FROM clin.episode 
-       WHERE (episode.pk = dm.fk_episode)
-     ) AS pk_health_issue
-     , dm.pk AS src_pk
-     ,'blobs.doc_med'::text AS src_table 
-  FROM blobs.doc_med dm
-     , blobs.doc_type dt 
- WHERE (dt.pk = dm.fk_type);</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-doc-type">v_doc_type</a>
-		</h2>
-        
-         <p>list active document types, those that are activated for use</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>blobs.v_doc_type Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_doc_type</td>
-            	<td>integer</td>
+            	<td>narrative</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>can be used as a status field, eg. "printed", "faxed" etc.
 				</td>
 			 </tr>
             
@@ -44591,7 +59097,7 @@ SELECT encounter.fk_patient
 				<td>
                 
                 </td>
-            	<td>type</td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -44606,26 +59112,17 @@ SELECT encounter.fk_patient
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>l10n_type</td>
-            	<td>text</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>is_user_defined</td>
-            	<td>boolean</td>
-                <td><i>
+					
 				
 
 				
@@ -44635,35 +59132,46 @@ SELECT encounter.fk_patient
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#ref.table.paperwork-templates">ref.paperwork_templates.pk</a>
+                  
+                
                 </td>
-            	<td>is_in_use</td>
-            	<td>boolean</td>
+            	<td>fk_form_def</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
 
+					
 				
+
+				NOT NULL
 				
 				</i>
-				
+				<br><br>points to the definition of this instance,
+	 this FK will fail once we start separating services,
+	 make it into a x_db_fk then
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>xmin_doc_type</td>
-            	<td>xid</td>
+            	<td>form_name</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>a string uniquely identifying the form template,
+	 necessary for the audit trail
 				</td>
 			 </tr>
             
@@ -44671,66 +59179,98 @@ SELECT encounter.fk_patient
 
         <!-- Inherits -->
 		
+        <p>Table clin.form_instances Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin_root_item</a>, 
+        
+        </p>
+		
 
 		
+		
+		
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.form_instances Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>clin_root_item_sane_soap_cat</td>
+                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>form_is_plan</td>
+                <td>CHECK ((soap_cat = 'p'::text))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#au.table.referral">au.referral</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.form-data">clin.form_data</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#public.table.form-job-queue">public.form_job_queue</a></li>
+			</ul>
+		
+		
 
     <!-- Indexes -->
     
+       idx_clin_form_instances_fk_encounter fk_encounter
+    
+       idx_clin_form_instances_fk_episode fk_episode
+    
 
 	<!-- View Definition -->
 	
-	<pre>
-SELECT dt.pk AS pk_doc_type
-, dt.name AS type
-, _
-(dt.name) AS l10n_type
-, (NOT 
-     (EXISTS 
-           (
-            SELECT 1 
-              FROM ref.document_type 
-             WHERE (document_type.description = dt.name)
-           )
-     )
-) AS is_user_defined
-, (EXISTS 
-     (
-      SELECT 1 
-        FROM blobs.doc_med 
-       WHERE (doc_med.fk_type = dt.pk)
-     )
-) AS is_in_use
-, dt.xmin AS xmin_doc_type 
-FROM blobs.doc_type dt;</pre>
-	
 
 	<!-- List off permissions -->
 	
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
-		<h2>View:
+		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-latest-mugshot">v_latest_mugshot</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.health-issue">health_issue</a>
 		</h2>
         
-         <p>shows the latest picture of the patient, currently the highest
-	 seq_idx of the newest document of type "patient photograph"</p>
+         <p>This is pretty much what others would call "Past Medical History"
+	 or "Foundational illness", eg. longer-ranging, underlying,
+	 encompassing issues with one's health such as "immunodeficiency",
+	 "type 2 diabetes". In Belgium it is called "problem".
+	 L.L.Weed includes lots of little things into it, we do not.</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>blobs.v_latest_mugshot Structure</caption>
+                <caption>clin.health_issue Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -44742,13 +59282,13 @@ FROM blobs.doc_type dt;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
+            	<td>pk_audit</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -44758,12 +59298,12 @@ FROM blobs.doc_type dt;</pre>
 				<td>
                 
                 </td>
-            	<td>doc_comment</td>
-            	<td>text</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -44774,13 +59314,13 @@ FROM blobs.doc_type dt;</pre>
 				<td>
                 
                 </td>
-            	<td>date_taken</td>
+            	<td>modified_when</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -44789,14 +59329,22 @@ FROM blobs.doc_type dt;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
-            	<td>ext_ref</td>
-            	<td>text</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
+					
 
+					
 				
-				
+
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -44805,11 +59353,18 @@ FROM blobs.doc_type dt;</pre>
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>obj_seq_idx</td>
-            	<td>integer</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
+
+					
+				
 
 				
 				
@@ -44822,15 +59377,16 @@ FROM blobs.doc_type dt;</pre>
 				<td>
                 
                 </td>
-            	<td>obj_comment</td>
+            	<td>description</td>
             	<td>text</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>descriptive name of this health issue, may
+	 change over time as evidence increases
 				</td>
 			 </tr>
             
@@ -44838,15 +59394,19 @@ FROM blobs.doc_type dt;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_doc</td>
-            	<td>integer</td>
+            	<td>laterality</td>
+            	<td>character varying(2)</td>
                 <td><i>
 				
 
 				
-				
+				DEFAULT NULL::character varying
 				</i>
-				
+				<br><br>NULL: don't know
+	 s: sinister - left
+	 d: dexter - right
+	 sd: sinister and dexter - both sides
+	 na: not applicable
 				</td>
 			 </tr>
             
@@ -44854,125 +59414,31 @@ FROM blobs.doc_type dt;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_obj</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>image</td>
-            	<td>bytea</td>
+            	<td>age_noted</td>
+            	<td>interval</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>at what age the patient acquired the condition
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT vo4d.pk_patient
-, vo4d.doc_comment
-, vo4d.date_generated AS date_taken
-, vo4d.ext_ref
-, vo4d.seq_idx AS obj_seq_idx
-, vo4d.obj_comment
-, vo4d.pk_doc
-, vo4d.pk_obj
-, bdo.data AS image 
-FROM blobs.v_obj4doc_no_data vo4d
-, blobs.doc_obj bdo 
-WHERE (
-     (
-           (vo4d.type = 'patient photograph'::text)
-         AND (vo4d.seq_idx = 
-                 (
-                  SELECT max
-                       (vo4d1.seq_idx) AS max 
-                    FROM blobs.v_obj4doc_no_data vo4d1 
-                   WHERE (
-                             (vo4d1.pk_patient = vo4d.pk_patient)
-                           AND (vo4d1.type = 'patient photograph'::text)
-                       )
-                GROUP BY vo4d1.date_generated 
-                ORDER BY vo4d1.date_generated DESC LIMIT 1
-                 )
-           )
-     )
-   AND (bdo.pk = vo4d.pk_obj)
-);</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-obj4doc-no-data">v_obj4doc_no_data</a>
-		</h2>
-        
-         <p>denormalized metadata for blobs.doc_obj but without the data itself</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>blobs.v_obj4doc_no_data Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>is_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
 				
-				
+				DEFAULT true
 				</i>
-				
+				<br><br>whether this health issue (problem) is active
 				</td>
 			 </tr>
             
@@ -44980,15 +59446,15 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_obj</td>
-            	<td>integer</td>
+            	<td>clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
 				
-				
+				DEFAULT true
 				</i>
-				
+				<br><br>whether this health issue (problem) has any clinical relevance
 				</td>
 			 </tr>
             
@@ -44996,13 +59462,13 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>seq_idx</td>
-            	<td>integer</td>
+            	<td>is_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
 				
-				
+				DEFAULT false
 				</i>
 				
 				</td>
@@ -45012,13 +59478,13 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>size</td>
-            	<td>integer</td>
+            	<td>is_cause_of_death</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT false
 				</i>
 				
 				</td>
@@ -45027,16 +59493,24 @@ WHERE (
             <tr class="tr0">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  
+                
                 </td>
-            	<td>date_generated</td>
-            	<td>timestamp with time zone</td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
 
+					
 				
+
+				NOT NULL
 				
 				</i>
-				
+				<br><br>The encounter during which this health issue was added.
 				</td>
 			 </tr>
             
@@ -45044,7 +59518,7 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>type</td>
+            	<td>grouping</td>
             	<td>text</td>
                 <td><i>
 				
@@ -45052,7 +59526,8 @@ WHERE (
 				
 				
 				</i>
-				
+				<br><br>This can be used to entirely arbitrarily group health
+ issues felt to belong to each other.
 				</td>
 			 </tr>
             
@@ -45060,7 +59535,7 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>l10n_type</td>
+            	<td>diagnostic_certainty_classification</td>
             	<td>text</td>
                 <td><i>
 				
@@ -45068,7 +59543,11 @@ WHERE (
 				
 				
 				</i>
-				
+				<br><br>The certainty at which this issue is believed to be a diagnosis:
+A: sign (Symptom)
+B: cluster of signs (Symptomkomplex)
+C: syndromic diagnosis (Bild einer Diagnose)
+D: proven diagnosis (diagnostisch gesichert)
 				</td>
 			 </tr>
             
@@ -45076,7 +59555,7 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>ext_ref</td>
+            	<td>summary</td>
             	<td>text</td>
                 <td><i>
 				
@@ -45084,21 +59563,133 @@ WHERE (
 				
 				
 				</i>
-				
+				<br><br>Used for tracking the summary of this health issue.
 				</td>
 			 </tr>
             
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table clin.health_issue Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.health_issue Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>health_issue_laterality_check</td>
+                <td>CHECK (((laterality)::text = ANY (ARRAY[(NULL::character varying)::text, ('s'::character varying)::text, ('d'::character varying)::text, ('sd'::character varying)::text, ('na'::character varying)::text])))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>health_issue_sane_summary</td>
+                <td>CHECK (gm.is_null_or_non_empty_string(summary))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>issue_name_not_empty</td>
+                <td>CHECK ((btrim(description) <> ''::text))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>sane_grouping</td>
+                <td>CHECK (gm.is_null_or_non_empty_string(grouping))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>valid_diagnostic_certainty_classification</td>
+                <td>CHECK ((diagnostic_certainty_classification = ANY (ARRAY['A'::text, 'B'::text, 'C'::text, 'D'::text, NULL::text])))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.episode">clin.episode</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.external-care">clin.external_care</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2h-issue">clin.lnk_code2h_issue</a></li>
+			</ul>
+		
+		
+
+    <!-- Indexes -->
+    
+       idx_health_issue_modified_by modified_by
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.hospital-stay">hospital_stay</a>
+		</h2>
+        
+         <p>collects data on hospitalisations of patients, reasons are linked via a link table</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.hospital_stay Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>episode</td>
-            	<td>text</td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -45108,12 +59699,12 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>doc_comment</td>
-            	<td>text</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -45124,13 +59715,13 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>obj_comment</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -45139,14 +59730,22 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
-            	<td>filename</td>
-            	<td>text</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
+					
 
+					
 				
-				
+
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -45156,13 +59755,13 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_intended_reviewer</td>
+            	<td>pk_item</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('clin_root_item_pk_item_seq'::regclass)
 				</i>
 				
 				</td>
@@ -45172,28 +59771,36 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>reviewed</td>
-            	<td>boolean</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
-				
+				<br><br>to be used as when the patient was admitted
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  
+                
                 </td>
-            	<td>reviewed_by_you</td>
-            	<td>boolean</td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
 
+					
 				
+
+				NOT NULL
 				
 				</i>
 				
@@ -45203,57 +59810,49 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
-                </td>
-            	<td>reviewed_by_intended_reviewer</td>
-            	<td>boolean</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
+                  
                 
                 </td>
-            	<td>pk_doc</td>
+            	<td>fk_episode</td>
             	<td>integer</td>
                 <td><i>
 				
+					
 
+					
 				
+
+				NOT NULL
 				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_type</td>
-            	<td>integer</td>
+            	<td>narrative</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>a comment on the hospital stay
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -45264,14 +59863,21 @@ WHERE (
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
+
+					
+				
 
 				
 				
@@ -45280,35 +59886,43 @@ WHERE (
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
-            	<td>integer</td>
+            	<td>discharge</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>when was the patient discharged
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.org-unit">dem.org_unit.pk</a>
+                  
+                
                 </td>
-            	<td>xmin_doc_obj</td>
-            	<td>xid</td>
+            	<td>fk_org_unit</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
 
+					
 				
+
+				NOT NULL
 				
 				</i>
-				
+				<br><br>links to the hospital the patient was admitted to
 				</td>
 			 </tr>
             
@@ -45316,103 +59930,97 @@ WHERE (
 
         <!-- Inherits -->
 		
+        <p>Table clin.hospital_stay Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin_root_item</a>, 
+        
+        </p>
+		
 
 		
+		
+		
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.hospital_stay Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>clin_root_item_sane_soap_cat</td>
+                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>sane_duration</td>
+                <td>CHECK (((discharge IS NULL) OR (discharge > clin_when)))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>sane_hospital</td>
+                <td>CHECK (gm.is_null_or_non_empty_string(narrative))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#blobs.table.lnk-doc2hospital-stay">blobs.lnk_doc2hospital_stay</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.procedure">clin.procedure</a></li>
+			</ul>
+		
+		
 
     <!-- Indexes -->
     
+       idx_clin_hospital_stay_fk_encounter fk_encounter
+    
+       idx_clin_hospital_stay_fk_episode fk_episode
+    
 
 	<!-- View Definition -->
 	
-	<pre>
-SELECT vdm.pk_patient
-, dobj.pk AS pk_obj
-, dobj.seq_idx
-, octet_length
-(COALESCE
-     (dobj.data
-           ,'\x'::bytea
-     )
-) AS size
-, vdm.clin_when AS date_generated
-, vdm.type
-, vdm.l10n_type
-, vdm.ext_ref
-, vdm.episode
-, vdm.comment AS doc_comment
-, dobj.comment AS obj_comment
-, dobj.filename
-, dobj.fk_intended_reviewer AS pk_intended_reviewer
-, (EXISTS 
-     (
-      SELECT 1 
-        FROM blobs.reviewed_doc_objs 
-       WHERE (reviewed_doc_objs.fk_reviewed_row = dobj.pk)
-     )
-) AS reviewed
-, (EXISTS 
-     (
-      SELECT 1 
-        FROM blobs.reviewed_doc_objs 
-       WHERE (
-                 (reviewed_doc_objs.fk_reviewed_row = dobj.pk)
-               AND (reviewed_doc_objs.fk_reviewer = 
-                       (
-                        SELECT staff.pk 
-                          FROM dem.staff 
-                         WHERE (staff.db_user = "current_user"
-                                   ()
-                             )
-                       )
-                 )
-           )
-     )
-) AS reviewed_by_you
-, (EXISTS 
-     (
-      SELECT 1 
-        FROM blobs.reviewed_doc_objs 
-       WHERE (
-                 (reviewed_doc_objs.fk_reviewed_row = dobj.pk)
-               AND (reviewed_doc_objs.fk_reviewer = dobj.fk_intended_reviewer)
-           )
-     )
-) AS reviewed_by_intended_reviewer
-, vdm.pk_doc
-, vdm.pk_type
-, vdm.pk_encounter
-, vdm.pk_episode
-, vdm.pk_health_issue
-, dobj.xmin AS xmin_doc_obj 
-FROM blobs.v_doc_med vdm
-, blobs.doc_obj dobj 
-WHERE (vdm.pk_doc = dobj.fk_doc);</pre>
-	
 
 	<!-- List off permissions -->
 	
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
-		<h2>View:
+		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-reviewed-doc-objects">v_reviewed_doc_objects</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.incoming-data-unmatchable">incoming_data_unmatchable</a>
 		</h2>
         
+         <p>this table holds test results that could not be matched
+	 to any patient, it is intended to prevent overflow of
+	 incoming_data_unmatched with unmatchable data</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>blobs.v_reviewed_doc_objects Structure</caption>
+                <caption>clin.incoming_data_unmatchable Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -45424,13 +60032,13 @@ WHERE (vdm.pk_doc = dobj.fk_doc);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_doc_obj</td>
+            	<td>pk_audit</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -45440,12 +60048,12 @@ WHERE (vdm.pk_doc = dobj.fk_doc);</pre>
 				<td>
                 
                 </td>
-            	<td>reviewer</td>
-            	<td>text</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -45456,13 +60064,13 @@ WHERE (vdm.pk_doc = dobj.fk_doc);</pre>
 				<td>
                 
                 </td>
-            	<td>is_technically_abnormal</td>
-            	<td>boolean</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -45471,14 +60079,22 @@ WHERE (vdm.pk_doc = dobj.fk_doc);</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
-            	<td>clinically_relevant</td>
-            	<td>boolean</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
+					
 
+					
 				
-				
+
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -45487,11 +60103,18 @@ WHERE (vdm.pk_doc = dobj.fk_doc);</pre>
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>is_review_by_responsible_reviewer</td>
-            	<td>boolean</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
+
+					
+				
 
 				
 				
@@ -45504,8 +60127,8 @@ WHERE (vdm.pk_doc = dobj.fk_doc);</pre>
 				<td>
                 
                 </td>
-            	<td>is_your_review</td>
-            	<td>boolean</td>
+            	<td>fk_patient_candidates</td>
+            	<td>integer[]</td>
                 <td><i>
 				
 
@@ -45520,7 +60143,7 @@ WHERE (vdm.pk_doc = dobj.fk_doc);</pre>
 				<td>
                 
                 </td>
-            	<td>comment</td>
+            	<td>request_id</td>
             	<td>text</td>
                 <td><i>
 				
@@ -45536,8 +60159,8 @@ WHERE (vdm.pk_doc = dobj.fk_doc);</pre>
 				<td>
                 
                 </td>
-            	<td>reviewed_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>firstnames</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -45552,8 +60175,8 @@ WHERE (vdm.pk_doc = dobj.fk_doc);</pre>
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>lastnames</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -45568,8 +60191,8 @@ WHERE (vdm.pk_doc = dobj.fk_doc);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_review_root</td>
-            	<td>integer</td>
+            	<td>dob</td>
+            	<td>date</td>
                 <td><i>
 				
 
@@ -45584,8 +60207,8 @@ WHERE (vdm.pk_doc = dobj.fk_doc);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_reviewer</td>
-            	<td>integer</td>
+            	<td>postcode</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -45600,8 +60223,8 @@ WHERE (vdm.pk_doc = dobj.fk_doc);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>other_info</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -45616,8 +60239,8 @@ WHERE (vdm.pk_doc = dobj.fk_doc);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -45632,12 +60255,12 @@ WHERE (vdm.pk_doc = dobj.fk_doc);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>data</td>
+            	<td>bytea</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -45648,8 +60271,8 @@ WHERE (vdm.pk_doc = dobj.fk_doc);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
-            	<td>integer</td>
+            	<td>gender</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -45660,120 +60283,12 @@ WHERE (vdm.pk_doc = dobj.fk_doc);</pre>
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT rdo.fk_reviewed_row AS pk_doc_obj
-, COALESCE
-(
-     (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.pk = rdo.fk_reviewer)
-     )
-     , (
-           ('<#'::text || rdo.fk_reviewer) || '>'::text
-     )
-) AS reviewer
-, rdo.is_technically_abnormal
-, rdo.clinically_relevant
-, (EXISTS 
-     (
-      SELECT 1 
-        FROM blobs.doc_obj 
-       WHERE (
-                 (doc_obj.pk = rdo.fk_reviewed_row)
-               AND (doc_obj.fk_intended_reviewer = rdo.fk_reviewer)
-           )
-     )
-) AS is_review_by_responsible_reviewer
-, (EXISTS 
-     (
-      SELECT 1 
-        FROM dem.staff 
-       WHERE (
-                 (staff.pk = rdo.fk_reviewer)
-               AND (staff.db_user = "current_user"
-                       ()
-                 )
-           )
-     )
-) AS is_your_review
-, rdo.comment
-, rdo.modified_when AS reviewed_when
-, rdo.modified_by
-, rdo.pk AS pk_review_root
-, rdo.fk_reviewer AS pk_reviewer
-, (
-SELECT v_obj4doc_no_data.pk_patient 
-  FROM blobs.v_obj4doc_no_data 
- WHERE (v_obj4doc_no_data.pk_obj = rdo.fk_reviewed_row)
-) AS pk_patient
-, (
-SELECT v_obj4doc_no_data.pk_encounter 
-  FROM blobs.v_obj4doc_no_data 
- WHERE (v_obj4doc_no_data.pk_obj = rdo.fk_reviewed_row)
-) AS pk_encounter
-, (
-SELECT v_obj4doc_no_data.pk_episode 
-  FROM blobs.v_obj4doc_no_data 
- WHERE (v_obj4doc_no_data.pk_obj = rdo.fk_reviewed_row)
-) AS pk_episode
-, (
-SELECT v_obj4doc_no_data.pk_health_issue 
-  FROM blobs.v_obj4doc_no_data 
- WHERE (v_obj4doc_no_data.pk_obj = rdo.fk_reviewed_row)
-) AS pk_health_issue 
-FROM blobs.reviewed_doc_objs rdo;</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-unreviewed-docs">v_unreviewed_docs</a>
-		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>blobs.v_unreviewed_docs Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>pk_doc</td>
-            	<td>integer</td>
+            	<td>requestor</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -45784,12 +60299,12 @@ FROM blobs.reviewed_doc_objs rdo;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_intended_reviewer</td>
-            	<td>integer</td>
+            	<td>external_data_id</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -45800,11 +60315,11 @@ FROM blobs.reviewed_doc_objs rdo;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
+            	<td>fk_identity_disambiguated</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -45820,11 +60335,35 @@ FROM blobs.reviewed_doc_objs rdo;</pre>
 
         <!-- Inherits -->
 		
+        <p>Table clin.incoming_data_unmatchable Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
 
 		
+		
+		
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.incoming_data_unmatchable Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
@@ -45834,201 +60373,48 @@ FROM blobs.reviewed_doc_objs rdo;</pre>
 
 	<!-- View Definition -->
 	
-	<pre>
-SELECT DISTINCT 
-ON (b_do.fk_doc) b_do.fk_doc AS pk_doc
-, min
-(b_do.fk_intended_reviewer) AS pk_intended_reviewer
-, min
-(c_e.fk_patient) AS pk_patient 
-FROM (
-     (blobs.doc_obj b_do 
-        JOIN blobs.doc_med b_dm 
-          ON (
-                 (b_dm.pk = b_do.fk_doc)
-           )
-     )
-  JOIN clin.encounter c_e 
-    ON (
-           (b_dm.fk_encounter = c_e.pk)
-     )
-)
-WHERE (NOT 
-     (EXISTS 
-           (
-            SELECT 1 
-              FROM blobs.reviewed_doc_objs b_rdo 
-             WHERE (b_rdo.fk_reviewed_row = b_do.pk)
-           )
-     )
-)
-GROUP BY b_do.fk_doc;</pre>
-	
 
 	<!-- List off permissions -->
 	
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
-		<h2>View:
+		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-unreviewed-docs-inbox">v_unreviewed_docs_inbox</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.incoming-data-unmatched">incoming_data_unmatched</a>
 		</h2>
         
+         <p>this table holds incoming data (lab results, documents)
+	 that could not be matched to one single patient automatically,
+	 it is intended to facilitate manual matching,
+	 - use "modified_when" for import time</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>blobs.v_unreviewed_docs_inbox Structure</caption>
+                <caption>clin.incoming_data_unmatched Structure</caption>
                 <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>received_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>modified_by</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>provider</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>importance</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>category</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>l10n_category</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>type</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>l10n_type</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -46038,12 +60424,12 @@ GROUP BY b_do.fk_doc;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_context</td>
-            	<td>integer[]</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -46054,13 +60440,13 @@ GROUP BY b_do.fk_doc;</pre>
 				<td>
                 
                 </td>
-            	<td>data</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -46069,14 +60455,22 @@ GROUP BY b_do.fk_doc;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
-            	<td>pk_inbox_message</td>
-            	<td>integer</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
+					
 
+					
 				
-				
+
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -46085,11 +60479,18 @@ GROUP BY b_do.fk_doc;</pre>
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>pk_staff</td>
-            	<td>integer</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
+
+					
+				
 
 				
 				
@@ -46102,15 +60503,17 @@ GROUP BY b_do.fk_doc;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_category</td>
-            	<td>integer</td>
+            	<td>fk_patient_candidates</td>
+            	<td>integer[]</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>a matching algorithm can be applied to produce
+	 a list of likely candidate patients, the question
+	 remains whether this should not be done at runtime
 				</td>
 			 </tr>
             
@@ -46118,15 +60521,15 @@ GROUP BY b_do.fk_doc;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_type</td>
-            	<td>integer</td>
+            	<td>request_id</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>request ID as found in <data>
 				</td>
 			 </tr>
             
@@ -46134,15 +60537,15 @@ GROUP BY b_do.fk_doc;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>firstnames</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>first names as found in <data>
 				</td>
 			 </tr>
             
@@ -46150,15 +60553,15 @@ GROUP BY b_do.fk_doc;</pre>
 				<td>
                 
                 </td>
-            	<td>is_virtual</td>
-            	<td>boolean</td>
+            	<td>lastnames</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>last names as found in <data>
 				</td>
 			 </tr>
             
@@ -46166,15 +60569,15 @@ GROUP BY b_do.fk_doc;</pre>
 				<td>
                 
                 </td>
-            	<td>due_date</td>
-            	<td>timestamp with time zone</td>
+            	<td>dob</td>
+            	<td>date</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>date of birth as found in <data>
 				</td>
 			 </tr>
             
@@ -46182,15 +60585,15 @@ GROUP BY b_do.fk_doc;</pre>
 				<td>
                 
                 </td>
-            	<td>expiry_date</td>
-            	<td>timestamp with time zone</td>
+            	<td>postcode</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>postcode as found in <data>
 				</td>
 			 </tr>
             
@@ -46198,15 +60601,15 @@ GROUP BY b_do.fk_doc;</pre>
 				<td>
                 
                 </td>
-            	<td>is_overdue</td>
-            	<td>boolean</td>
+            	<td>other_info</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>other identifying information as found in <data>
 				</td>
 			 </tr>
             
@@ -46214,15 +60617,16 @@ GROUP BY b_do.fk_doc;</pre>
 				<td>
                 
                 </td>
-            	<td>is_expired</td>
-            	<td>boolean</td>
+            	<td>type</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>the type of <data>, eg HL7, LDT, ...,
+	 useful for selecting an importer
 				</td>
 			 </tr>
             
@@ -46230,156 +60634,31 @@ GROUP BY b_do.fk_doc;</pre>
 				<td>
                 
                 </td>
-            	<td>interval_due</td>
-            	<td>interval</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>xmin_message_inbox</td>
-            	<td>integer</td>
+            	<td>data</td>
+            	<td>bytea</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>the raw data
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT now
-() AS received_when
-,'<system>'::text AS modified_by
-, NULL::text AS provider
-, 0 AS importance
-,'clinical'::text AS category
-, _
-('clinical'::text) AS l10n_category
-,'review docs'::text AS type
-, _
-('review docs'::text) AS l10n_type
-, (
-SELECT (
-           (
-                 (
-                       (
-                             (
-                                   (b_vuds.no_of_docs || ' '::text) || _
-                                   ('unreviewed documents for patient'::text)
-                             ) || ' '::text
-                       ) || d_n.lastnames
-                 ) || 
-              ', '::text
-           ) || d_n.firstnames
-     )
-) AS comment
-, NULL::integer[] AS pk_context
-, NULL::text AS data
-, NULL::integer AS pk_inbox_message
-, (
-SELECT staff.pk 
-  FROM dem.staff 
- WHERE (staff.db_user = "current_user"
-           ()
-     )
-) AS pk_staff
-, (
-SELECT v_inbox_item_type.pk_category 
-  FROM dem.v_inbox_item_type 
- WHERE (v_inbox_item_type.type = 'review docs'::text)
-) AS pk_category
-, (
-SELECT v_inbox_item_type.pk_type 
-  FROM dem.v_inbox_item_type 
- WHERE (v_inbox_item_type.type = 'review docs'::text)
-) AS pk_type
-, b_vuds.pk_patient
-, true AS is_virtual
-, (now
-     () - '01:00:00'::interval
-) AS due_date
-, NULL::timestamp with time zone AS expiry_date
-, true AS is_overdue
-, false AS is_expired
-,'01:00:00'::interval AS interval_due
-, NULL::integer AS xmin_message_inbox 
-FROM (blobs.v_unreviewed_docs_summary b_vuds 
-  JOIN dem.names d_n 
-    ON (
-           (b_vuds.pk_patient = d_n.id_identity)
-     )
-)
-WHERE (d_n.active IS TRUE);</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.view.v-unreviewed-docs-summary">v_unreviewed_docs_summary</a>
-		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>blobs.v_unreviewed_docs_summary Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>gender</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>Gender of patient in source data if available.
 				</td>
 			 </tr>
             
@@ -46387,327 +60666,43 @@ WHERE (d_n.active IS TRUE);</pre>
 				<td>
                 
                 </td>
-            	<td>no_of_docs</td>
-            	<td>bigint</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT b_vud.pk_patient
-, count
-(1) AS no_of_docs 
-FROM blobs.v_unreviewed_docs b_vud 
-GROUP BY b_vud.pk_patient;</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#blobs.schema">Schema blobs</a>
-    </p>
-	
-
-	<!-- We've gone through the table structure, now lets take a look at user functions -->
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.function.delete-document-integer-integer">delete_document(integer, integer)</a>
-		</h2>
-<h3>Returns: boolean</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-DECLARE
-	_pk_doc alias for $1;
-	_pk_encounter alias for $2;
-	_del_note text;
-	_doc_row record;
-	_obj_row record;
-	tmp text;
-BEGIN
-	select * into _doc_row from blobs.doc_med where pk = _pk_doc;
-	_del_note := _('Deletion of document') || E':
-'
-		|| ' '
-			|| to_char(_doc_row.clin_when, 'YYYY-MM-DD HH24:MI')
-			|| ' "' || (select _(dt.name) from blobs.doc_type dt where pk = _doc_row.fk_type) || '"'
-			|| coalesce(' (' || _doc_row.ext_ref || ')', '')
-		|| coalesce(E'
- ' || _doc_row.comment, '')
-	;
-	FOR _obj_row IN select * from blobs.doc_obj where fk_doc = _pk_doc order by seq_idx LOOP
-		_del_note := _del_note || E'
-'
-			|| ' #' || coalesce(_obj_row.seq_idx, '-1') || ': "' || coalesce(_obj_row.comment, '') || E'"
-'
-			|| ' ' || coalesce(_obj_row.filename, '') || E'
-';
-	end LOOP;
-	insert into clin.clin_narrative
-		(fk_encounter, fk_episode, narrative, soap_cat)
-	values (
-		_pk_encounter,
-		_doc_row.fk_episode,
-		_del_note,
-		NULL
-	);
-	-- should auto-cascade:
-	--delete from blobs.doc_obj where fk_doc = _pk_doc;
-	-- should auto-NULL:
-	--bill.bill.fk_doc
-	delete from blobs.doc_med where pk = _pk_doc;
-	return True;
-END;</pre>
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.function.delete-document-part-integer-integer">delete_document_part(integer, integer)</a>
-		</h2>
-<h3>Returns: boolean</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-DECLARE
-	_pk_doc_part alias for $1;
-	_pk_encounter alias for $2;
-	_del_note text;
-	_doc_row record;
-	_obj_row record;
-	tmp text;
-BEGIN
-	select * into _obj_row from blobs.doc_obj where pk = _pk_doc_part;
-	select * into _doc_row from blobs.doc_med where pk = _obj_row.fk_doc;
-	_del_note := _('Deletion of part from document') || E':
-'
-		|| ' '
-			|| to_char(_doc_row.clin_when, 'YYYY-MM-DD HH24:MI')
-			|| ' "' || (select _(dt.name) from blobs.doc_type dt where pk = _doc_row.fk_type) || '"'
-			|| coalesce(' (' || _doc_row.ext_ref || ')', '')
-		|| coalesce(E'
- ' || _doc_row.comment, '')
-		|| E'
-'
-		|| ' #' || coalesce(_obj_row.seq_idx, '-1') || ': "' || coalesce(_obj_row.comment, '') || E'"
-'
-		|| ' ' || coalesce(_obj_row.filename, '') || E'
-'
-	;
-	insert into clin.clin_narrative
-		(fk_encounter, fk_episode, narrative, soap_cat)
-	values (
-		_pk_encounter,
-		_doc_row.fk_episode,
-		_del_note,
-		NULL
-	);
-	delete from blobs.doc_obj where pk = _pk_doc_part;
-	return True;
-END;</pre>
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.function.trf-do-not-duplicate-primary-episode-in-link-table">trf_do_not_duplicate_primary_episode_in_link_table()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        <p>This trigger function is called before a lnk_doc_med2episode
-	 row is inserted or updated. It makes sure the episode does
-	 not duplicate the primary episode for this document listed
-	 in doc_med. If it does the insert/update is skipped.</p>
-        <pre>
-BEGIN
-	-- if already in doc_med
-	perform 1 from blobs.doc_med dm where dm.fk_episode = NEW.fk_episode and dm.pk = NEW.fk_doc_med;
-	if FOUND then
-		-- skip the insert/update
-		return null;
-	end if;
-	return NEW;
-END;</pre>
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.function.trf-mark-unreviewed-on-doc-obj-update">trf_mark_unreviewed_on_doc_obj_update()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-BEGIN
-	if (NEW.data != OLD.data) or ((NEW.data != OLD.data) is NULL) then
-		delete from blobs.reviewed_doc_objs where fk_reviewed_row = OLD.pk;
-	end if;
-	return NEW;
-END;</pre>
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.function.trf-remove-primary-episode-from-link-table">trf_remove_primary_episode_from_link_table()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        <p>This trigger function is called when a doc_med row
-	 is inserted or updated. It makes sure the primary
-	 episode listed in doc_med is not duplicated in
-	 lnk_doc_med2episode for the same document. If it
-	 exists in the latter it is removed from there.</p>
-        <pre>
-BEGIN
-	-- if update
-	if TG_OP = 'UPDATE' then
-		-- and no change
-		if NEW.fk_episode = OLD.fk_episode then
-			-- then do nothing
-			return NEW;
-		end if;
-	end if;
-	-- if already in link table
-	perform 1 from blobs.lnk_doc_med2episode ldm2e where ldm2e.fk_episode = NEW.fk_episode and ldm2e.fk_doc_med = NEW.pk;
-	if FOUND then
-		-- delete from link table
-		delete from blobs.lnk_doc_med2episode where fk_episode = NEW.fk_episode and fk_doc_med = NEW.pk;
-	end if;
-	return NEW;
-END;</pre>
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.function.trf-set-intended-reviewer">trf_set_intended_reviewer()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        <p>Set the default on blobs.doc_obj.fk_intended_reviewer.</p>
-        <pre>
-DECLARE
-	_pk_patient integer;
-	_pk_provider integer;
-BEGIN
-	-- explicitely set ?
-	if NEW.fk_intended_reviewer is not NULL then
-		return NEW;
-	end if;
-	-- find patient via document
-	select
-		fk_patient into _pk_patient
-	from
-		clin.encounter
-	where
-		clin.encounter.pk = (
-			select fk_encounter from blobs.doc_med where pk = NEW.fk_doc
-		);
-	-- does patient have primary provider ?
-	select
-		fk_primary_provider into _pk_provider
-	from
-		dem.identity
-	where
-		dem.identity.pk = _pk_patient;
-	if _pk_provider is not NULL then
-		NEW.fk_intended_reviewer := _pk_provider;
-		return NEW;
-	end if;
-	-- else use CURRENT_USER
-	select
-		pk into _pk_provider
-	from
-		dem.staff
-	where
-		dem.staff.db_user = current_user;
-	NEW.fk_intended_reviewer := _pk_provider;
-	return NEW;
-END;</pre>
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#blobs.schema">blobs</a>.<a name="blobs.function.trf-verify-page-number">trf_verify_page_number()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-declare
-	msg text;
-begin
-	if NEW.seq_idx is NULL then
-		return NEW;
-	end if;
-	perform 1 from blobs.doc_obj where pk <> NEW.pk and fk_doc = NEW.fk_doc and seq_idx = NEW.seq_idx;
-	if FOUND then
-		msg := '[blobs.trf_verify_page_number]: uniqueness violation: seq_idx [' || NEW.seq_idx || '] already exists for fk_doc [' || NEW.fk_doc || ']';
-		raise exception '%', msg;
-	end if;
-	return NEW;
-end;</pre>
-	
-
-<!-- cfgcfg -->
-
-		
-		<hr>
-		<h1>Schema cfg</h1>
-		
-			<p>This schema holds all the configuration data.</p>
-		
-
-		
-		
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.cfg-data">cfg_data</a>
-		</h2>
-        
-         <p>stores opaque configuration data, either text or binary,
-	 note that it will be difficult to share such options
-	 among different types of clients</p>
-        
-
+            	<td>requestor</td>
+            	<td>text</td>
+                <td><i>
+				
 
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>cfg.cfg_data Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
+				
+				
+				</i>
+				<br><br>Requestor of data (e.g. who ordered test results) if available in source data.
+				</td>
+			 </tr>
             
             <tr class="tr0">
 				<td>
                 
+                </td>
+            	<td>external_data_id</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>ID of content of .data in external system (e.g. importer) where appropriate
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
                   
-                  <a href="gnumed-entire_schema.html#cfg.table.cfg-item">cfg.cfg_item.pk</a>
+                  <a href="gnumed-entire_schema.html#clin.table.patient">clin.patient.fk_identity</a>
                   
                 
                 </td>
-            	<td>fk_item</td>
+            	<td>fk_identity_disambiguated</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -46716,40 +60711,41 @@ end;</pre>
 					
 				
 
-				NOT NULL
 				
-				</i>
 				
+				</i>
+				<br><br>ID of patient the data is judged to really belong to.
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>value</td>
-            	<td>bytea</td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
 				
-				</i>
 				
+				</i>
+				<br><br>a free text comment on this row, eg. why is it here
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                   
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.pk</a>
+                  
                 
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>fk_provider_disambiguated</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
 					
 
 					
@@ -46758,7 +60754,7 @@ end;</pre>
 				
 				
 				</i>
-				
+				<br><br>The provider the data is relevant to.
 				</td>
 			 </tr>
             
@@ -46766,6 +60762,13 @@ end;</pre>
 
         <!-- Inherits -->
 		
+        <p>Table clin.incoming_data_unmatched Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
 
 		
 		
@@ -46773,6 +60776,26 @@ end;</pre>
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.incoming_data_unmatched Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>unmatched_data_sane_comment</td>
+                <td>CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
@@ -46788,21 +60811,21 @@ end;</pre>
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.cfg-item">cfg_item</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lab-request">lab_request</a>
 		</h2>
         
-         <p>this table holds all "instances" of cfg.cfg_template</p>
+         <p>test request metadata</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>cfg.cfg_item Structure</caption>
+                <caption>clin.lab_request Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -46813,6 +60836,192 @@ end;</pre>
             <tr class="tr0">
 				<td>
                 
+                </td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				DEFAULT "current_user"()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_item</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT nextval('clin_root_item_pk_item_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				<br><br>the time the sample for this request was taken
+	 LDT: 8432:8433
+	 HL7: OBR.quantity_timing
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  
+                
+                </td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
+                  
+                
+                </td>
+            	<td>fk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>narrative</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>free text comment on request
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>soap_cat</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				DEFAULT 'p'::text
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
                   
                 
                 </td>
@@ -46837,13 +61046,13 @@ end;</pre>
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#cfg.table.cfg-template">cfg.cfg_template.pk</a>
+                  <a href="gnumed-entire_schema.html#clin.table.test-org">clin.test_org.pk</a>
                   
                 
                   
                 
                 </td>
-            	<td>fk_template</td>
+            	<td>fk_test_org</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -46858,10 +61067,10 @@ end;</pre>
                     
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>this points to the class of this option, think of this as a base object, this also defines the data type
+				
 				</td>
 			 </tr>
             
@@ -46871,8 +61080,8 @@ end;</pre>
                   
                 
                 </td>
-            	<td>owner</td>
-            	<td>name</td>
+            	<td>request_id</td>
+            	<td>text</td>
                 <td><i>
 				
 					
@@ -46883,12 +61092,11 @@ end;</pre>
 				
 
 				NOT NULL
-				DEFAULT "current_user"()
+				
 				</i>
-				<br><br>the database level user this option belongs to; this
-	 is the "role" of the user from the perspective of
-	 the database; can be "default" at the application
-	 level to indicate that it does not care
+				<br><br>ID this request had when sent to the lab
+	 LDT: 8310
+	 HL7: OBR.filler_order_number
 				</td>
 			 </tr>
             
@@ -46896,56 +61104,161 @@ end;</pre>
 				<td>
                 
                   
+                  <a href="gnumed-entire_schema.html#dem.table.identity">dem.identity.pk</a>
+                  
                 
                 </td>
-            	<td>workplace</td>
-            	<td>text</td>
+            	<td>fk_requestor</td>
+            	<td>integer</td>
                 <td><i>
 				
 					
 
 					
-                       UNIQUE#1
-                    
 				
 
 				
 				
 				</i>
-				<br><br>- the logical workplace this option pertains to
-	 - can be a hostname but should be a logical rather
-	   than a physical identifier as machines get moved,
-	   workplaces do not, kind of like a "role" for the
-	   machine
-	 - associate this with a physical workplace through
-	   a local config file or environment variable
+				<br><br>who requested the test - really needed ?
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
+                </td>
+            	<td>lab_request_id</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>ID this request had internally at the lab
+	 LDT: 8311
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
                 
                 </td>
-            	<td>cookie</td>
+            	<td>lab_rxd_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>when did the lab receive the request+sample
+	 LDT: 8301
+	 HL7: OBR.requested_date_time
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>results_reported_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>when was the report on the result generated,
+	LDT: 8302
+	HL7: OBR.results_report_status_change
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>request_status</td>
             	<td>text</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
+				NOT NULL
+				
+				</i>
+				<br><br>pending, final, preliminary, partial
+	 LDT: 8401
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>is_pending</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT true
+				</i>
+				<br><br>true if any (even partial) results are still pending
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>diagnostic_service_section</td>
+            	<td>text</td>
+                <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>an arbitrary, opaque entity the client code can use
-	 to associate this config item with even finer grained
-	 context; could be the pertinent patient ID for patient
-	 specific options
+				<br><br>The (section of) the diagnostic service which performed the test.
+- HL7 2.3: OBR:24 Diagnostic Service Section ID
+- somewhat redundant with fk_test_org, which, however,
+  points to more normalized data
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>ordered_service</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>The (battery of) test(s)/service(s) ordered.
+- HL7 2.3: OBR:4 Universal Service ID
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>note_test_org</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>A comment on this lab request by the performing organization (lab).
 				</td>
 			 </tr>
             
@@ -46953,6 +61266,13 @@ end;</pre>
 
         <!-- Inherits -->
 		
+        <p>Table clin.lab_request Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin_root_item</a>, 
+        
+        </p>
+		
 
 		
 		
@@ -46960,31 +61280,58 @@ end;</pre>
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.lab_request Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>clin_lab_req_sane_test_org_note</td>
+                <td>CHECK ((gm.is_null_or_non_empty_string(note_test_org) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>clin_root_item_sane_soap_cat</td>
+                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>lab_request_request_id_check</td>
+                <td>CHECK ((btrim(request_id) <> ''::text))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>lab_request_request_status_check</td>
+                <td>CHECK ((request_status = ANY (ARRAY['pending'::text, 'preliminary'::text, 'partial'::text, 'final'::text])))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
 			<p>Tables referencing this one via Foreign Key Constraints:</p>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#cfg.table.cfg-data">cfg.cfg_data</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#cfg.table.cfg-numeric">cfg.cfg_numeric</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#cfg.table.cfg-str-array">cfg.cfg_str_array</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#cfg.table.cfg-string">cfg.cfg_string</a></li>
+				<li><a href="gnumed-entire_schema.html#clin.table.test-result">clin.test_result</a></li>
 			</ul>
 		
 		
 
     <!-- Indexes -->
     
+       idx_clin_lab_request_fk_encounter fk_encounter
+    
+       idx_clin_lab_request_fk_episode fk_episode
+    
 
 	<!-- View Definition -->
 	
@@ -46994,19 +61341,21 @@ end;</pre>
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.cfg-numeric">cfg_numeric</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-code2aoe">lnk_code2aoe</a>
 		</h2>
         
+         <p>Links codes to encounter.aoe.</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>cfg.cfg_numeric Structure</caption>
+                <caption>clin.lnk_code2aoe Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -47017,22 +61366,14 @@ end;</pre>
             <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#cfg.table.cfg-item">cfg.cfg_item.pk</a>
-                  
-                
                 </td>
-            	<td>fk_item</td>
+            	<td>pk_audit</td>
             	<td>integer</td>
                 <td><i>
 				
-					
-
-					
-				
 
 				NOT NULL
-				
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -47042,8 +61383,8 @@ end;</pre>
 				<td>
                 
                 </td>
-            	<td>value</td>
-            	<td>numeric</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -47057,82 +61398,29 @@ end;</pre>
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.cfg-str-array">cfg_str_array</a>
-		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>cfg.cfg_str_array Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#cfg.table.cfg-item">cfg.cfg_item.pk</a>
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
                   
                 
                 </td>
-            	<td>fk_item</td>
-            	<td>integer</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 					
@@ -47141,102 +61429,59 @@ end;</pre>
 				
 
 				NOT NULL
-				
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>value</td>
-            	<td>text[]</td>
+            	<td>pk_lnk_code2item</td>
+            	<td>integer</td>
                 <td><i>
 				
 
 				NOT NULL
-				
+				DEFAULT nextval('lnk_code2item_root_pk_lnk_code2item_seq'::regclass)
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                   
                 
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>fk_generic_code</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
 					
 
 					
+                       UNIQUE#1
+                    
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>Custom foreign key to ref.coding_system_root.
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.cfg-string">cfg_string</a>
-		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>cfg.cfg_string Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#cfg.table.cfg-item">cfg.cfg_item.pk</a>
+                
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
                   
                 
                 </td>
@@ -47247,12 +61492,18 @@ end;</pre>
 					
 
 					
+                       UNIQUE#1
+                    
+				
+					
+
+					
 				
 
-				NOT NULL
 				
-				</i>
 				
+				</i>
+				<br><br>Foreign key to clin.encounter
 				</td>
 			 </tr>
             
@@ -47260,12 +61511,12 @@ end;</pre>
 				<td>
                 
                 </td>
-            	<td>value</td>
+            	<td>code_modifier</td>
             	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -47299,6 +61550,13 @@ end;</pre>
 
         <!-- Inherits -->
 		
+        <p>Table clin.lnk_code2aoe Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#clin.table.lnk-code2item-root">lnk_code2item_root</a>, 
+        
+        </p>
+		
 
 		
 		
@@ -47306,12 +61564,29 @@ end;</pre>
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.lnk_code2aoe Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
 
     <!-- Indexes -->
     
+       idx_c_lc2aoe_fk_item fk_item
+    
 
 	<!-- View Definition -->
 	
@@ -47321,21 +61596,21 @@ end;</pre>
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.cfg-template">cfg_template</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-code2episode">lnk_code2episode</a>
 		</h2>
         
-         <p>meta definition of config items</p>
+         <p>Links codes to episodes.</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>cfg.cfg_template Structure</caption>
+                <caption>clin.lnk_code2episode Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -47346,52 +61621,61 @@ end;</pre>
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
 
-					
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				</i>
 				
-
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
 				
+
+				NOT NULL
 				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>name</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
 				NOT NULL
-				DEFAULT 'must set this !'::text
+				DEFAULT now()
 				</i>
-				<br><br>the name of the option; this MUST be set to something meaningful
+				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#cfg.table.cfg-type-enum">cfg.cfg_type_enum.name</a>
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
                   
                 
                 </td>
-            	<td>type</td>
-            	<td>text</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 					
@@ -47400,98 +61684,99 @@ end;</pre>
 				
 
 				NOT NULL
-				
+				DEFAULT "current_user"()
 				</i>
-				<br><br>type of the value
+				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>cfg_group</td>
-            	<td>text</td>
+            	<td>pk_lnk_code2item</td>
+            	<td>integer</td>
                 <td><i>
 				
 
 				NOT NULL
-				DEFAULT 'xxxDEFAULTxxx'::text
+				DEFAULT nextval('lnk_code2item_root_pk_lnk_code2item_seq'::regclass)
 				</i>
-				<br><br>just for logical grouping of options according to task sets to facilitate better config management
+				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>description</td>
-            	<td>text</td>
+            	<td>fk_generic_code</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
+
+					
+                       UNIQUE#1
+                    
+				
 
 				NOT NULL
-				DEFAULT 'programmer is an avid Camel Book Reader'::text
+				
 				</i>
-				<br><br>arbitrary description (user visible)
+				<br><br>Custom foreign key to ref.coding_system_root.
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#cfg.table.cfg-item">cfg.cfg_item</a></li>
-			</ul>
-		
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
+                  
+                
+                </td>
+            	<td>fk_item</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
 
-	<!-- List off permissions -->
-	
+					
+                       UNIQUE#1
+                    
+				
+					
 
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.cfg-type-enum">cfg_type_enum</a>
-		</h2>
-        
-         <p>enumeration of config option data types</p>
-        
+					
+				
 
+				
+				
+				</i>
+				<br><br>Foreign key to clin.episode
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>code_modifier</td>
+            	<td>text</td>
+                <td><i>
+				
 
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>cfg.cfg_type_enum Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
             
             <tr class="tr0">
 				<td>
@@ -47499,18 +61784,17 @@ end;</pre>
                   
                 
                 </td>
-            	<td>name</td>
-            	<td>text</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
 					
 
 					
-                       UNIQUE
-                    
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -47521,6 +61805,13 @@ end;</pre>
 
         <!-- Inherits -->
 		
+        <p>Table clin.lnk_code2episode Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#clin.table.lnk-code2item-root">lnk_code2item_root</a>, 
+        
+        </p>
+		
 
 		
 		
@@ -47528,19 +61819,29 @@ end;</pre>
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.lnk_code2episode Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#cfg.table.cfg-template">cfg.cfg_template</a></li>
-			</ul>
-		
-		
 
     <!-- Indexes -->
     
+       idx_c_lc2epi_fk_item fk_item
+    
 
 	<!-- View Definition -->
 	
@@ -47550,23 +61851,21 @@ end;</pre>
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.config">config</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-code2fhx">lnk_code2fhx</a>
 		</h2>
         
-         <p>maps a service name to a database location
-	 for a particular user, includes user
-	 credentials for that database</p>
+         <p>Links codes to family history items.</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>cfg.config Structure</caption>
+                <caption>clin.lnk_code2fhx Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -47577,21 +61876,14 @@ end;</pre>
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>id</td>
-            	<td>serial</td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -47601,18 +61893,15 @@ end;</pre>
 				<td>
                 
                 </td>
-            	<td>profile</td>
-            	<td>character(25)</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
+				NOT NULL
 				
-				DEFAULT 'default'::bpchar
 				</i>
-				<br><br>allows multiple profiles per user/
-	 pseudo user, one user may have different
-	 configuration profiles depending on role,
-	 need and location
+				
 				</td>
 			 </tr>
             
@@ -47620,63 +61909,39 @@ end;</pre>
 				<td>
                 
                 </td>
-            	<td>username</td>
-            	<td>character(25)</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				DEFAULT "current_user"()
+				NOT NULL
+				DEFAULT now()
 				</i>
-				<br><br>user name as used within the GNUmed system
+				
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
-                </td>
-            	<td>ddb</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				<br><br>which GNUmed service are we mapping to a database here
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
                 
                 </td>
-            	<td>db</td>
-            	<td>integer</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
+					
 
-				
-				
-				</i>
-				<br><br>how to reach the database host for this service
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>crypt_pwd</td>
-            	<td>text</td>
-                <td><i>
+					
 				
 
-				
-				
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
-				<br><br>password for user and database, encrypted
+				
 				</td>
 			 </tr>
             
@@ -47684,103 +61949,79 @@ end;</pre>
 				<td>
                 
                 </td>
-            	<td>crypt_algo</td>
-            	<td>text</td>
+            	<td>pk_lnk_code2item</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('lnk_code2item_root_pk_lnk_code2item_seq'::regclass)
 				</i>
-				<br><br>encryption algorithm used for password encryption
+				
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>pwd_hash</td>
-            	<td>text</td>
+            	<td>fk_generic_code</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
 
+					
+                       UNIQUE#1
+                    
 				
+
+				NOT NULL
 				
 				</i>
-				<br><br>hash of the unencrypted password
+				<br><br>Custom foreign key to ref.coding_system_root.
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
+                  
+                
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.family-history">clin.family_history.pk</a>
+                  
+                
                 </td>
-            	<td>hash_algo</td>
-            	<td>text</td>
+            	<td>fk_item</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
+
+					
+                       UNIQUE#1
+                    
+				
+					
+
+					
+				
 
 				
 				
 				</i>
-				<br><br>algorithm used for password hashing
+				<br><br>Foreign key to clin.family_history
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.db-logon-banner">db_logon_banner</a>
-		</h2>
-        
-         <p>Stores a banner to show when clients log on.</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>cfg.db_logon_banner Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>message</td>
+            	<td>code_modifier</td>
             	<td>text</td>
                 <td><i>
 				
@@ -47788,31 +62029,30 @@ end;</pre>
 				
 				
 				</i>
-				<br><br>The actual message to show.
+				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                   
                 
                 </td>
-            	<td>singularizer</td>
-            	<td>boolean</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
 					
 
 					
-                       UNIQUE
-                    
 				
 
 				
-				DEFAULT true
+				
 				</i>
-				<br><br>Makes sure there only ever is one such banner at any given time.
+				
 				</td>
 			 </tr>
             
@@ -47820,6 +62060,13 @@ end;</pre>
 
         <!-- Inherits -->
 		
+        <p>Table clin.lnk_code2fhx Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#clin.table.lnk-code2item-root">lnk_code2item_root</a>, 
+        
+        </p>
+		
 
 		
 		
@@ -47829,20 +62076,15 @@ end;</pre>
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>cfg.db_logon_banner Constraints</caption>
+            <caption>clin.lnk_code2fhx Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
-				<td>db_logon_banner_message_check</td>
-                <td>CHECK ((btrim(message) <> ''::text))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>db_logon_banner_singularizer_check</td>
-                <td>CHECK ((singularizer IS TRUE))</td>
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
             </tr>
 			
 		</table>
@@ -47853,6 +62095,8 @@ end;</pre>
 
     <!-- Indexes -->
     
+       idx_c_lc2fhx_fk_item fk_item
+    
 
 	<!-- View Definition -->
 	
@@ -47862,21 +62106,21 @@ end;</pre>
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.table.report-query">report_query</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-code2h-issue">lnk_code2h_issue</a>
 		</h2>
         
-         <p>This table stores SQL commands to be used in frontend report style queries.</p>
+         <p>Links codes to health issues.</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>cfg.report_query Structure</caption>
+                <caption>clin.lnk_code2h_issue Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -47935,11 +62179,19 @@ end;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -47951,44 +62203,85 @@ end;</pre>
             <tr class="tr0">
 				<td>
                 
+                </td>
+            	<td>pk_lnk_code2item</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT nextval('lnk_code2item_root_pk_lnk_code2item_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
                   
                 
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>fk_generic_code</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
 					
 
 					
+                       UNIQUE#1
+                    
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>Custom foreign key to ref.coding_system_root.
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                   
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.health-issue">clin.health_issue.pk</a>
+                  
+                
                 </td>
-            	<td>label</td>
-            	<td>text</td>
+            	<td>fk_item</td>
+            	<td>integer</td>
                 <td><i>
 				
 					
 
 					
-                       UNIQUE
+                       UNIQUE#1
                     
 				
+					
+
+					
+				
+
+				
+				
+				</i>
+				<br><br>Foreign key to clin.health_issue
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>code_modifier</td>
+            	<td>text</td>
+                <td><i>
+				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -47998,13 +62291,20 @@ end;</pre>
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>cmd</td>
-            	<td>text</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
 
-				NOT NULL
+					
+				
+
+				
 				
 				</i>
 				
@@ -48015,10 +62315,10 @@ end;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table cfg.report_query Inherits
+        <p>Table clin.lnk_code2h_issue Inherits
         
             
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+           <a href="gnumed-entire_schema.html#clin.table.lnk-code2item-root">lnk_code2item_root</a>, 
         
         </p>
 		
@@ -48031,20 +62331,15 @@ end;</pre>
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>cfg.report_query Constraints</caption>
+            <caption>clin.lnk_code2h_issue Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
-				<td>report_query_cmd_check</td>
-                <td>CHECK ((btrim(COALESCE(cmd, 'NULL'::text)) <> ''::text))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>report_query_label_check</td>
-                <td>CHECK ((btrim(COALESCE(label, 'NULL'::text)) <> ''::text))</td>
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
             </tr>
 			
 		</table>
@@ -48055,6 +62350,8 @@ end;</pre>
 
     <!-- Indexes -->
     
+       idx_c_lc2iss_fk_item fk_item
+    
 
 	<!-- View Definition -->
 	
@@ -48064,19 +62361,27 @@ end;</pre>
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
-		<h2>View:
+		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.view.v-cfg-options">v_cfg_options</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-code2item-root">lnk_code2item_root</a>
 		</h2>
         
+         <p>The parent table of all tables linking codes to EMR structures.
+Coding tables check this table for existence of their PK in
+.fk_generic_code in order to prevent cascading DELETEs/UPDATEs
+from breaking referential integrity.
+EMR structure tables foreign key into children of this table in
+order to link structures to codes.
+</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>cfg.v_cfg_options Structure</caption>
+                <caption>clin.lnk_code2item_root Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -48088,13 +62393,13 @@ end;</pre>
 				<td>
                 
                 </td>
-            	<td>option</td>
-            	<td>text</td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -48104,12 +62409,12 @@ end;</pre>
 				<td>
                 
                 </td>
-            	<td>description</td>
-            	<td>text</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -48120,13 +62425,13 @@ end;</pre>
 				<td>
                 
                 </td>
-            	<td>owner</td>
-            	<td>name</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -48136,13 +62441,13 @@ end;</pre>
 				<td>
                 
                 </td>
-            	<td>workplace</td>
-            	<td>text</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -48151,26 +62456,17 @@ end;</pre>
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>cookie</td>
-            	<td>text</td>
+            	<td>pk_lnk_code2item</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>type</td>
-            	<td>text</td>
-                <td><i>
+					
 				
 
 				
@@ -48180,27 +62476,27 @@ end;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>group</td>
-            	<td>text</td>
+            	<td>fk_generic_code</td>
+            	<td>integer</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>Custom foreign key to ref.coding_system_root.pk_coding_system.
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_cfg_template</td>
+            	<td>fk_item</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -48208,23 +62504,23 @@ end;</pre>
 				
 				
 				</i>
-				
+				<br><br>Foreign key to clin.* tables
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>pk_cfg_item</td>
-            	<td>integer</td>
+            	<td>code_modifier</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>Usage specific modifier on the base code, say, certainty or laterality of ICD-10 codes.
 				</td>
 			 </tr>
             
@@ -48232,11 +62528,35 @@ end;</pre>
 
         <!-- Inherits -->
 		
+        <p>Table clin.lnk_code2item_root Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
 
 		
+		
+		
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.lnk_code2item_root Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
@@ -48246,39 +62566,27 @@ end;</pre>
 
 	<!-- View Definition -->
 	
-	<pre>
-SELECT cfg_t.name AS option
-, cfg_t.description
-, cfg_i.owner
-, cfg_i.workplace
-, cfg_i.cookie
-, cfg_t.type
-, cfg_t.cfg_group AS "group"
-, cfg_t.pk AS pk_cfg_template
-, cfg_i.pk AS pk_cfg_item 
-FROM cfg.cfg_template cfg_t
-, cfg.cfg_item cfg_i 
-WHERE (cfg_i.fk_template = cfg_t.pk);</pre>
-	
 
 	<!-- List off permissions -->
 	
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
-		<h2>View:
+		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.view.v-cfg-opts-data">v_cfg_opts_data</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-code2narrative">lnk_code2narrative</a>
 		</h2>
         
+         <p>Links codes to SOAP narrative.</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>cfg.v_cfg_opts_data Structure</caption>
+                <caption>clin.lnk_code2narrative Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -48290,13 +62598,13 @@ WHERE (cfg_i.fk_template = cfg_t.pk);</pre>
 				<td>
                 
                 </td>
-            	<td>option</td>
-            	<td>text</td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -48306,12 +62614,12 @@ WHERE (cfg_i.fk_template = cfg_t.pk);</pre>
 				<td>
                 
                 </td>
-            	<td>value</td>
-            	<td>bytea</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -48322,13 +62630,13 @@ WHERE (cfg_i.fk_template = cfg_t.pk);</pre>
 				<td>
                 
                 </td>
-            	<td>description</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -48337,14 +62645,22 @@ WHERE (cfg_i.fk_template = cfg_t.pk);</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
-            	<td>owner</td>
+            	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
 
+					
 				
-				
+
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -48354,13 +62670,13 @@ WHERE (cfg_i.fk_template = cfg_t.pk);</pre>
 				<td>
                 
                 </td>
-            	<td>workplace</td>
-            	<td>text</td>
+            	<td>pk_lnk_code2item</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('lnk_code2item_root_pk_lnk_code2item_seq'::regclass)
 				</i>
 				
 				</td>
@@ -48369,32 +62685,56 @@ WHERE (cfg_i.fk_template = cfg_t.pk);</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>cookie</td>
-            	<td>text</td>
+            	<td>fk_generic_code</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
 
+					
+                       UNIQUE#1
+                    
 				
+
+				NOT NULL
 				
 				</i>
-				
+				<br><br>Custom foreign key to ref.coding_system_root.
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
+                  
+                
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.clin-narrative">clin.clin_narrative.pk</a>
+                  
+                
                 </td>
-            	<td>group</td>
-            	<td>text</td>
+            	<td>fk_item</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
 
+					
+                       UNIQUE#1
+                    
 				
+					
+
+					
+				
+
 				
-				</i>
 				
+				</i>
+				<br><br>Foreign key to clin.clin_narrative
 				</td>
 			 </tr>
             
@@ -48402,8 +62742,8 @@ WHERE (cfg_i.fk_template = cfg_t.pk);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_cfg_template</td>
-            	<td>integer</td>
+            	<td>code_modifier</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -48417,11 +62757,18 @@ WHERE (cfg_i.fk_template = cfg_t.pk);</pre>
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>pk_cfg_item</td>
-            	<td>integer</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
+
+					
+				
 
 				
 				
@@ -48434,57 +62781,67 @@ WHERE (cfg_i.fk_template = cfg_t.pk);</pre>
 
         <!-- Inherits -->
 		
+        <p>Table clin.lnk_code2narrative Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#clin.table.lnk-code2item-root">lnk_code2item_root</a>, 
+        
+        </p>
+		
 
 		
+		
+		
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.lnk_code2narrative Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
 
     <!-- Indexes -->
     
+       idx_c_lc2narr_fk_item fk_item
+    
 
 	<!-- View Definition -->
 	
-	<pre>
-SELECT cfg_t.name AS option
-, cfg_v.value
-, cfg_t.description
-, cfg_i.owner
-, cfg_i.workplace
-, cfg_i.cookie
-, cfg_t.cfg_group AS "group"
-, cfg_t.pk AS pk_cfg_template
-, cfg_i.pk AS pk_cfg_item 
-FROM cfg.cfg_template cfg_t
-, cfg.cfg_item cfg_i
-, cfg.cfg_data cfg_v 
-WHERE (
-     (cfg_i.fk_template = cfg_t.pk)
-   AND (cfg_v.fk_item = cfg_i.pk)
-);</pre>
-	
 
 	<!-- List off permissions -->
 	
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
-		<h2>View:
+		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.view.v-cfg-opts-numeric">v_cfg_opts_numeric</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-code2procedure">lnk_code2procedure</a>
 		</h2>
         
+         <p>Links codes to procedures. OPS comes to mind.</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>cfg.v_cfg_opts_numeric Structure</caption>
+                <caption>clin.lnk_code2procedure Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -48496,13 +62853,13 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>option</td>
-            	<td>text</td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -48512,12 +62869,12 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>value</td>
-            	<td>numeric</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -48528,13 +62885,13 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>description</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -48543,14 +62900,22 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
-            	<td>owner</td>
+            	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
 
+					
 				
-				
+
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -48560,13 +62925,13 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>workplace</td>
-            	<td>text</td>
+            	<td>pk_lnk_code2item</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('lnk_code2item_root_pk_lnk_code2item_seq'::regclass)
 				</i>
 				
 				</td>
@@ -48575,32 +62940,56 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>cookie</td>
-            	<td>text</td>
+            	<td>fk_generic_code</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
 
+					
+                       UNIQUE#1
+                    
 				
+
+				NOT NULL
 				
 				</i>
-				
+				<br><br>Custom foreign key to ref.coding_system_root.
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
+                  
+                
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.procedure">clin.procedure.pk</a>
+                  
+                
                 </td>
-            	<td>group</td>
-            	<td>text</td>
+            	<td>fk_item</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
+
+					
+                       UNIQUE#1
+                    
+				
+					
+
+					
+				
 
 				
 				
 				</i>
-				
+				<br><br>Foreign key to clin.procedure
 				</td>
 			 </tr>
             
@@ -48608,8 +62997,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_cfg_template</td>
-            	<td>integer</td>
+            	<td>code_modifier</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -48623,11 +63012,18 @@ WHERE (
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>pk_cfg_item</td>
-            	<td>integer</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
+
+					
+				
 
 				
 				
@@ -48640,57 +63036,67 @@ WHERE (
 
         <!-- Inherits -->
 		
+        <p>Table clin.lnk_code2procedure Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#clin.table.lnk-code2item-root">lnk_code2item_root</a>, 
+        
+        </p>
+		
 
 		
+		
+		
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.lnk_code2procedure Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
 
     <!-- Indexes -->
     
+       idx_c_lc2proc_fk_item fk_item
+    
 
 	<!-- View Definition -->
 	
-	<pre>
-SELECT cfg_t.name AS option
-, cfg_v.value
-, cfg_t.description
-, cfg_i.owner
-, cfg_i.workplace
-, cfg_i.cookie
-, cfg_t.cfg_group AS "group"
-, cfg_t.pk AS pk_cfg_template
-, cfg_i.pk AS pk_cfg_item 
-FROM cfg.cfg_template cfg_t
-, cfg.cfg_item cfg_i
-, cfg.cfg_numeric cfg_v 
-WHERE (
-     (cfg_i.fk_template = cfg_t.pk)
-   AND (cfg_v.fk_item = cfg_i.pk)
-);</pre>
-	
 
 	<!-- List off permissions -->
 	
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
-		<h2>View:
+		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.view.v-cfg-opts-str-array">v_cfg_opts_str_array</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-code2rfe">lnk_code2rfe</a>
 		</h2>
         
+         <p>Links codes to encounters.</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>cfg.v_cfg_opts_str_array Structure</caption>
+                <caption>clin.lnk_code2rfe Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -48702,13 +63108,13 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>option</td>
-            	<td>text</td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -48718,12 +63124,12 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>value</td>
-            	<td>text[]</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -48734,13 +63140,13 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>description</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -48749,14 +63155,22 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
-            	<td>owner</td>
+            	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
 
+					
 				
-				
+
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -48766,13 +63180,13 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>workplace</td>
-            	<td>text</td>
+            	<td>pk_lnk_code2item</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('lnk_code2item_root_pk_lnk_code2item_seq'::regclass)
 				</i>
 				
 				</td>
@@ -48781,32 +63195,56 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>cookie</td>
-            	<td>text</td>
+            	<td>fk_generic_code</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
 
+					
+                       UNIQUE#1
+                    
 				
+
+				NOT NULL
 				
 				</i>
-				
+				<br><br>Custom foreign key to ref.coding_system_root.
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
+                  
+                
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  
+                
                 </td>
-            	<td>group</td>
-            	<td>text</td>
+            	<td>fk_item</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
+
+					
+                       UNIQUE#1
+                    
+				
+					
 
+					
 				
+
 				
-				</i>
 				
+				</i>
+				<br><br>Foreign key to clin.encounter
 				</td>
 			 </tr>
             
@@ -48814,8 +63252,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_cfg_template</td>
-            	<td>integer</td>
+            	<td>code_modifier</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -48829,11 +63267,18 @@ WHERE (
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>pk_cfg_item</td>
-            	<td>integer</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
+
+					
+				
 
 				
 				
@@ -48846,57 +63291,67 @@ WHERE (
 
         <!-- Inherits -->
 		
+        <p>Table clin.lnk_code2rfe Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#clin.table.lnk-code2item-root">lnk_code2item_root</a>, 
+        
+        </p>
+		
 
 		
+		
+		
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.lnk_code2rfe Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
 
     <!-- Indexes -->
     
+       idx_c_lc2rfe_fk_item fk_item
+    
 
 	<!-- View Definition -->
 	
-	<pre>
-SELECT cfg_t.name AS option
-, cfg_v.value
-, cfg_t.description
-, cfg_i.owner
-, cfg_i.workplace
-, cfg_i.cookie
-, cfg_t.cfg_group AS "group"
-, cfg_t.pk AS pk_cfg_template
-, cfg_i.pk AS pk_cfg_item 
-FROM cfg.cfg_template cfg_t
-, cfg.cfg_item cfg_i
-, cfg.cfg_str_array cfg_v 
-WHERE (
-     (cfg_i.fk_template = cfg_t.pk)
-   AND (cfg_v.fk_item = cfg_i.pk)
-);</pre>
-	
 
 	<!-- List off permissions -->
 	
 
 	<p>
 		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
     </p>
 	
         <hr>
-		<h2>View:
+		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.view.v-cfg-opts-string">v_cfg_opts_string</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-code2tst-pnl">lnk_code2tst_pnl</a>
 		</h2>
         
+         <p>Links codes to test panels.</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>cfg.v_cfg_opts_string Structure</caption>
+                <caption>clin.lnk_code2tst_pnl Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -48908,13 +63363,13 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>option</td>
-            	<td>text</td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -48924,12 +63379,12 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>value</td>
-            	<td>text</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -48940,13 +63395,13 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>description</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -48955,46 +63410,22 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
-                </td>
-            	<td>owner</td>
-            	<td>name</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
                 
                 </td>
-            	<td>workplace</td>
-            	<td>text</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
+					
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>cookie</td>
-            	<td>text</td>
-                <td><i>
+					
 				
 
-				
-				
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -49004,13 +63435,13 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>group</td>
-            	<td>text</td>
+            	<td>pk_lnk_code2item</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('lnk_code2item_root_pk_lnk_code2item_seq'::regclass)
 				</i>
 				
 				</td>
@@ -49019,239 +63450,47 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
-                </td>
-            	<td>pk_cfg_template</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
+                  
                 
                 </td>
-            	<td>pk_cfg_item</td>
+            	<td>fk_generic_code</td>
             	<td>integer</td>
                 <td><i>
 				
+					
 
+					
+                       UNIQUE#1
+                    
 				
+
+				NOT NULL
 				
 				</i>
-				
+				<br><br>Custom foreign key to ref.coding_system_root.
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT cfg_t.name AS option
-, cfg_v.value
-, cfg_t.description
-, cfg_i.owner
-, cfg_i.workplace
-, cfg_i.cookie
-, cfg_t.cfg_group AS "group"
-, cfg_t.pk AS pk_cfg_template
-, cfg_i.pk AS pk_cfg_item 
-FROM cfg.cfg_template cfg_t
-, cfg.cfg_item cfg_i
-, cfg.cfg_string cfg_v 
-WHERE (
-     (cfg_i.fk_template = cfg_t.pk)
-   AND (cfg_v.fk_item = cfg_i.pk)
-);</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#cfg.schema">Schema cfg</a>
-    </p>
-	
-
-	<!-- We've gone through the table structure, now lets take a look at user functions -->
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.function.create-cfg-item-text-text-text-text-text">create_cfg_item(text, text, text, text, text)</a>
-		</h2>
-<h3>Returns: integer</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-declare
-	_option alias for $1;
-	_val_type alias for $2;
-	_workplace alias for $3;
-	_cookie alias for $4;
-	_owner alias for $5;
-	real_owner text;
-	pk_template integer;
-	pk_item integer;
-begin
-	-- check template
-	select into pk_template pk from cfg.cfg_template where name = _option and type = _val_type;
-	if not FOUND then
-		insert into cfg.cfg_template (name, type) values (_option, _val_type);
-		select into pk_template currval('cfg.cfg_template_pk_seq');
-	end if;
-	if _owner is null then
-		select into real_owner CURRENT_USER;
-	else
-		real_owner := _owner;
-	end if;
-	-- check item
-	if _cookie is NULL then
-		select into pk_item pk from cfg.cfg_item where
-			fk_template = pk_template and
-			owner = real_owner and
-			workplace = _workplace and
-			cookie is null;
-	else
-		select into pk_item pk from cfg.cfg_item where
-			fk_template = pk_template and
-			owner = real_owner and
-			workplace = _workplace and
-			cookie = _cookie;
-	end if;
-	if FOUND then
-		return pk_item;
-	end if;
-	insert into cfg.cfg_item (
-		fk_template, workplace, cookie, owner
-	) values (
-		pk_template,
-		_workplace,
-		_cookie,
-		real_owner
-	);
-	select into pk_item currval('cfg.cfg_item_pk_seq');
-	return pk_item;
-end;</pre>
-	
-		<hr>
-		<h2>Function:
-			<a href="gnumed-entire_schema.html#cfg.schema">cfg</a>.<a name="cfg.function.set-option-text-anyelement-text-text-text">set_option(text, anyelement, text, text, text)</a>
-		</h2>
-<h3>Returns: boolean</h3>
-<h3>Language: PLPGSQL</h3>
-        <p>set option, owner = NULL means CURRENT_USER</p>
-        <pre>
-declare
-	_option alias for $1;
-	_value alias for $2;
-	_workplace alias for $3;
-	_cookie alias for $4;
-	_owner alias for $5;
-	val_type text;
-	pk_item integer;
-	rows integer;
-	cmd text;
-begin
-	-- determine data type
-	if _value is of (text, char, varchar, name) then
-		val_type := 'string';
-	elsif _value is of (smallint, integer, bigint, numeric, boolean) then
-		val_type := 'numeric';
-	elsif _value is of (bytea) then
-		val_type := 'data';
-	elsif _value is of (text[]) then
-		val_type := 'str_array';
-	else
-		raise exception 'cfg.set_option(text, any, text, text, text): invalid type of value';
-	end if;
-	-- create template/item if need be
-	select into pk_item cfg.create_cfg_item(_option, val_type, _workplace, _cookie, _owner);
-	-- set item value
-	cmd := 'select 1 from cfg.cfg_' || val_type || ' where fk_item=' || pk_item || ';';
-	execute cmd;
-	get diagnostics rows = row_count;
-	found := rows <> 0;
-	if FOUND then
-		if val_type = 'str_array' then
-			cmd := 'update cfg.cfg_str_array set value=''{"' || array_to_string(_value, '","') || '"}'' where fk_item=' || pk_item || ';';
-		elsif val_type = 'data' then
-			cmd := 'update cfg.cfg_data set value=''' || encode(_value, 'escape') || ''' where fk_item=' || pk_item || ';';
-		else
-			cmd := 'update cfg.cfg_' || val_type || ' set value=' || quote_literal(_value) || ' where fk_item=' || pk_item || ';';
-		end if;
-		execute cmd;
-		return True;
-	end if;
-	if val_type = 'str_array' then
-		cmd := 'insert into cfg.cfg_str_array(fk_item, value) values (' || pk_item || ', ''{"' || array_to_string(_value, '","') || '"}'');';
-	elsif val_type = 'data' then
-		cmd := 'insert into cfg.cfg_data(fk_item, value) values (' || pk_item || ', ''' || encode(_value, 'escape') || ''');';
-	else
-		cmd := 'insert into cfg.cfg_' || val_type || ' (fk_item, value) values (' || pk_item || ', ' || quote_literal(_value) || ');';
-	end if;
-	execute cmd;
-	return True;
-end;</pre>
-	
-
-<!-- clinclin -->
-
-		
-		<hr>
-		<h1>Schema clin</h1>
-		
-
-		
-		
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.-enum-allergy-type">_enum_allergy_type</a>
-		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin._enum_allergy_type Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                   
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.test-panel">clin.test_panel.pk</a>
+                  
+                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>fk_item</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
+					
+
+					
+                       UNIQUE#1
+                    
+				
 					
 
 					
@@ -49260,28 +63499,43 @@ end;</pre>
 				
 				
 				</i>
-				
+				<br><br>Foreign key to clin.test_panel
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
+                </td>
+            	<td>code_modifier</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
                   
                 
                 </td>
-            	<td>value</td>
-            	<td>text</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
 					
 
 					
-                       UNIQUE
-                    
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -49292,6 +63546,13 @@ end;</pre>
 
         <!-- Inherits -->
 		
+        <p>Table clin.lnk_code2tst_pnl Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#clin.table.lnk-code2item-root">lnk_code2item_root</a>, 
+        
+        </p>
+		
 
 		
 		
@@ -49299,19 +63560,29 @@ end;</pre>
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.lnk_code2tst_pnl Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.allergy">clin.allergy</a></li>
-			</ul>
-		
-		
 
     <!-- Indexes -->
     
+       idx_c_lc2tp_fk_item fk_item
+    
 
 	<!-- View Definition -->
 	
@@ -49327,15 +63598,15 @@ end;</pre>
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.allergy">allergy</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-constraint2vacc-course">lnk_constraint2vacc_course</a>
 		</h2>
         
-         <p>patient allergy details</p>
+         <p>links constraints to courses</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.allergy Structure</caption>
+                <caption>clin.lnk_constraint2vacc_course Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -49394,11 +63665,19 @@ end;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -49410,44 +63689,37 @@ end;</pre>
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>pk_item</td>
-            	<td>integer</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
 
-				NOT NULL
-				DEFAULT nextval('clin_root_item_pk_item_seq'::regclass)
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
+					
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  <a href="gnumed-entire_schema.html#clin.table.vaccination-course">clin.vaccination_course.pk</a>
+                  
+                
                   
                 
                 </td>
-            	<td>fk_encounter</td>
+            	<td>fk_vaccination_course</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -49455,6 +63727,12 @@ end;</pre>
 
 					
 				
+					
+
+					
+                       UNIQUE#1
+                    
+				
 
 				NOT NULL
 				
@@ -49463,15 +63741,17 @@ end;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
+                  <a href="gnumed-entire_schema.html#clin.table.vaccination-course-constraint">clin.vaccination_course_constraint.pk</a>
+                  
+                
                   
                 
                 </td>
-            	<td>fk_episode</td>
+            	<td>fk_constraint</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -49479,6 +63759,12 @@ end;</pre>
 
 					
 				
+					
+
+					
+                       UNIQUE#1
+                    
+				
 
 				NOT NULL
 				
@@ -49487,56 +63773,91 @@ end;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>narrative</td>
-            	<td>text</td>
-                <td><i>
-				
+        </table>
 
-				
-				
-				</i>
-				<br><br>used as field "reaction"
-				</td>
-			 </tr>
+        <!-- Inherits -->
+		
+        <p>Table clin.lnk_constraint2vacc_course Inherits
+        
             
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
-                <td><i>
-				
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
 
-				
-				DEFAULT 'o'::text
-				</i>
-				
-				</td>
-			 </tr>
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.lnk_constraint2vacc_course Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-pat2vaccination-course">lnk_pat2vaccination_course</a>
+		</h2>
+        
+         <p>links patients to vaccination courses they are actually on,
+	 this allows for per-patient selection of courses to be
+	 followed, eg. children at different ages may be on different
+	 vaccination courses or some people are on a course due
+	 to a trip abroad while most others are not</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.lnk_pat2vaccination_course Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -49546,15 +63867,15 @@ end;</pre>
 				<td>
                 
                 </td>
-            	<td>substance</td>
-            	<td>text</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
 				NOT NULL
 				
 				</i>
-				<br><br>real-world name of substance the patient reacted to, brand name if drug
+				
 				</td>
 			 </tr>
             
@@ -49562,79 +63883,76 @@ end;</pre>
 				<td>
                 
                 </td>
-            	<td>substance_code</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT now()
 				</i>
-				<br><br>data source specific opaque product code; must provide a link
-	 to a unique product/substance in the database in use; should follow
-	 the parseable convention of "<source>::<source version>::<identifier>",
-	 e.g. "MIMS::2003-1::190" for Zantac; it is left as an exercise to the
-	 application to know what to do with this information
+				
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
-            	<td>generics</td>
-            	<td>text</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
+					
 
+					
 				
-				
+
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
-				<br><br>names of generic compounds if drug; brand names change/disappear, generic names do not
+				
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>allergene</td>
-            	<td>text</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
 
-				
-				
-				</i>
-				<br><br>name of allergenic ingredient in substance if known
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>atc_code</td>
-            	<td>text</td>
-                <td><i>
+					
 				
 
 				
 				
 				</i>
-				<br><br>ATC code of allergene or substance if approprate, applicable for penicilline, not so for cat fur
+				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.-enum-allergy-type">clin._enum_allergy_type.pk</a>
+                  <a href="gnumed-entire_schema.html#clin.table.patient">clin.patient.fk_identity</a>
+                  
+                
                   
                 
                 </td>
-            	<td>fk_type</td>
+            	<td>fk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -49642,47 +63960,49 @@ end;</pre>
 
 					
 				
+					
+
+					
+                       UNIQUE#1
+                    
+				
 
 				NOT NULL
 				
 				</i>
-				<br><br>allergy/sensitivity
+				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.vaccination-course">clin.vaccination_course.pk</a>
+                  
+                
+                  
+                
                 </td>
-            	<td>generic_specific</td>
-            	<td>boolean</td>
+            	<td>fk_course</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
 
+					
 				
-				DEFAULT false
-				</i>
-				<br><br>only meaningful for *drug*/*generic* reactions:
-	 1) true: applies to one in "generics" forming "substance",
-			  if more than one generic listed in "generics" then
-			  "allergene" *must* contain the generic in question;
-	 2) false: applies to drug class of "substance";
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>definite</td>
-            	<td>boolean</td>
-                <td><i>
+					
+
+					
+                       UNIQUE#1
+                    
 				
 
+				NOT NULL
 				
-				DEFAULT false
 				</i>
-				<br><br>true: definite, false: not definite
+				
 				</td>
 			 </tr>
             
@@ -49690,10 +64010,10 @@ end;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table clin.allergy Inherits
+        <p>Table clin.lnk_pat2vaccination_course Inherits
         
             
-           <a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin_root_item</a>, 
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
         
         </p>
 		
@@ -49706,15 +64026,15 @@ end;</pre>
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.allergy Constraints</caption>
+            <caption>clin.lnk_pat2vaccination_course Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
-				<td>clin_root_item_sane_soap_cat</td>
-                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
             </tr>
 			
 		</table>
@@ -49725,10 +64045,6 @@ end;</pre>
 
     <!-- Indexes -->
     
-       idx_clin_allergy_fk_encounter fk_encounter
-    
-       idx_clin_allergy_fk_episode fk_episode
-    
 
 	<!-- View Definition -->
 	
@@ -49744,13 +64060,13 @@ end;</pre>
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.allergy-state">allergy_state</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-substance2episode">lnk_substance2episode</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.allergy_state Structure</caption>
+                <caption>clin.lnk_substance2episode Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -49848,53 +64164,24 @@ end;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
+                  
+                
                 </td>
-            	<td>has_allergy</td>
+            	<td>fk_episode</td>
             	<td>integer</td>
                 <td><i>
 				
+					
 
-				
-				
-				</i>
-				<br><br>patient allergenic state:
-	 - null: unknown, not asked, no data available
-	 - -1: unknown, asked, no data obtained
-	 - 0:  known, asked, has no known allergies
-	 - 1:  known, asked, does have allergies
-	
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>comment</td>
-            	<td>text</td>
-                <td><i>
+					
 				
 
 				
 				
 				</i>
-				<br><br>A comment on the state, such as "patient says no allergies but I think he is holding back some".
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>last_confirmed</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
 				
-				</i>
-				<br><br>When was the state of allergies last confirmed. Must be not NULL if has_allergy is not NULL.
 				</td>
 			 </tr>
             
@@ -49902,11 +64189,11 @@ end;</pre>
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  <a href="gnumed-entire_schema.html#clin.table.substance-intake">clin.substance_intake.pk</a>
                   
                 
                 </td>
-            	<td>fk_encounter</td>
+            	<td>fk_substance</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -49915,7 +64202,7 @@ end;</pre>
 					
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -49926,7 +64213,7 @@ end;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table clin.allergy_state Inherits
+        <p>Table clin.lnk_substance2episode Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
@@ -49942,20 +64229,15 @@ end;</pre>
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.allergy_state Constraints</caption>
+            <caption>clin.lnk_substance2episode Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
-				<td>allergy_state_check</td>
-                <td>CHECK (((has_allergy IS NULL) OR ((has_allergy IS NOT NULL) AND (last_confirmed IS NOT NULL))))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>allergy_state_has_allergy_check</td>
-                <td>CHECK ((has_allergy = ANY (ARRAY[NULL::integer, 0, 1])))</td>
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
             </tr>
 			
 		</table>
@@ -49981,15 +64263,15 @@ end;</pre>
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.clin-aux-note">clin_aux_note</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-tst2norm">lnk_tst2norm</a>
 		</h2>
         
-         <p>Other tables link to this if they need more free text fields.</p>
+         <p>links test result evaluation norms to tests</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.clin_aux_note Structure</caption>
+                <caption>clin.lnk_tst2norm Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -50029,89 +64311,17 @@ end;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT now()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>modified_by</td>
-            	<td>name</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT "current_user"()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_item</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT nextval('clin_root_item_pk_item_seq'::regclass)
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT now()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
-                  
+            <tr class="tr0">
+				<td>
                 
                 </td>
-            	<td>fk_encounter</td>
-            	<td>integer</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
-					
-
-					
-				
 
 				NOT NULL
-				
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -50121,12 +64331,12 @@ end;</pre>
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
                   
                 
                 </td>
-            	<td>fk_episode</td>
-            	<td>integer</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 					
@@ -50135,7 +64345,7 @@ end;</pre>
 				
 
 				NOT NULL
-				
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -50144,11 +64354,18 @@ end;</pre>
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>narrative</td>
-            	<td>text</td>
+            	<td>id</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
+
+					
+				
 
 				
 				
@@ -50160,16 +64377,32 @@ end;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.test-type">clin.test_type.pk</a>
+                  
+                
+                  
+                
                 </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>id_test</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
 
+					
 				
+					
+
+					
+                       UNIQUE#1
+                    
 				
-				</i>
+
+				NOT NULL
 				
+				</i>
+				<br><br>which test does the linked norm apply to
 				</td>
 			 </tr>
             
@@ -50179,20 +64412,21 @@ end;</pre>
                   
                 
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>id_norm</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
 					
 
 					
+                       UNIQUE#1
+                    
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>the norm to apply to the linked test
 				</td>
 			 </tr>
             
@@ -50200,10 +64434,10 @@ end;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table clin.clin_aux_note Inherits
+        <p>Table clin.lnk_tst2norm Inherits
         
             
-           <a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin_root_item</a>, 
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
         
         </p>
 		
@@ -50216,15 +64450,15 @@ end;</pre>
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.clin_aux_note Constraints</caption>
+            <caption>clin.lnk_tst2norm Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
-				<td>clin_root_item_sane_soap_cat</td>
-                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
             </tr>
 			
 		</table>
@@ -50235,10 +64469,6 @@ end;</pre>
 
     <!-- Indexes -->
     
-       idx_clin_clin_aux_note_fk_encounter fk_encounter
-    
-       idx_clin_clin_aux_note_fk_episode fk_episode
-    
 
 	<!-- View Definition -->
 	
@@ -50254,17 +64484,15 @@ end;</pre>
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.clin-diag">clin_diag</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-type2item">lnk_type2item</a>
 		</h2>
         
-         <p>stores additional detail on those clin.clin_narrative
-	 rows where soap_cat=a that are true diagnoses,
-	 true diagnoses DO have a code from one of the coding systems</p>
+         <p>allow to link many-to-many between clin.clin_root_item and clin.clin_item_type</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.clin_diag Structure</caption>
+                <caption>clin.lnk_type2item Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -50323,11 +64551,19 @@ end;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -50363,13 +64599,13 @@ end;</pre>
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.clin-narrative">clin.clin_narrative.pk</a>
+                  <a href="gnumed-entire_schema.html#clin.table.clin-item-type">clin.clin_item_type.pk</a>
                   
                 
                   
                 
                 </td>
-            	<td>fk_narrative</td>
+            	<td>fk_type</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -50380,7 +64616,7 @@ end;</pre>
 					
 
 					
-                       UNIQUE
+                       UNIQUE#1
                     
 				
 
@@ -50394,87 +64630,29 @@ end;</pre>
             <tr class="tr0">
 				<td>
                 
-                </td>
-            	<td>laterality</td>
-            	<td>character(1)</td>
-                <td><i>
-				
-
-				
-				DEFAULT NULL::bpchar
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>is_chronic</td>
-            	<td>boolean</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT false
-				</i>
-				<br><br>whether this diagnosis is chronic, eg. no complete
-	 cure is to be expected, regardless of whether it is
-	 *active* right now (think of active/non-active phases
-	 of Multiple Sclerosis which is sure chronic)
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
+                  
                 
                 </td>
-            	<td>is_active</td>
-            	<td>boolean</td>
+            	<td>fk_item</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
 
-				NOT NULL
-				DEFAULT true
-				</i>
-				<br><br>whether diagnosis is currently active or dormant
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>is_definite</td>
-            	<td>boolean</td>
-                <td><i>
+					
+                       UNIQUE#1
+                    
 				
 
 				NOT NULL
-				DEFAULT false
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>clinically_relevant</td>
-            	<td>boolean</td>
-                <td><i>
 				
-
-				NOT NULL
-				DEFAULT true
 				</i>
-				<br><br>whether this diagnosis is considered clinically
-	 relevant, eg. significant;
-	 currently active diagnoses are considered to
-	 always be relevant, while inactive ones may
-	 or may not be
+				<br><br>the item this type is linked to,
+	 since PostgreSQL apparently cannot reference a value
+	 inserted from a child table (?) we must simulate
+	 referential integrity checks with a custom trigger,
+	 this, however, does not deal with update/delete
+	 cascading :-(
 				</td>
 			 </tr>
             
@@ -50482,7 +64660,7 @@ end;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table clin.clin_diag Inherits
+        <p>Table clin.lnk_type2item Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
@@ -50498,20 +64676,15 @@ end;</pre>
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.clin_diag Constraints</caption>
+            <caption>clin.lnk_type2item Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
-				<td>clin_diag_laterality_check</td>
-                <td>CHECK (((laterality = ANY (ARRAY['l'::bpchar, 'r'::bpchar, 'b'::bpchar, '?'::bpchar])) OR (laterality IS NULL)))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>if_active_then_relevant</td>
-                <td>CHECK (((is_active = false) OR ((is_active = true) AND (clinically_relevant = true))))</td>
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
             </tr>
 			
 		</table>
@@ -50537,15 +64710,17 @@ end;</pre>
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.clin-item-type">clin_item_type</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-vaccination-course2schedule">lnk_vaccination_course2schedule</a>
 		</h2>
         
-         <p>stores arbitrary types for tagging clinical items</p>
+         <p>this table links vaccination courses for a single epitope
+	 into schedules defined and recommended by a vaccination
+	 council or similar entity</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.clin_item_type Structure</caption>
+                <caption>clin.lnk_vaccination_course2schedule Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -50604,11 +64779,19 @@ end;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -50644,23 +64827,31 @@ end;</pre>
 				<td>
                 
                   
+                  <a href="gnumed-entire_schema.html#clin.table.vaccination-course">clin.vaccination_course.pk</a>
+                  
+                
+                  
                 
                 </td>
-            	<td>type</td>
-            	<td>text</td>
+            	<td>fk_course</td>
+            	<td>integer</td>
                 <td><i>
 				
 					
 
 					
+				
+					
+
+					
                        UNIQUE
                     
 				
 
 				NOT NULL
-				DEFAULT 'history'::text
+				
 				</i>
-				<br><br>the full name of the item type such as "family history"
+				
 				</td>
 			 </tr>
             
@@ -50668,23 +64859,23 @@ end;</pre>
 				<td>
                 
                   
+                  <a href="gnumed-entire_schema.html#clin.table.vaccination-schedule">clin.vaccination_schedule.pk</a>
+                  
                 
                 </td>
-            	<td>code</td>
-            	<td>text</td>
+            	<td>fk_schedule</td>
+            	<td>integer</td>
                 <td><i>
 				
 					
 
 					
-                       UNIQUE
-                    
 				
 
 				NOT NULL
-				DEFAULT 'Hx'::text
+				
 				</i>
-				<br><br>shorthand for the type, eg "FHx"
+				
 				</td>
 			 </tr>
             
@@ -50692,7 +64883,7 @@ end;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table clin.clin_item_type Inherits
+        <p>Table clin.lnk_vaccination_course2schedule Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
@@ -50706,16 +64897,24 @@ end;</pre>
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.lnk_vaccination_course2schedule Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.lnk-type2item">clin.lnk_type2item</a></li>
-			</ul>
-		
-		
 
     <!-- Indexes -->
     
@@ -50734,18 +64933,15 @@ end;</pre>
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.clin-narrative">clin_narrative</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-vaccine2inds">lnk_vaccine2inds</a>
 		</h2>
         
-         <p>Used to store clinical free text *not* associated
-	 with any other table. Used to implement a simple
-	 SOAP structure. Also other tags can be associated
-	 via link tables.</p>
+         <p>links vaccines to their indications</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.clin_narrative Structure</caption>
+                <caption>clin.lnk_vaccine2inds Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -50804,69 +65000,44 @@ end;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
 
-				NOT NULL
-				DEFAULT "current_user"()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_item</td>
-            	<td>integer</td>
-                <td><i>
+					
 				
 
 				NOT NULL
-				DEFAULT nextval('clin_root_item_pk_item_seq'::regclass)
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT now()
-				</i>
-				<br><br>when did the item reach clinical reality
-				</td>
-			 </tr>
-            
             <tr class="tr0">
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
-                  
                 
                 </td>
-            	<td>fk_encounter</td>
-            	<td>integer</td>
+            	<td>id</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
 					
 
 					
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -50877,11 +65048,13 @@ end;</pre>
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
+                  <a href="gnumed-entire_schema.html#clin.table.vaccine">clin.vaccine.pk</a>
+                  
+                
                   
                 
                 </td>
-            	<td>fk_episode</td>
+            	<td>fk_vaccine</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -50889,40 +65062,14 @@ end;</pre>
 
 					
 				
+					
 
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>narrative</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
-                <td><i>
+					
+                       UNIQUE#1
+                    
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -50933,19 +65080,28 @@ end;</pre>
 				<td>
                 
                   
+                  <a href="gnumed-entire_schema.html#clin.table.vacc-indication">clin.vacc_indication.id</a>
+                  
+                
+                  
                 
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>fk_indication</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
 					
 
 					
 				
+					
 
+					
+                       UNIQUE#1
+                    
 				
+
+				NOT NULL
 				
 				</i>
 				
@@ -50956,10 +65112,10 @@ end;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table clin.clin_narrative Inherits
+        <p>Table clin.lnk_vaccine2inds Inherits
         
             
-           <a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin_root_item</a>, 
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
         
         </p>
 		
@@ -50972,20 +65128,15 @@ end;</pre>
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.clin_narrative Constraints</caption>
+            <caption>clin.lnk_vaccine2inds Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
-				<td>clin_root_item_sane_soap_cat</td>
-                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>narrative_neither_null_nor_empty</td>
-                <td>CHECK ((btrim(COALESCE(narrative, ''::text)) <> ''::text))</td>
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
             </tr>
 			
 		</table>
@@ -50993,27 +65144,12 @@ end;</pre>
 
         <!-- Foreign Key Discovery -->
 		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.clin-diag">clin.clin_diag</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2narrative">clin.lnk_code2narrative</a></li>
-			</ul>
-		
-		
 
     <!-- Indexes -->
     
-       idx_clin_clin_narrative_fk_encounter fk_encounter
-    
-       idx_clin_clin_narrative_fk_episode fk_episode
-    
-       idx_narrative_modified_by modified_by
+       idx_clin_lnk_vaccine2inds_fk_ind fk_indication
     
-       idx_narrative_soap_cat soap_cat) WHERE (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text])
+       idx_clin_lnk_vaccine2inds_fk_vacc fk_vaccine
     
 
 	<!-- View Definition -->
@@ -51030,20 +65166,19 @@ end;</pre>
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.clin-root-item">clin_root_item</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.meta-test-type">meta_test_type</a>
 		</h2>
         
-         <p>ancestor table for clinical items of any kind, basic
-	 unit of clinical information, do *not* store data in
-	 here directly, use child tables,
-	 contains all the clinical narrative aggregated for full
-	 text search, ancestor for all tables that want to store
-	 clinical free text</p>
+         <p>this table merges test types from various test orgs
+	 which are intended to measure the same value but have
+	 differing names into one logical test type,
+	 this is not intended to be used for aggregating
+	 semantically different test types into "profiles"</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.clin_root_item Structure</caption>
+                <caption>clin.meta_test_type Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -51054,74 +65189,10 @@ end;</pre>
             <tr class="tr0">
 				<td>
                 
-                </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>row_version</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT now()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>modified_by</td>
-            	<td>name</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT "current_user"()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
                   
                 
                 </td>
-            	<td>pk_item</td>
+            	<td>pk</td>
             	<td>serial</td>
                 <td><i>
 				
@@ -51134,83 +65205,63 @@ end;</pre>
 				
 				
 				</i>
-				<br><br>the primary key, not named "id" or "pk" as usual since child
-	 tables will have "id"/"pk"-named primary keys already and
-	 we would get duplicate columns while inheriting from this
-	 table
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
 				
-
-				NOT NULL
-				DEFAULT now()
-				</i>
-				<br><br>when this clinical item became known, can be different from
-	 when it was entered into the system (= audit.audit_fields.modified_when)
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
-                  
                 
                 </td>
-            	<td>fk_encounter</td>
-            	<td>integer</td>
+            	<td>abbrev</td>
+            	<td>text</td>
                 <td><i>
 				
 					
 
 					
+                       UNIQUE#1
+                    
 				
 
 				NOT NULL
 				
 				</i>
-				<br><br>the encounter this item belongs to
+				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
-                
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
+                
                   
                 
                 </td>
-            	<td>fk_episode</td>
-            	<td>integer</td>
+            	<td>name</td>
+            	<td>text</td>
                 <td><i>
 				
 					
 
 					
+                       UNIQUE#1
+                    
 				
 
 				NOT NULL
 				
 				</i>
-				<br><br>the episode this item belongs to
+				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>narrative</td>
+            	<td>loinc</td>
             	<td>text</td>
                 <td><i>
 				
@@ -51218,15 +65269,15 @@ end;</pre>
 				
 				
 				</i>
-				<br><br>each clinical item by default inherits a free text field for clinical narrative
+				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
+            	<td>comment</td>
             	<td>text</td>
                 <td><i>
 				
@@ -51234,8 +65285,7 @@ end;</pre>
 				
 				
 				</i>
-				<br><br>each clinical item must be either one of the S, O, A, P, U
-	 categories or NULL to indicate a non-clinical item, U meaning Unspecified-but-clinical
+				
 				</td>
 			 </tr>
             
@@ -51243,13 +65293,6 @@ end;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table clin.clin_root_item Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
 
 		
 		
@@ -51257,31 +65300,19 @@ end;</pre>
 
         <!-- Constraint List -->
 		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.clin_root_item Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>clin_root_item_sane_soap_cat</td>
-                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
-            </tr>
-			
-		</table>
-		
 
         <!-- Foreign Key Discovery -->
 		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.test-type">clin.test_type</a></li>
+			</ul>
+		
+		
 
     <!-- Indexes -->
     
-       idx_cri_encounter fk_encounter
-    
-       idx_cri_episode fk_episode
-    
 
 	<!-- View Definition -->
 	
@@ -51297,15 +65328,15 @@ end;</pre>
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.encounter">encounter</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.patient">patient</a>
 		</h2>
         
-         <p>a clinical encounter between a person and the health care system</p>
+         <p>A table to hold unique-per-identity *clinical* items, such as Expected Due Date.</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.encounter Structure</caption>
+                <caption>clin.patient Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -51364,11 +65395,19 @@ end;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -51404,61 +65443,21 @@ end;</pre>
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.patient">clin.patient.fk_identity</a>
-                  
-                
-                </td>
-            	<td>fk_patient</td>
-            	<td>integer</td>
-                <td><i>
-				
-					
-
-					
-				
-
-				NOT NULL
-				
-				</i>
-				<br><br>PK of subject of care, should be PUPIC, actually
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.encounter-type">clin.encounter_type.pk</a>
+                  <a href="gnumed-entire_schema.html#dem.table.identity">dem.identity.pk</a>
                   
                 
                 </td>
-            	<td>fk_type</td>
+            	<td>fk_identity</td>
             	<td>integer</td>
                 <td><i>
 				
 					
 
 					
-				
-
-				NOT NULL
-				DEFAULT 1
-				</i>
-				<br><br>PK of type of this encounter
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.org-unit">dem.org_unit.pk</a>
-                  
-                
-                </td>
-            	<td>fk_location</td>
-            	<td>integer</td>
-                <td><i>
+                       UNIQUE
+                    
 				
 					
 
@@ -51468,42 +65467,7 @@ end;</pre>
 				NOT NULL
 				
 				</i>
-				<br><br>PK of location *of care*, e.g. where the provider is at
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>source_time_zone</td>
-            	<td>interval</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				<br><br>time zone of location, used to approximate source time
-	 zone for all timestamps in this encounter
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>reason_for_encounter</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				<br><br>the RFE for the encounter as related by either
-	 the patient or the provider (say, in a chart
-	 review)
+				<br><br>the dem.identity.pk of this patient
 				</td>
 			 </tr>
             
@@ -51511,48 +65475,13 @@ end;</pre>
 				<td>
                 
                 </td>
-            	<td>assessment_of_encounter</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				<br><br>the Assessment of Encounter (eg consultation summary)
-	 as determined by the provider, may simply be a
-	 concatenation of soAp narrative, this assessment
-	 should go across all problems
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>started</td>
-            	<td>timestamp with time zone</td>
+            	<td>edc</td>
+            	<td>date</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
-				</i>
 				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>last_affirmed</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
 				
-
-				NOT NULL
-				DEFAULT now()
 				</i>
 				
 				</td>
@@ -51562,7 +65491,7 @@ end;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table clin.encounter Inherits
+        <p>Table clin.patient Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
@@ -51578,25 +65507,20 @@ end;</pre>
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.encounter Constraints</caption>
+            <caption>clin.patient Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
-				<td>clin_enc_sane_duration</td>
-                <td>CHECK ((last_affirmed >= started))</td>
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
             </tr>
 			
             <tr class="tr1">
-				<td>encounter_assessment_of_encounter_check</td>
-                <td>CHECK ((btrim(COALESCE(assessment_of_encounter, 'xxxDEFAULTxxx'::text)) <> ''::text))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>encounter_reason_for_encounter_check</td>
-                <td>CHECK ((btrim(COALESCE(reason_for_encounter, 'xxxDEFAULTxxx'::text)) <> ''::text))</td>
+				<td>clin_patient_sane_edc</td>
+                <td>CHECK (((edc IS NULL) OR ((clin.get_dod(fk_identity) IS NULL) AND ((clin.get_dob(fk_identity) IS NULL) OR (edc > (clin.get_dob(fk_identity) + '5 years'::interval))))))</td>
             </tr>
 			
 		</table>
@@ -51607,107 +65531,25 @@ end;</pre>
 			<p>Tables referencing this one via Foreign Key Constraints:</p>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#au.table.referral">au.referral</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#bill.table.bill-item">bill.bill_item</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#blobs.table.doc-med">blobs.doc_med</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.allergy">clin.allergy</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.allergy-state">clin.allergy_state</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.clin-aux-note">clin.clin_aux_note</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.clin-narrative">clin.clin_narrative</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin.clin_root_item</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.episode">clin.episode</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.external-care">clin.external_care</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.family-history">clin.family_history</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.form-instances">clin.form_instances</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.health-issue">clin.health_issue</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.hospital-stay">clin.hospital_stay</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.lab-request">clin.lab_request</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2aoe">clin.lnk_code2aoe</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2rfe">clin.lnk_code2rfe</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.procedure">clin.procedure</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.substance-intake">clin.substance_intake</a></li>
+				<li><a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter</a></li>
 			</ul>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.suppressed-hint">clin.suppressed_hint</a></li>
+				<li><a href="gnumed-entire_schema.html#clin.table.export-item">clin.export_item</a></li>
 			</ul>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.test-result">clin.test_result</a></li>
+				<li><a href="gnumed-entire_schema.html#clin.table.incoming-data-unmatched">clin.incoming_data_unmatched</a></li>
 			</ul>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.vaccination">clin.vaccination</a></li>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-pat2vaccination-course">clin.lnk_pat2vaccination_course</a></li>
 			</ul>
 		
 		
 
     <!-- Indexes -->
     
-       idx_clin_encounter_fk_location fk_location
-    
-       idx_encounter_affirmed last_affirmed
-    
-       idx_encounter_modified_by modified_by
-    
-       idx_encounter_started started
-    
-       idx_pat_per_encounter fk_patient
-    
 
 	<!-- View Definition -->
 	
@@ -51723,15 +65565,16 @@ end;</pre>
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.encounter-type">encounter_type</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.procedure">procedure</a>
 		</h2>
         
-         <p>these are the types of encounter</p>
+         <p>This table holds procedure/operations performed on the patient
+ both in hospital or in community care.</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.encounter_type Structure</caption>
+                <caption>clin.procedure Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -51742,21 +65585,14 @@ end;</pre>
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -51765,19 +65601,11 @@ end;</pre>
             <tr class="tr1">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>description</td>
-            	<td>text</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
-					
-
-					
-                       UNIQUE
-                    
-				
 
 				NOT NULL
 				
@@ -51786,80 +65614,17 @@ end;</pre>
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#bill.table.lnk-enc-type2billable">bill.lnk_enc_type2billable</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter</a></li>
-			</ul>
-		
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.episode">episode</a>
-		</h2>
-        
-         <p>Clinical episodes such as "Otitis media",
-	 "traffic accident 7/99", "Hepatitis B".
-	 This covers a range of time in which
-	 activity of illness was noted for the
-	 problem episode.description.</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.episode Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
 				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -51868,14 +65633,22 @@ end;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
-				
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -51885,13 +65658,13 @@ end;</pre>
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_item</td>
+            	<td>integer</td>
                 <td><i>
 				
 
 				NOT NULL
-				DEFAULT now()
+				DEFAULT nextval('clin_root_item_pk_item_seq'::regclass)
 				</i>
 				
 				</td>
@@ -51901,13 +65674,13 @@ end;</pre>
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
 				NOT NULL
-				DEFAULT "current_user"()
+				DEFAULT now()
 				</i>
 				
 				</td>
@@ -51917,19 +65690,20 @@ end;</pre>
 				<td>
                 
                   
+                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  
                 
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
 					
 
 					
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -51940,11 +65714,11 @@ end;</pre>
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.health-issue">clin.health_issue.pk</a>
+                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
                   
                 
                 </td>
-            	<td>fk_health_issue</td>
+            	<td>fk_episode</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -51953,10 +65727,10 @@ end;</pre>
 					
 				
 
-				
+				NOT NULL
 				
 				</i>
-				<br><br>health issue this episode belongs to
+				
 				</td>
 			 </tr>
             
@@ -51964,15 +65738,15 @@ end;</pre>
 				<td>
                 
                 </td>
-            	<td>description</td>
+            	<td>narrative</td>
             	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>description/name of this episode
+				<br><br>Which procedure/operation was performed.
 				</td>
 			 </tr>
             
@@ -51980,17 +65754,15 @@ end;</pre>
 				<td>
                 
                 </td>
-            	<td>is_open</td>
-            	<td>boolean</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
-				DEFAULT true
+				DEFAULT 'p'::text
 				</i>
-				<br><br>whether the episode is open (eg. there is activity for it),
-	 means open in a temporal sense as in "not closed yet";
-	 only one episode can be open per health issue
+				
 				</td>
 			 </tr>
             
@@ -51998,11 +65770,34 @@ end;</pre>
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.hospital-stay">clin.hospital_stay.pk</a>
                   
                 
                 </td>
-            	<td>fk_encounter</td>
+            	<td>fk_hospital_stay</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -52011,10 +65806,29 @@ end;</pre>
 					
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>The encounter during which this episode was added (begun).
+				<br><br>At which hospital was the procedure performed,
+ unless clin_where is not null,
+ if null it was an ambulatory procedure.
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>clin_end</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>When did this procedure end/is expected to end.
+- NULL if unknown or .clin_when (=start) is sufficient (eg. insignificant duration)
 				</td>
 			 </tr>
             
@@ -52022,35 +65836,39 @@ end;</pre>
 				<td>
                 
                 </td>
-            	<td>diagnostic_certainty_classification</td>
-            	<td>text</td>
+            	<td>is_ongoing</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				
-				
+				NOT NULL
+				DEFAULT false
 				</i>
-				<br><br>The certainty at which this problem is believed to be a diagnosis:
-A: sign (Symptom)
-B: cluster of signs (Symptomkomplex)
-C: syndromic diagnosis (Bild einer Diagnose)
-D: proven diagnosis (diagnostisch gesichert)
+				<br><br>Whether this procedure is still going on (such as desensibilisation, chemotherapy, etc).
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.org-unit">dem.org_unit.pk</a>
+                  
+                
                 </td>
-            	<td>summary</td>
-            	<td>text</td>
+            	<td>fk_org_unit</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				
 				
 				</i>
-				<br><br>Used for tracking the summary of this episode.
+				<br><br>links to the or unit the procedure was performed at
 				</td>
 			 </tr>
             
@@ -52058,10 +65876,10 @@ D: proven diagnosis (diagnostisch gesichert)
 
         <!-- Inherits -->
 		
-        <p>Table clin.episode Inherits
+        <p>Table clin.procedure Inherits
         
             
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+           <a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin_root_item</a>, 
         
         </p>
 		
@@ -52074,25 +65892,40 @@ D: proven diagnosis (diagnostisch gesichert)
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.episode Constraints</caption>
+            <caption>clin.procedure Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
-				<td>episode_sane_summary</td>
-                <td>CHECK (gm.is_null_or_non_empty_string(summary))</td>
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
             </tr>
 			
             <tr class="tr1">
-				<td>sane_description</td>
-                <td>CHECK ((gm.is_null_or_blank_string(description) IS FALSE))</td>
+				<td>clin_procedure_lnk_org_or_stay</td>
+                <td>CHECK ((((fk_hospital_stay IS NULL) AND (fk_org_unit IS NOT NULL)) OR ((fk_hospital_stay IS NOT NULL) AND (fk_org_unit IS NULL))))</td>
             </tr>
 			
             <tr class="tr0">
-				<td>valid_diagnostic_certainty_classification</td>
-                <td>CHECK ((diagnostic_certainty_classification = ANY (ARRAY['A'::text, 'B'::text, 'C'::text, 'D'::text, NULL::text])))</td>
+				<td>clin_root_item_sane_soap_cat</td>
+                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>procedure_sane_end</td>
+                <td>CHECK (((clin_end IS NULL) OR (clin_end >= clin_when)))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>sane_procedure</td>
+                <td>CHECK ((gm.is_null_or_blank_string(narrative) IS FALSE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>sane_soap_cat</td>
+                <td>CHECK ((soap_cat = ANY (ARRAY['a'::text, 'p'::text])))</td>
             </tr>
 			
 		</table>
@@ -52103,86 +65936,16 @@ D: proven diagnosis (diagnostisch gesichert)
 			<p>Tables referencing this one via Foreign Key Constraints:</p>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#au.table.referral">au.referral</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#blobs.table.doc-med">blobs.doc_med</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#blobs.table.lnk-doc-med2episode">blobs.lnk_doc_med2episode</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.allergy">clin.allergy</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.clin-aux-note">clin.clin_aux_note</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.clin-narrative">clin.clin_narrative</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin.clin_root_item</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.family-history">clin.family_history</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.form-instances">clin.form_instances</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.hospital-stay">clin.hospital_stay</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.lab-request">clin.lab_request</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2episode">clin.lnk_code2episode</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.lnk-substance2episode">clin.lnk_substance2episode</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.procedure">clin.procedure</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.substance-intake">clin.substance_intake</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.test-result">clin.test_result</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.vaccination">clin.vaccination</a></li>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2procedure">clin.lnk_code2procedure</a></li>
 			</ul>
 		
 		
 
     <!-- Indexes -->
     
-       idx_episode_fk_encounter fk_encounter
-    
-       idx_episode_issue fk_health_issue
-    
-       idx_episode_modified_by modified_by
-    
-       idx_episode_with_issue fk_health_issue) WHERE (fk_health_issue IS NOT NULL
+       idx_clin_procedure_fk_encounter fk_encounter
     
-       idx_episode_without_issue fk_health_issue) WHERE (fk_health_issue IS NULL
+       idx_clin_procedure_fk_episode fk_episode
     
 
 	<!-- View Definition -->
@@ -52199,15 +65962,16 @@ D: proven diagnosis (diagnostisch gesichert)
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.export-item">export_item</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.review-root">review_root</a>
 		</h2>
         
-         <p>A table to hold binary data for patients intended for export as print/mail/fax/removable media/...</p>
+         <p>this table tracks whether a particular clinical item
+	 was reviewed by a clinician or not</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.export_item Structure</caption>
+                <caption>clin.review_root Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -52218,21 +65982,14 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
 				</i>
 				
 				</td>
@@ -52241,32 +65998,16 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr1">
 				<td>
                 
-                  
-                
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.patient">clin.patient.fk_identity</a>
-                  
-                
                 </td>
-            	<td>fk_identity</td>
+            	<td>row_version</td>
             	<td>integer</td>
                 <td><i>
 				
-					
-
-					
-                       UNIQUE#1
-                    
-				
-					
-
-					
-				
 
-				
+				NOT NULL
 				
 				</i>
-				<br><br>the patient this item pertains to, DELETE does not cascade because we may have wanted to export data before deleting a patient ...
+				
 				</td>
 			 </tr>
             
@@ -52274,15 +66015,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>created_by</td>
-            	<td>name</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
 				NOT NULL
-				DEFAULT "current_user"()
+				DEFAULT now()
 				</i>
-				<br><br>who put this item here
+				
 				</td>
 			 </tr>
             
@@ -52290,31 +66031,38 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>created_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
 				NOT NULL
-				DEFAULT statement_timestamp()
+				DEFAULT "current_user"()
 				</i>
-				<br><br>when was this item put here
+				
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>designation</td>
-            	<td>text</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
+
+					
+				
 
 				
 				
 				</i>
-				<br><br>the intended use for this item if any, say "print" for printing
+				
 				</td>
 			 </tr>
             
@@ -52324,8 +66072,8 @@ D: proven diagnosis (diagnostisch gesichert)
                   
                 
                 </td>
-            	<td>description</td>
-            	<td>text</td>
+            	<td>fk_reviewed_row</td>
+            	<td>integer</td>
                 <td><i>
 				
 					
@@ -52335,10 +66083,11 @@ D: proven diagnosis (diagnostisch gesichert)
                     
 				
 
-				
+				NOT NULL
 				
 				</i>
-				<br><br>a unique-per-patient description of the item
+				<br><br>the row the review status is for: to be qualified
+	 as a proper foreign key in child tables
 				</td>
 			 </tr>
             
@@ -52348,18 +66097,18 @@ D: proven diagnosis (diagnostisch gesichert)
                   
                 
                   
-                  <a href="gnumed-entire_schema.html#blobs.table.doc-obj">blobs.doc_obj.pk</a>
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.pk</a>
                   
                 
                 </td>
-            	<td>fk_doc_obj</td>
+            	<td>fk_reviewer</td>
             	<td>integer</td>
                 <td><i>
 				
 					
 
 					
-                       UNIQUE
+                       UNIQUE#1
                     
 				
 					
@@ -52367,10 +66116,10 @@ D: proven diagnosis (diagnostisch gesichert)
 					
 				
 
-				
+				NOT NULL
 				
 				</i>
-				<br><br>points to a document object
+				<br><br>who has reviewed the item
 				</td>
 			 </tr>
             
@@ -52378,15 +66127,17 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>data</td>
-            	<td>bytea</td>
+            	<td>is_technically_abnormal</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
-				<br><br>binary data representing the actual export item (unless fk_doc_obj points to a document object)
+				<br><br>whether test provider flagged this result as abnormal,
+	 *not* a clinical assessment but rather a technical one
+	 LDT: exist(8422)
 				</td>
 			 </tr>
             
@@ -52394,7 +66145,26 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>filename</td>
+            	<td>clinically_relevant</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>whether this result is considered relevant clinically,
+	 need not correspond to the value of "techically_abnormal"
+	 since abnormal values may be irrelevant while normal
+	 ones can be of significance
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>comment</td>
             	<td>text</td>
                 <td><i>
 				
@@ -52402,7 +66172,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 				
 				</i>
-				<br><br>a filename, possibly from an import, if applicable, mainly used to please non-mime pseudo operating systems
+				
 				</td>
 			 </tr>
             
@@ -52410,6 +66180,13 @@ D: proven diagnosis (diagnostisch gesichert)
 
         <!-- Inherits -->
 		
+        <p>Table clin.review_root Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
 
 		
 		
@@ -52419,50 +66196,15 @@ D: proven diagnosis (diagnostisch gesichert)
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.export_item Constraints</caption>
+            <caption>clin.review_root Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
-				<td>clin_export_item_fk_obj_or_data</td>
-                <td>CHECK ((((data IS NULL) AND (fk_doc_obj IS NOT NULL)) OR ((data IS NOT NULL) AND (fk_doc_obj IS NULL))))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>clin_export_item_fk_obj_or_filename</td>
-                <td>CHECK ((((filename IS NULL) AND (fk_doc_obj IS NOT NULL)) OR ((filename IS NOT NULL) AND (fk_doc_obj IS NULL))))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>clin_export_item_fk_obj_or_fk_identity</td>
-                <td>CHECK ((((fk_identity IS NULL) AND (fk_doc_obj IS NOT NULL)) OR ((fk_identity IS NOT NULL) AND (fk_doc_obj IS NULL))))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>clin_export_item_sane_by</td>
-                <td>CHECK ((length((created_by)::text) > 0))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>clin_export_item_sane_data</td>
-                <td>CHECK (((data IS NULL) OR (length(data) > 0)))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>clin_export_item_sane_description</td>
-                <td>CHECK ((gm.is_null_or_blank_string(description) IS FALSE))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>clin_export_item_sane_designation</td>
-                <td>CHECK ((gm.is_null_or_non_empty_string(designation) IS TRUE))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>clin_export_item_sane_filename</td>
-                <td>CHECK ((gm.is_null_or_non_empty_string(filename) IS TRUE))</td>
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
             </tr>
 			
 		</table>
@@ -52488,15 +66230,15 @@ D: proven diagnosis (diagnostisch gesichert)
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.external-care">external_care</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.reviewed-test-results">reviewed_test_results</a>
 		</h2>
         
-         <p>lists external care situations for patients</p>
+         <p>review table for test results</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.external_care Structure</caption>
+                <caption>clin.reviewed_test_results Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -52575,7 +66317,7 @@ D: proven diagnosis (diagnostisch gesichert)
                 
                 </td>
             	<td>pk</td>
-            	<td>serial</td>
+            	<td>integer</td>
                 <td><i>
 				
 					PRIMARY KEY
@@ -52585,7 +66327,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 
 				
-				
+				DEFAULT nextval('review_root_pk_seq'::regclass)
 				</i>
 				
 				</td>
@@ -52595,11 +66337,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  <a href="gnumed-entire_schema.html#clin.table.test-result">clin.test_result.pk</a>
+                  
+                
+                  
+                
                   
                 
                 </td>
-            	<td>fk_encounter</td>
+            	<td>fk_reviewed_row</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -52607,11 +66353,23 @@ D: proven diagnosis (diagnostisch gesichert)
 
 					
 				
+					
+
+					
+                       UNIQUE#1
+                    
+				
+					
+
+					
+                       UNIQUE
+                    
+				
 
 				NOT NULL
 				
 				</i>
-				<br><br>the encounter during which this external care item was first documented
+				
 				</td>
 			 </tr>
             
@@ -52621,11 +66379,11 @@ D: proven diagnosis (diagnostisch gesichert)
                   
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.health-issue">clin.health_issue.pk</a>
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.pk</a>
                   
                 
                 </td>
-            	<td>fk_health_issue</td>
+            	<td>fk_reviewer</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -52640,10 +66398,42 @@ D: proven diagnosis (diagnostisch gesichert)
 					
 				
 
+				NOT NULL
+				DEFAULT f_fk_reviewer_default()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>is_technically_abnormal</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>clinically_relevant</td>
+            	<td>boolean</td>
+                <td><i>
 				
+
+				NOT NULL
 				
 				</i>
-				<br><br>link to a health issue, if any
+				
 				</td>
 			 </tr>
             
@@ -52651,7 +66441,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>issue</td>
+            	<td>comment</td>
             	<td>text</td>
                 <td><i>
 				
@@ -52659,39 +66449,100 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 				
 				</i>
-				<br><br>description of the issue of external care
+				
 				</td>
 			 </tr>
             
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table clin.reviewed_test_results Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#clin.table.review-root">review_root</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.reviewed_test_results Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+       idx_rtr_fk_reviewer fk_reviewer
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.soap-cat-ranks">soap_cat_ranks</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.soap_cat_ranks Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
             <tr class="tr0">
 				<td>
                 
                   
                 
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.org-unit">dem.org_unit.pk</a>
-                  
-                
                 </td>
-            	<td>fk_org_unit</td>
-            	<td>integer</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
 					
 
 					
-                       UNIQUE#1
-                    
 				
-					
 
-					
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>link to the org unit where care is rendered
+				
 				</td>
 			 </tr>
             
@@ -52699,15 +66550,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>provider</td>
-            	<td>text</td>
+            	<td>rank</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				
+				NOT NULL
 				
 				</i>
-				<br><br>name of actual provider at .fk_org_unit
+				
 				</td>
 			 </tr>
             
@@ -52715,15 +66566,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>soap_cat</td>
+            	<td>character(1)</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>comment on the patient/provider relationship, say role/issues cared for/...
+				
 				</td>
 			 </tr>
             
@@ -52731,13 +66582,6 @@ D: proven diagnosis (diagnostisch gesichert)
 
         <!-- Inherits -->
 		
-        <p>Table clin.external_care Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
 
 		
 		
@@ -52747,30 +66591,20 @@ D: proven diagnosis (diagnostisch gesichert)
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.external_care Constraints</caption>
+            <caption>clin.soap_cat_ranks Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
-				<td>clin_ext_care_issue_xor_fk_issue</td>
-                <td>CHECK ((((fk_health_issue IS NULL) AND (issue IS NOT NULL)) OR ((fk_health_issue IS NOT NULL) AND (issue IS NULL))))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>clin_ext_care_sane_comment</td>
-                <td>CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>clin_ext_care_sane_issue</td>
-                <td>CHECK ((gm.is_null_or_non_empty_string(issue) IS TRUE))</td>
+				<td>clin_soap_cat_ranks_sane_cats</td>
+                <td>CHECK (((soap_cat IS NULL) OR (lower((soap_cat)::text) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
             </tr>
 			
             <tr class="tr1">
-				<td>clin_ext_care_sane_provider</td>
-                <td>CHECK ((gm.is_null_or_non_empty_string(provider) IS TRUE))</td>
+				<td>clin_soap_cat_ranks_sane_ranks</td>
+                <td>CHECK ((rank = ANY (ARRAY[1, 2, 3, 4, 5, 6])))</td>
             </tr>
 			
 		</table>
@@ -52781,12 +66615,6 @@ D: proven diagnosis (diagnostisch gesichert)
 
     <!-- Indexes -->
     
-       idx_external_care_fk_encounter fk_encounter
-    
-       idx_external_care_fk_health_issue fk_health_issue
-    
-       idx_external_care_fk_org_unit fk_org_unit
-    
 
 	<!-- View Definition -->
 	
@@ -52802,15 +66630,15 @@ D: proven diagnosis (diagnostisch gesichert)
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.family-history">family_history</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.substance-intake">substance_intake</a>
 		</h2>
         
-         <p>This table stores family history items on persons not otherwise in the database.</p>
+         <p>The substances a patient is actually currently taking.</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.family_history Structure</caption>
+                <caption>clin.substance_intake Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -52869,11 +66697,19 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -52910,7 +66746,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				NOT NULL
 				DEFAULT now()
 				</i>
-				<br><br>When the family history item became known to the patient (not the afflicted relative).
+				<br><br>When was this substance started.
 				</td>
 			 </tr>
             
@@ -52934,7 +66770,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				NOT NULL
 				
 				</i>
-				<br><br>encounter during which family history item became known
+				<br><br>The encounter use of this substance was documented under.
 				</td>
 			 </tr>
             
@@ -52958,7 +66794,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				NOT NULL
 				
 				</i>
-				<br><br>episode to which family history item is of importance
+				
 				</td>
 			 </tr>
             
@@ -52974,7 +66810,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 				
 				</i>
-				<br><br>the condition this relative suffered from
+				<br><br>Any notes on this substance use.
 				</td>
 			 </tr>
             
@@ -52988,7 +66824,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 
 				
-				
+				DEFAULT 'p'::text
 				</i>
 				
 				</td>
@@ -53021,11 +66857,11 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.fhx-relation-type">clin.fhx_relation_type.pk</a>
+                  <a href="gnumed-entire_schema.html#ref.table.consumable-substance">ref.consumable_substance.pk</a>
                   
                 
                 </td>
-            	<td>fk_relation_type</td>
+            	<td>fk_substance</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -53037,7 +66873,11 @@ D: proven diagnosis (diagnostisch gesichert)
 				NOT NULL
 				
 				</i>
-				<br><br>foreign key to the type of relation the patient has to the afflicated relative
+				<br><br>Links to a substance the patient is taking.
+********************************************* 
+DO NOT TRY TO USE THIS TO FIND OUT THE BRAND.
+IT WILL BE WRONG.
+*********************************************
 				</td>
 			 </tr>
             
@@ -53045,7 +66885,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>age_noted</td>
+            	<td>preparation</td>
             	<td>text</td>
                 <td><i>
 				
@@ -53053,7 +66893,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 				
 				</i>
-				<br><br>age at which the condition was noted in the relative if known
+				<br><br>How this substance is delivered, tablet, pill, liquid, cream.
 				</td>
 			 </tr>
             
@@ -53061,7 +66901,40 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>age_of_death</td>
+            	<td>schedule</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>The schedule, if any, the substance is to be taken by.
+ An XML snippet to be interpreted by the middleware.
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>aim</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>The aim of taking this substance.
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>duration</td>
             	<td>interval</td>
                 <td><i>
 				
@@ -53069,7 +66942,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 				
 				</i>
-				<br><br>age at which the relative died if known
+				<br><br>How long is this substances intended to be taken.
 				</td>
 			 </tr>
             
@@ -53077,7 +66950,23 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>contributed_to_death</td>
+            	<td>intake_is_approved_of</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				<br><br>Whether or not intake of this substance is recommended/approved of by the provider
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>is_long_term</td>
             	<td>boolean</td>
                 <td><i>
 				
@@ -53085,7 +66974,23 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 				
 				</i>
-				<br><br>whether the condition contributed to the death of the relative if known
+				<br><br>whether this is expected to be a regular/ongoing/chronic/long-term/repeat/permament/perpetual/life-long substance intake
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>discontinued</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>When was this intake discontinued ?
 				</td>
 			 </tr>
             
@@ -53093,7 +66998,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>name_relative</td>
+            	<td>discontinue_reason</td>
             	<td>text</td>
                 <td><i>
 				
@@ -53101,23 +67006,31 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 				
 				</i>
-				<br><br>name of the relative suffering the condition
+				<br><br>Why was this intake discontinued ?
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#ref.table.lnk-substance2brand">ref.lnk_substance2brand.pk</a>
+                  
+                
                 </td>
-            	<td>dob_relative</td>
-            	<td>timestamp with time zone</td>
+            	<td>fk_drug_component</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				
 				
 				</i>
-				<br><br>date of birth of the relative if known
+				<br><br>Links to the component of a branded drug taken by a patient.
 				</td>
 			 </tr>
             
@@ -53125,7 +67038,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>comment</td>
+            	<td>comment_on_start</td>
             	<td>text</td>
                 <td><i>
 				
@@ -53133,7 +67046,23 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 				
 				</i>
+				<br><br>Comment (uncertainty level) on .clin_when = started. "?" = "entirely unknown".
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>harmful_use_type</td>
+            	<td>integer</td>
+                <td><i>
+				
+
 				
+				
+				</i>
+				<br><br>NULL=not considered=medication, 0=no or not considered harmful, 1=presently harmful use, 2=presently addicted, 3=previously addicted
 				</td>
 			 </tr>
             
@@ -53141,7 +67070,7 @@ D: proven diagnosis (diagnostisch gesichert)
 
         <!-- Inherits -->
 		
-        <p>Table clin.family_history Inherits
+        <p>Table clin.substance_intake Inherits
         
             
            <a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin_root_item</a>, 
@@ -53157,35 +67086,60 @@ D: proven diagnosis (diagnostisch gesichert)
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.family_history Constraints</caption>
+            <caption>clin.substance_intake Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
-				<td>c_family_history_sane_age_noted</td>
-                <td>CHECK ((gm.is_null_or_non_empty_string(age_noted) IS TRUE))</td>
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
             </tr>
 			
             <tr class="tr1">
-				<td>c_family_history_sane_condition</td>
-                <td>CHECK ((gm.is_null_or_blank_string(narrative) IS FALSE))</td>
+				<td>clin_patient_sane_use_type</td>
+                <td>CHECK (((harmful_use_type IS NULL) OR ((harmful_use_type >= 0) AND (harmful_use_type <= 3))))</td>
             </tr>
 			
             <tr class="tr0">
-				<td>c_family_history_sane_name</td>
-                <td>CHECK ((gm.is_null_or_non_empty_string(name_relative) IS TRUE))</td>
+				<td>clin_root_item_sane_soap_cat</td>
+                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
             </tr>
 			
             <tr class="tr1">
-				<td>clin_root_item_sane_soap_cat</td>
-                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
+				<td>clin_subst_intake_sane_prep</td>
+                <td>CHECK ((((fk_drug_component IS NULL) AND (preparation IS NOT NULL)) OR ((fk_drug_component IS NOT NULL) AND (preparation IS NULL))))</td>
             </tr>
 			
             <tr class="tr0">
-				<td>narrative_neither_null_nor_empty</td>
-                <td>CHECK ((btrim(COALESCE(narrative, ''::text)) <> ''::text))</td>
+				<td>clin_substance_intake_sane_start_comment</td>
+                <td>CHECK (gm.is_null_or_non_empty_string(comment_on_start))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>discontinued_after_started</td>
+                <td>CHECK ((((clin_when IS NULL) OR (discontinued IS NULL)) OR ((discontinued >= clin_when) AND (discontinued <= now()))))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>medication_is_plan</td>
+                <td>CHECK ((soap_cat = 'p'::text))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>sane_aim</td>
+                <td>CHECK ((gm.is_null_or_non_empty_string(aim) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>sane_discontinue_reason</td>
+                <td>CHECK ((((discontinued IS NULL) AND (discontinue_reason IS NULL)) OR ((discontinued IS NOT NULL) AND (gm.is_null_or_non_empty_string(discontinue_reason) IS TRUE))))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>sane_schedule</td>
+                <td>CHECK ((gm.is_null_or_non_empty_string(schedule) IS TRUE))</td>
             </tr>
 			
 		</table>
@@ -53196,16 +67150,20 @@ D: proven diagnosis (diagnostisch gesichert)
 			<p>Tables referencing this one via Foreign Key Constraints:</p>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2fhx">clin.lnk_code2fhx</a></li>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-substance2episode">clin.lnk_substance2episode</a></li>
 			</ul>
 		
 		
 
     <!-- Indexes -->
     
-       idx_clin_family_history_fk_encounter fk_encounter
+       idx_c_subst_int_fk_drug_comp fk_drug_component
     
-       idx_clin_family_history_fk_episode fk_episode
+       idx_clin_substance_intake_fk_encounter fk_encounter
+    
+       idx_clin_substance_intake_fk_episode fk_episode
+    
+       idx_fk_substance_curr_med fk_substance
     
 
 	<!-- View Definition -->
@@ -53222,15 +67180,15 @@ D: proven diagnosis (diagnostisch gesichert)
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.fhx-relation-type">fhx_relation_type</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.suppressed-hint">suppressed_hint</a>
 		</h2>
         
-         <p>Enumerates inter-person relations for family history linking.</p>
+         <p>A table to hold hints suppressed per patient</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.fhx_relation_type Structure</caption>
+                <caption>clin.suppressed_hint Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -53289,11 +67247,19 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -53329,23 +67295,23 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                   
+                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  
                 
                 </td>
-            	<td>description</td>
-            	<td>text</td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 					
 
 					
-                       UNIQUE#1
-                    
 				
 
-				
+				NOT NULL
 				
 				</i>
-				<br><br>Description of the relation type, specific or unspecific: sister, father, ..., maternal family, ...
+				<br><br>the encounter during which this hint was first suppressed
 				</td>
 			 </tr>
             
@@ -53353,23 +67319,87 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                   
+                  <a href="gnumed-entire_schema.html#ref.table.auto-hint">ref.auto_hint.pk</a>
+                  
                 
                 </td>
-            	<td>is_genetic</td>
-            	<td>boolean</td>
+            	<td>fk_hint</td>
+            	<td>integer</td>
                 <td><i>
 				
 					
 
 					
-                       UNIQUE#1
-                    
 				
 
 				NOT NULL
 				
 				</i>
-				<br><br>Whether or not this type of relation is biologic/genetic or not. Note that non-genetic relations may still pose a risk because of infectious diseases.
+				<br><br>the hint that is suppressed
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>suppressed_by</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT "current_user"()
+				</i>
+				<br><br>who suppressed this hint
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>suppressed_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT statement_timestamp()
+				</i>
+				<br><br>when was this hint suppressed
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>rationale</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>rationale on why this hint is suppressed in this patient
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>md5_sum</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>md5 of relevant fields of this hint
 				</td>
 			 </tr>
             
@@ -53377,7 +67407,7 @@ D: proven diagnosis (diagnostisch gesichert)
 
         <!-- Inherits -->
 		
-        <p>Table clin.fhx_relation_type Inherits
+        <p>Table clin.suppressed_hint Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
@@ -53393,15 +67423,30 @@ D: proven diagnosis (diagnostisch gesichert)
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.fhx_relation_type Constraints</caption>
+            <caption>clin.suppressed_hint Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
-				<td>c_fhx_relation_type_sane_desc</td>
-                <td>CHECK ((gm.is_null_or_blank_string(description) IS FALSE))</td>
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>clin_suppressed_hint_sane_by</td>
+                <td>CHECK ((length((suppressed_by)::text) > 0))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>clin_suppressed_hint_sane_md5</td>
+                <td>CHECK ((gm.is_null_or_blank_string(md5_sum) IS FALSE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>clin_suppressed_hint_sane_rationale</td>
+                <td>CHECK ((gm.is_null_or_blank_string(rationale) IS FALSE))</td>
             </tr>
 			
 		</table>
@@ -53409,16 +67454,13 @@ D: proven diagnosis (diagnostisch gesichert)
 
         <!-- Foreign Key Discovery -->
 		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.family-history">clin.family_history</a></li>
-			</ul>
-		
-		
 
     <!-- Indexes -->
     
+       idx_suppressed_hint_fk_encounter fk_encounter
+    
+       idx_suppressed_hint_fk_hint fk_hint
+    
 
 	<!-- View Definition -->
 	
@@ -53434,16 +67476,15 @@ D: proven diagnosis (diagnostisch gesichert)
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.form-data">form_data</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.test-org">test_org</a>
 		</h2>
         
-         <p>holds the values used in form instances, for
-	 later re-use/validation</p>
+         <p>organisation providing results</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.form_data Structure</caption>
+                <caption>clin.test_org Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -53502,11 +67543,19 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -53542,31 +67591,31 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.form-instances">clin.form_instances.pk</a>
-                  
                 
                   
+                  <a href="gnumed-entire_schema.html#dem.table.org-unit">dem.org_unit.pk</a>
+                  
                 
                 </td>
-            	<td>fk_instance</td>
+            	<td>fk_org_unit</td>
             	<td>integer</td>
                 <td><i>
 				
 					
 
 					
+                       UNIQUE
+                    
 				
 					
 
 					
-                       UNIQUE#1
-                    
 				
 
 				NOT NULL
 				
 				</i>
-				<br><br>the form instance this value was used in
+				<br><br>link to a unit of an organization more closely defining this lab
 				</td>
 			 </tr>
             
@@ -53574,13 +67623,35 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#public.table.form-fields">public.form_fields.pk</a>
+                  <a href="gnumed-entire_schema.html#dem.table.identity">dem.identity.pk</a>
                   
                 
+                </td>
+            	<td>fk_adm_contact</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				
+				
+				</i>
+				<br><br>whom to call for admin questions (modem link, etc.)
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.identity">dem.identity.pk</a>
                   
                 
                 </td>
-            	<td>fk_form_field</td>
+            	<td>fk_med_contact</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -53588,19 +67659,30 @@ D: proven diagnosis (diagnostisch gesichert)
 
 					
 				
-					
 
-					
-                       UNIQUE#1
-                    
+				
+				
+				</i>
+				<br><br>whom to call for medical questions (result verification,
+	 additional test requests)
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>comment</td>
+            	<td>text</td>
+                <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>points to the definition of the field in the form
-	 which in turn defines the place holder in the
-	 template to replace with <value>
+				<br><br>useful for, say, dummy records where you want
+	 to mark up stuff like "pharmacy such-and-such"
+	 if you don't have it in your contacts
 				</td>
 			 </tr>
             
@@ -53608,15 +67690,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>value</td>
+            	<td>contact</td>
             	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>the value to replace the place holder with
+				<br><br>free-text contact information for this lab
 				</td>
 			 </tr>
             
@@ -53624,7 +67706,7 @@ D: proven diagnosis (diagnostisch gesichert)
 
         <!-- Inherits -->
 		
-        <p>Table clin.form_data Inherits
+        <p>Table clin.test_org Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
@@ -53638,9 +67720,49 @@ D: proven diagnosis (diagnostisch gesichert)
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.test_org Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>sane_comment</td>
+                <td>CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>sane_contact</td>
+                <td>CHECK ((gm.is_null_or_non_empty_string(contact) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lab-request">clin.lab_request</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.test-type">clin.test_type</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#staging.table.lab-request">staging.lab_request</a></li>
+			</ul>
+		
+		
 
     <!-- Indexes -->
     
@@ -53659,15 +67781,15 @@ D: proven diagnosis (diagnostisch gesichert)
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.form-instances">form_instances</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.test-panel">test_panel</a>
 		</h2>
         
-         <p>instances of forms, like a log of all processed forms</p>
+         <p>Panels of tests. The same test can appear in several panels.</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.form_instances Structure</caption>
+                <caption>clin.test_panel Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -53726,61 +67848,13 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr1">
 				<td>
                 
-                </td>
-            	<td>modified_by</td>
-            	<td>name</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT "current_user"()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_item</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT nextval('clin_root_item_pk_item_seq'::regclass)
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT now()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
                   
-                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
                   
                 
                 </td>
-            	<td>fk_encounter</td>
-            	<td>integer</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 					
@@ -53789,49 +67863,32 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 
 				NOT NULL
-				
+				DEFAULT "current_user"()
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
-                  
                 
                 </td>
-            	<td>fk_episode</td>
-            	<td>integer</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
 					
 
 					
 				
 
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>narrative</td>
-            	<td>text</td>
-                <td><i>
-				
-
 				
 				
 				</i>
-				<br><br>can be used as a status field, eg. "printed", "faxed" etc.
+				
 				</td>
 			 </tr>
             
@@ -53839,7 +67896,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
+            	<td>description</td>
             	<td>text</td>
                 <td><i>
 				
@@ -53847,73 +67904,39 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 				
 				</i>
-				
+				<br><br>A description/label for this panel.
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
 				</i>
-				
+				<br><br>An arbitrary comment on this panel.
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#ref.table.paperwork-templates">ref.paperwork_templates.pk</a>
-                  
-                
                 </td>
-            	<td>fk_form_def</td>
-            	<td>integer</td>
+            	<td>fk_test_types</td>
+            	<td>integer[]</td>
                 <td><i>
 				
-					
-
-					
-				
 
-				NOT NULL
-				
-				</i>
-				<br><br>points to the definition of this instance,
-	 this FK will fail once we start separating services,
-	 make it into a x_db_fk then
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>form_name</td>
-            	<td>text</td>
-                <td><i>
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>a string uniquely identifying the form template,
-	 necessary for the audit trail
+				<br><br>Links to test types which belong to this panel.
 				</td>
 			 </tr>
             
@@ -53921,10 +67944,10 @@ D: proven diagnosis (diagnostisch gesichert)
 
         <!-- Inherits -->
 		
-        <p>Table clin.form_instances Inherits
+        <p>Table clin.test_panel Inherits
         
             
-           <a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin_root_item</a>, 
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
         
         </p>
 		
@@ -53937,20 +67960,25 @@ D: proven diagnosis (diagnostisch gesichert)
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.form_instances Constraints</caption>
+            <caption>clin.test_panel Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
-				<td>clin_root_item_sane_soap_cat</td>
-                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
             </tr>
 			
             <tr class="tr1">
-				<td>form_is_plan</td>
-                <td>CHECK ((soap_cat = 'p'::text))</td>
+				<td>clin_test_panel_sane_cmt</td>
+                <td>CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>clin_test_panel_sane_desc</td>
+                <td>CHECK ((gm.is_null_or_blank_string(description) IS FALSE))</td>
             </tr>
 			
 		</table>
@@ -53961,25 +67989,13 @@ D: proven diagnosis (diagnostisch gesichert)
 			<p>Tables referencing this one via Foreign Key Constraints:</p>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#au.table.referral">au.referral</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.form-data">clin.form_data</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#public.table.form-job-queue">public.form_job_queue</a></li>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2tst-pnl">clin.lnk_code2tst_pnl</a></li>
 			</ul>
 		
 		
 
     <!-- Indexes -->
     
-       idx_clin_form_instances_fk_encounter fk_encounter
-    
-       idx_clin_form_instances_fk_episode fk_episode
-    
 
 	<!-- View Definition -->
 	
@@ -53995,19 +68011,15 @@ D: proven diagnosis (diagnostisch gesichert)
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.health-issue">health_issue</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.test-result">test_result</a>
 		</h2>
         
-         <p>This is pretty much what others would call "Past Medical History"
-	 or "Foundational illness", eg. longer-ranging, underlying,
-	 encompassing issues with one's health such as "immunodeficiency",
-	 "type 2 diabetes". In Belgium it is called "problem".
-	 L.L.Weed includes lots of little things into it, we do not.</p>
+         <p>the results of a single measurement</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.health_issue Structure</caption>
+                <caption>clin.test_result Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -54066,11 +68078,19 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -54082,21 +68102,14 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>pk_item</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
-				
-				
+				NOT NULL
+				DEFAULT nextval('clin_root_item_pk_item_seq'::regclass)
 				</i>
 				
 				</td>
@@ -54106,52 +68119,66 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>description</td>
-            	<td>text</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
 				NOT NULL
-				
+				DEFAULT now()
 				</i>
-				<br><br>descriptive name of this health issue, may
-	 change over time as evidence increases
+				<br><br>the time when this result was *actually* obtained,
+	 if this is a lab result this should be between
+	 lab_request.clin_when and lab_request.results_reported_when,
+	 HL7: OBR.observation_date_time
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
+                  
+                
                 </td>
-            	<td>laterality</td>
-            	<td>character varying(2)</td>
+            	<td>fk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
 
+					
+				
+
+				NOT NULL
 				
-				DEFAULT NULL::character varying
 				</i>
-				<br><br>NULL: don't know
-	 s: sinister - left
-	 d: dexter - right
-	 sd: sinister and dexter - both sides
-	 na: not applicable
+				
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
+                  
+                
                 </td>
-            	<td>age_noted</td>
-            	<td>interval</td>
+            	<td>fk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
 
+					
 				
+
+				NOT NULL
 				
 				</i>
-				<br><br>at what age the patient acquired the condition
+				
 				</td>
 			 </tr>
             
@@ -54159,15 +68186,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>is_active</td>
-            	<td>boolean</td>
+            	<td>narrative</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
-				DEFAULT true
+				
 				</i>
-				<br><br>whether this health issue (problem) is active
+				<br><br>clinical comment, progress note
 				</td>
 			 </tr>
             
@@ -54175,29 +68202,36 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>clinically_relevant</td>
-            	<td>boolean</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
-				DEFAULT true
+				DEFAULT 'o'::text
 				</i>
-				<br><br>whether this health issue (problem) has any clinical relevance
+				
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>is_confidential</td>
-            	<td>boolean</td>
+            	<td>pk</td>
+            	<td>serial</td>
                 <td><i>
 				
+					PRIMARY KEY
+					
+
+					
+				
 
 				
-				DEFAULT false
+				
 				</i>
 				
 				</td>
@@ -54206,40 +68240,41 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.test-type">clin.test_type.pk</a>
+                  
+                
                 </td>
-            	<td>is_cause_of_death</td>
-            	<td>boolean</td>
+            	<td>fk_type</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
-				DEFAULT false
-				</i>
 				
+				</i>
+				<br><br>the type of test this result is from
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
-                  
-                
                 </td>
-            	<td>fk_encounter</td>
-            	<td>integer</td>
+            	<td>val_num</td>
+            	<td>numeric</td>
                 <td><i>
 				
-					
 
-					
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>The encounter during which this health issue was added.
+				<br><br>numeric value if any,
+	 HL7: OBX.observation_results if OBX.value_type == NM
 				</td>
 			 </tr>
             
@@ -54247,7 +68282,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>grouping</td>
+            	<td>val_alpha</td>
             	<td>text</td>
                 <td><i>
 				
@@ -54255,8 +68290,8 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 				
 				</i>
-				<br><br>This can be used to entirely arbitrarily group health
- issues felt to belong to each other.
+				<br><br>alphanumeric value if any,
+	 HL7: OBX.observation_results if OBX.value_type == FT
 				</td>
 			 </tr>
             
@@ -54264,7 +68299,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>diagnostic_certainty_classification</td>
+            	<td>val_unit</td>
             	<td>text</td>
                 <td><i>
 				
@@ -54272,11 +68307,8 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 				
 				</i>
-				<br><br>The certainty at which this issue is believed to be a diagnosis:
-A: sign (Symptom)
-B: cluster of signs (Symptomkomplex)
-C: syndromic diagnosis (Bild einer Diagnose)
-D: proven diagnosis (diagnostisch gesichert)
+				<br><br>the unit this result came in
+	 HL7: OBX.units
 				</td>
 			 </tr>
             
@@ -54284,138 +68316,33 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>summary</td>
-            	<td>text</td>
+            	<td>val_normal_min</td>
+            	<td>numeric</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>Used for tracking the summary of this health issue.
-				</td>
-			 </tr>
-            
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table clin.health_issue Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.health_issue Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>health_issue_laterality_check</td>
-                <td>CHECK (((laterality)::text = ANY (ARRAY[(NULL::character varying)::text, ('s'::character varying)::text, ('d'::character varying)::text, ('sd'::character varying)::text, ('na'::character varying)::text])))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>health_issue_sane_summary</td>
-                <td>CHECK (gm.is_null_or_non_empty_string(summary))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>issue_name_not_empty</td>
-                <td>CHECK ((btrim(description) <> ''::text))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>sane_grouping</td>
-                <td>CHECK (gm.is_null_or_non_empty_string(grouping))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>valid_diagnostic_certainty_classification</td>
-                <td>CHECK ((diagnostic_certainty_classification = ANY (ARRAY['A'::text, 'B'::text, 'C'::text, 'D'::text, NULL::text])))</td>
-            </tr>
-			
-		</table>
-		
-
-        <!-- Foreign Key Discovery -->
-		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.episode">clin.episode</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.external-care">clin.external_care</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2h-issue">clin.lnk_code2h_issue</a></li>
-			</ul>
-		
-		
-
-    <!-- Indexes -->
-    
-       idx_health_issue_modified_by modified_by
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.hospital-stay">hospital_stay</a>
-		</h2>
-        
-         <p>collects data on hospitalisations of patients, reasons are linked via a link table</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.hospital_stay Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
+				<br><br>lower bound of normal range if numerical as
+	 defined by provider for this result
+				</td>
+			 </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
+            	<td>val_normal_max</td>
+            	<td>numeric</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
-				</i>
 				
+				
+				</i>
+				<br><br>upper bound of normal range if numerical as
+	 defined by provider for this result
 				</td>
 			 </tr>
             
@@ -54423,15 +68350,18 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>val_normal_range</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
 				
-				</i>
 				
+				</i>
+				<br><br>range of normal values if alphanumerical
+	 as defined by provider for this result, eg.
+	 "less than 0.5 but detectable"
+	 HL7: OBX.reference_range
 				</td>
 			 </tr>
             
@@ -54439,15 +68369,16 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>val_target_min</td>
+            	<td>numeric</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
-				</i>
 				
+				
+				</i>
+				<br><br>lower bound of target range if numerical as
+	 defined by clinician caring this patient
 				</td>
 			 </tr>
             
@@ -54455,15 +68386,16 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>val_target_max</td>
+            	<td>numeric</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
-				</i>
 				
+				
+				</i>
+				<br><br>upper bound of target range if numerical as
+	 defined by clinician caring for this patient
 				</td>
 			 </tr>
             
@@ -54471,15 +68403,16 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
-            	<td>integer</td>
+            	<td>val_target_range</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('clin_root_item_pk_item_seq'::regclass)
-				</i>
 				
+				
+				</i>
+				<br><br>range of target values if alphanumerical
+	 as defined by clinician caring for this patient
 				</td>
 			 </tr>
             
@@ -54487,63 +68420,52 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>abnormality_indicator</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
-				<br><br>to be used as when the patient was admitted
+				<br><br>how the test provider flagged this result as abnormal,
+	 *not* a clinical assessment but rather a technical one
+	 LDT: 8422
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
-                  
-                
                 </td>
-            	<td>fk_encounter</td>
-            	<td>integer</td>
+            	<td>norm_ref_group</td>
+            	<td>text</td>
                 <td><i>
 				
-					
 
-					
 				
-
-				NOT NULL
 				
 				</i>
-				
+				<br><br>what sample of the population does this normal range
+	 applay to, eg what type of patient was assumed when
+	 interpreting this result,
+	 LDT: 8407
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
-                  
-                
                 </td>
-            	<td>fk_episode</td>
-            	<td>integer</td>
+            	<td>note_test_org</td>
+            	<td>text</td>
                 <td><i>
 				
-					
 
-					
 				
-
-				NOT NULL
 				
 				</i>
-				
+				<br><br>A comment on the test result provided by the tester or testing entity.
 				</td>
 			 </tr>
             
@@ -54551,7 +68473,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>narrative</td>
+            	<td>material</td>
             	<td>text</td>
                 <td><i>
 				
@@ -54559,7 +68481,8 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 				
 				</i>
-				<br><br>a comment on the hospital stay
+				<br><br>the submitted material, eg. smear, serum, urine, etc.,
+	 LDT: 8430
 				</td>
 			 </tr>
             
@@ -54567,7 +68490,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
+            	<td>material_detail</td>
             	<td>text</td>
                 <td><i>
 				
@@ -54575,7 +68498,8 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 				
 				</i>
-				
+				<br><br>details re the material, eg. site taken from, etc.
+	 LDT: 8431
 				</td>
 			 </tr>
             
@@ -54583,62 +68507,95 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                   
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.pk</a>
+                  
                 
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>fk_intended_reviewer</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
 					
 
 					
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>who is *supposed* to review this item
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.lab-request">clin.lab_request.pk</a>
+                  
+                
                 </td>
-            	<td>discharge</td>
-            	<td>timestamp with time zone</td>
+            	<td>fk_request</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				
 				
 				</i>
-				<br><br>when was the patient discharged
+				<br><br>The request this result was ordered under if any.
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.org-unit">dem.org_unit.pk</a>
-                  
+                </td>
+            	<td>status</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>The result status (say, HL7 OBX 11 Observ result status (#00579, table 0085).
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
                 
                 </td>
-            	<td>fk_org_unit</td>
-            	<td>integer</td>
+            	<td>source_data</td>
+            	<td>text</td>
                 <td><i>
 				
-					
 
-					
+				
+				
+				</i>
+				<br><br>The source data for this observation (say, HL7 OBX).
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>val_grouping</td>
+            	<td>text</td>
+                <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>links to the hospital the patient was admitted to
+				<br><br>A grouping for related values (say, HL7 OBX Obs Sub ID, think antibiogram).
 				</td>
 			 </tr>
             
@@ -54646,7 +68603,7 @@ D: proven diagnosis (diagnostisch gesichert)
 
         <!-- Inherits -->
 		
-        <p>Table clin.hospital_stay Inherits
+        <p>Table clin.test_result Inherits
         
             
            <a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin_root_item</a>, 
@@ -54662,25 +68619,45 @@ D: proven diagnosis (diagnostisch gesichert)
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.hospital_stay Constraints</caption>
+            <caption>clin.test_result Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>clin_root_item_sane_soap_cat</td>
                 <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
             </tr>
 			
+            <tr class="tr0">
+				<td>clin_test_result_sane_source_data</td>
+                <td>CHECK (gm.is_null_or_non_empty_string(source_data))</td>
+            </tr>
+			
             <tr class="tr1">
-				<td>sane_duration</td>
-                <td>CHECK (((discharge IS NULL) OR (discharge > clin_when)))</td>
+				<td>clin_test_result_sane_status</td>
+                <td>CHECK (gm.is_null_or_non_empty_string(status))</td>
             </tr>
 			
             <tr class="tr0">
-				<td>sane_hospital</td>
-                <td>CHECK (gm.is_null_or_non_empty_string(narrative))</td>
+				<td>clin_test_result_sane_val_grouping</td>
+                <td>CHECK (gm.is_null_or_non_empty_string(val_grouping))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>numval_needs_unit</td>
+                <td>CHECK ((((val_num IS NOT NULL) AND (btrim(COALESCE(val_unit, ''::text)) <> ''::text)) OR (val_num IS NULL)))</td>
+            </tr>
+			
+            <tr class="tr0">
+				<td>test_result_check</td>
+                <td>CHECK ((((val_num IS NOT NULL) OR (val_alpha IS NOT NULL)) OR (((val_num IS NULL) AND (val_alpha <> ''::text)) AND (val_alpha IS NOT NULL))))</td>
             </tr>
 			
 		</table>
@@ -54691,20 +68668,22 @@ D: proven diagnosis (diagnostisch gesichert)
 			<p>Tables referencing this one via Foreign Key Constraints:</p>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#blobs.table.lnk-doc2hospital-stay">blobs.lnk_doc2hospital_stay</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.procedure">clin.procedure</a></li>
+				<li><a href="gnumed-entire_schema.html#clin.table.reviewed-test-results">clin.reviewed_test_results</a></li>
 			</ul>
 		
 		
 
     <!-- Indexes -->
     
-       idx_clin_hospital_stay_fk_encounter fk_encounter
+       idx_clin_test_result_fk_encounter fk_encounter
     
-       idx_clin_hospital_stay_fk_episode fk_episode
+       idx_clin_test_result_fk_episode fk_episode
+    
+       idx_test_result_fk_type fk_type
+    
+       idx_test_result_status status
+    
+       idx_test_result_unit val_unit
     
 
 	<!-- View Definition -->
@@ -54721,17 +68700,15 @@ D: proven diagnosis (diagnostisch gesichert)
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.incoming-data-unmatchable">incoming_data_unmatchable</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.test-type">test_type</a>
 		</h2>
         
-         <p>this table holds test results that could not be matched
-	 to any patient, it is intended to prevent overflow of
-	 incoming_data_unmatched with unmatchable data</p>
+         <p>measurement type, like a "method" in a lab</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.incoming_data_unmatchable Structure</caption>
+                <caption>clin.test_type Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -54790,11 +68767,19 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -54829,64 +68814,65 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr1">
 				<td>
                 
-                </td>
-            	<td>fk_patient_candidates</td>
-            	<td>integer[]</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
+                  
+                
+                  
+                
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.test-org">clin.test_org.pk</a>
+                  
                 
                 </td>
-            	<td>request_id</td>
-            	<td>text</td>
+            	<td>fk_test_org</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
 
+					
+                       UNIQUE#1
+                    
 				
+					
+
+					
+                       UNIQUE#2
+                    
 				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>firstnames</td>
-            	<td>text</td>
-                <td><i>
-				
+					
 
+					
 				
+
+				NOT NULL
 				
 				</i>
-				
+				<br><br>organisation carrying out this type of measurement, eg. a particular lab
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>lastnames</td>
+            	<td>name</td>
             	<td>text</td>
                 <td><i>
 				
+					
 
+					
+                       UNIQUE#2
+                    
 				
+
+				NOT NULL
 				
 				</i>
-				
+				<br><br>descriptive name of this measurement type,
+	 HL7: OBX.observation_identifier
 				</td>
 			 </tr>
             
@@ -54894,15 +68880,16 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>dob</td>
-            	<td>date</td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				
+				<br><br>arbitrary comment on this type of measurement/test such
+	 as "outdated" or "only reliable when ..."
 				</td>
 			 </tr>
             
@@ -54910,7 +68897,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>postcode</td>
+            	<td>reference_unit</td>
             	<td>text</td>
                 <td><i>
 				
@@ -54918,7 +68905,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 				
 				</i>
-				
+				<br><br>The chosen reference unit for this test type, preferably SI, used for comparing results delivered in differing units. This does not relate to what unit the test provider delivers results in but rather the unit we think those results need to be converted to in order to be comparable to OTHER results.
 				</td>
 			 </tr>
             
@@ -54926,7 +68913,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>other_info</td>
+            	<td>loinc</td>
             	<td>text</td>
                 <td><i>
 				
@@ -54941,26 +68928,18 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>type</td>
+            	<td>abbrev</td>
             	<td>text</td>
                 <td><i>
 				
+					
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>data</td>
-            	<td>bytea</td>
-                <td><i>
+					
+                       UNIQUE#1
+                    
 				
 
 				NOT NULL
@@ -54970,67 +68949,27 @@ D: proven diagnosis (diagnostisch gesichert)
 				</td>
 			 </tr>
             
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>gender</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
             <tr class="tr1">
 				<td>
                 
-                </td>
-            	<td>requestor</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
+                  
+                  <a href="gnumed-entire_schema.html#clin.table.meta-test-type">clin.meta_test_type.pk</a>
+                  
                 
                 </td>
-            	<td>external_data_id</td>
-            	<td>text</td>
+            	<td>fk_meta_test_type</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>fk_identity_disambiguated</td>
-            	<td>integer</td>
-                <td><i>
+					
 				
 
 				
 				
 				</i>
-				
+				<br><br>Link to the meta test type (if any) this test type is to be aggregated under.
 				</td>
 			 </tr>
             
@@ -55038,7 +68977,7 @@ D: proven diagnosis (diagnostisch gesichert)
 
         <!-- Inherits -->
 		
-        <p>Table clin.incoming_data_unmatchable Inherits
+        <p>Table clin.test_type Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
@@ -55052,12 +68991,48 @@ D: proven diagnosis (diagnostisch gesichert)
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.test_type Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-tst2norm">clin.lnk_tst2norm</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.test-result">clin.test_result</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#de-de.table.lab-test-gnr">de_de.lab_test_gnr</a></li>
+			</ul>
+		
+		
 
     <!-- Indexes -->
     
+       idx_test_type_fk_meta_test_type fk_meta_test_type
+    
+       idx_test_type_fk_test_org fk_test_org
+    
+       idx_test_type_loinc loinc
+    
 
 	<!-- View Definition -->
 	
@@ -55071,20 +69046,15 @@ D: proven diagnosis (diagnostisch gesichert)
     </p>
 	
         <hr>
-		<h2>Table:
+		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.incoming-data-unmatched">incoming_data_unmatched</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-brand-intakes">v_brand_intakes</a>
 		</h2>
         
-         <p>this table holds incoming data (lab results, documents)
-	 that could not be matched to one single patient automatically,
-	 it is intended to facilitate manual matching,
-	 - use "modified_when" for import time</p>
-        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.incoming_data_unmatched Structure</caption>
+                <caption>clin.v_brand_intakes Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -55096,13 +69066,13 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
+            	<td>pk_substance_intake</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -55112,12 +69082,12 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>row_version</td>
+            	<td>pk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -55128,13 +69098,13 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -55144,13 +69114,13 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>brand</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -55159,18 +69129,11 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>preparation</td>
+            	<td>text</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -55183,17 +69146,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>fk_patient_candidates</td>
-            	<td>integer[]</td>
+            	<td>substance</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>a matching algorithm can be applied to produce
-	 a list of likely candidate patients, the question
-	 remains whether this should not be done at runtime
+				
 				</td>
 			 </tr>
             
@@ -55201,15 +69162,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>request_id</td>
-            	<td>text</td>
+            	<td>amount</td>
+            	<td>numeric</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>request ID as found in <data>
+				
 				</td>
 			 </tr>
             
@@ -55217,7 +69178,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>firstnames</td>
+            	<td>unit</td>
             	<td>text</td>
                 <td><i>
 				
@@ -55225,7 +69186,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 				
 				</i>
-				<br><br>first names as found in <data>
+				
 				</td>
 			 </tr>
             
@@ -55233,7 +69194,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>lastnames</td>
+            	<td>atc_substance</td>
             	<td>text</td>
                 <td><i>
 				
@@ -55241,7 +69202,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 				
 				</i>
-				<br><br>last names as found in <data>
+				
 				</td>
 			 </tr>
             
@@ -55249,15 +69210,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>dob</td>
-            	<td>date</td>
+            	<td>atc_brand</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>date of birth as found in <data>
+				
 				</td>
 			 </tr>
             
@@ -55265,7 +69226,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>postcode</td>
+            	<td>external_code_brand</td>
             	<td>text</td>
                 <td><i>
 				
@@ -55273,7 +69234,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 				
 				</i>
-				<br><br>postcode as found in <data>
+				
 				</td>
 			 </tr>
             
@@ -55281,7 +69242,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>other_info</td>
+            	<td>external_code_type_brand</td>
             	<td>text</td>
                 <td><i>
 				
@@ -55289,7 +69250,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				
 				
 				</i>
-				<br><br>other identifying information as found in <data>
+				
 				</td>
 			 </tr>
             
@@ -55297,16 +69258,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>type</td>
-            	<td>text</td>
+            	<td>started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>the type of <data>, eg HL7, LDT, ...,
-	 useful for selecting an importer
+				
 				</td>
 			 </tr>
             
@@ -55314,15 +69274,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>data</td>
-            	<td>bytea</td>
+            	<td>comment_on_start</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>the raw data
+				
 				</td>
 			 </tr>
             
@@ -55330,15 +69290,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>gender</td>
-            	<td>text</td>
+            	<td>start_is_unknown</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>Gender of patient in source data if available.
+				
 				</td>
 			 </tr>
             
@@ -55346,15 +69306,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>requestor</td>
-            	<td>text</td>
+            	<td>start_is_approximate</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>Requestor of data (e.g. who ordered test results) if available in source data.
+				
 				</td>
 			 </tr>
             
@@ -55362,39 +69322,31 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>external_data_id</td>
-            	<td>text</td>
+            	<td>intake_is_approved_of</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>ID of content of .data in external system (e.g. importer) where appropriate
+				
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.patient">clin.patient.fk_identity</a>
-                  
-                
                 </td>
-            	<td>fk_identity_disambiguated</td>
+            	<td>harmful_use_type</td>
             	<td>integer</td>
                 <td><i>
 				
-					
-
-					
-				
 
 				
 				
 				</i>
-				<br><br>ID of patient the data is judged to really belong to.
+				
 				</td>
 			 </tr>
             
@@ -55402,123 +69354,45 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>last_checked_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>a free text comment on this row, eg. why is it here
+				
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.pk</a>
-                  
-                
                 </td>
-            	<td>fk_provider_disambiguated</td>
-            	<td>integer</td>
+            	<td>schedule</td>
+            	<td>text</td>
                 <td><i>
 				
-					
-
-					
-				
 
 				
 				
 				</i>
-				<br><br>The provider the data is relevant to.
+				
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table clin.incoming_data_unmatched Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.incoming_data_unmatched Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>unmatched_data_sane_comment</td>
-                <td>CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE))</td>
-            </tr>
-			
-		</table>
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lab-request">lab_request</a>
-		</h2>
-        
-         <p>test request metadata</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.lab_request Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
+            	<td>duration</td>
+            	<td>interval</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -55528,12 +69402,12 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>discontinued</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -55544,13 +69418,13 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>discontinue_reason</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -55560,13 +69434,13 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>is_long_term</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -55576,13 +69450,13 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
-            	<td>integer</td>
+            	<td>aim</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('clin_root_item_pk_item_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -55592,38 +69466,28 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>episode</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
-				<br><br>the time the sample for this request was taken
-	 LDT: 8432:8433
-	 HL7: OBR.quantity_timing
+				
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
-                  
-                
                 </td>
-            	<td>fk_encounter</td>
-            	<td>integer</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
-					
 
-					
 				
-
-				NOT NULL
 				
 				</i>
 				
@@ -55633,21 +69497,13 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
-                  
-                
                 </td>
-            	<td>fk_episode</td>
-            	<td>integer</td>
+            	<td>notes</td>
+            	<td>text</td>
                 <td><i>
 				
-					
 
-					
 				
-
-				NOT NULL
 				
 				</i>
 				
@@ -55658,15 +69514,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>narrative</td>
-            	<td>text</td>
+            	<td>fake_brand</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>free text comment on request
+				
 				</td>
 			 </tr>
             
@@ -55674,13 +69530,13 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>is_currently_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
 				
-				DEFAULT 'p'::text
+				
 				</i>
 				
 				</td>
@@ -55689,18 +69545,11 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>seems_inactive</td>
+            	<td>boolean</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -55712,27 +69561,11 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.test-org">clin.test_org.pk</a>
-                  
-                
-                  
-                
                 </td>
-            	<td>fk_test_org</td>
+            	<td>pk_brand</td>
             	<td>integer</td>
                 <td><i>
 				
-					
-
-					
-				
-					
-
-					
-                       UNIQUE#1
-                    
-				
 
 				
 				
@@ -55744,50 +69577,32 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>request_id</td>
-            	<td>text</td>
+            	<td>pk_data_source</td>
+            	<td>integer</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>ID this request had when sent to the lab
-	 LDT: 8310
-	 HL7: OBR.filler_order_number
+				
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.identity">dem.identity.pk</a>
-                  
-                
                 </td>
-            	<td>fk_requestor</td>
+            	<td>pk_substance</td>
             	<td>integer</td>
                 <td><i>
 				
-					
-
-					
-				
 
 				
 				
 				</i>
-				<br><br>who requested the test - really needed ?
+				
 				</td>
 			 </tr>
             
@@ -55795,16 +69610,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>lab_request_id</td>
-            	<td>text</td>
+            	<td>pk_drug_component</td>
+            	<td>integer</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>ID this request had internally at the lab
-	 LDT: 8311
+				
 				</td>
 			 </tr>
             
@@ -55812,17 +69626,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>lab_rxd_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>when did the lab receive the request+sample
-	 LDT: 8301
-	 HL7: OBR.requested_date_time
+				
 				</td>
 			 </tr>
             
@@ -55830,17 +69642,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>results_reported_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>when was the report on the result generated,
-	LDT: 8302
-	HL7: OBR.results_report_status_change
+				
 				</td>
 			 </tr>
             
@@ -55848,16 +69658,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>request_status</td>
-            	<td>text</td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>pending, final, preliminary, partial
-	 LDT: 8401
+				
 				</td>
 			 </tr>
             
@@ -55865,15 +69674,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>is_pending</td>
-            	<td>boolean</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT true
+				
+				
 				</i>
-				<br><br>true if any (even partial) results are still pending
+				
 				</td>
 			 </tr>
             
@@ -55881,18 +69690,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>diagnostic_service_section</td>
-            	<td>text</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>The (section of) the diagnostic service which performed the test.
-- HL7 2.3: OBR:24 Diagnostic Service Section ID
-- somewhat redundant with fk_test_org, which, however,
-  points to more normalized data
+				
 				</td>
 			 </tr>
             
@@ -55900,16 +69706,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>ordered_service</td>
-            	<td>text</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>The (battery of) test(s)/service(s) ordered.
-- HL7 2.3: OBR:4 Universal Service ID
+				
 				</td>
 			 </tr>
             
@@ -55917,15 +69722,15 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>note_test_org</td>
-            	<td>text</td>
+            	<td>xmin_substance_intake</td>
+            	<td>xid</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>A comment on this lab request by the performing organization (lab).
+				
 				</td>
 			 </tr>
             
@@ -55933,70 +69738,197 @@ D: proven diagnosis (diagnostisch gesichert)
 
         <!-- Inherits -->
 		
-        <p>Table clin.lab_request Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin_root_item</a>, 
-        
-        </p>
-		
 
 		
-		
-		
 
         <!-- Constraint List -->
 		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.lab_request Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>clin_lab_req_sane_test_org_note</td>
-                <td>CHECK ((gm.is_null_or_non_empty_string(note_test_org) IS TRUE))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>clin_root_item_sane_soap_cat</td>
-                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>lab_request_request_id_check</td>
-                <td>CHECK ((btrim(request_id) <> ''::text))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>lab_request_request_status_check</td>
-                <td>CHECK ((request_status = ANY (ARRAY['pending'::text, 'preliminary'::text, 'partial'::text, 'final'::text])))</td>
-            </tr>
-			
-		</table>
-		
 
         <!-- Foreign Key Discovery -->
 		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.test-result">clin.test_result</a></li>
-			</ul>
-		
-		
 
     <!-- Indexes -->
     
-       idx_clin_lab_request_fk_encounter fk_encounter
-    
-       idx_clin_lab_request_fk_episode fk_episode
-    
 
 	<!-- View Definition -->
 	
+	<pre>
+SELECT c_si.pk AS pk_substance_intake
+,
+    
+(
+SELECT encounter.fk_patient
+           
+  FROM clin.encounter
+          
+ WHERE (encounter.pk = c_si.fk_encounter)
+) AS pk_patient
+,
+    c_si.soap_cat
+,
+    r_bd.description AS brand
+,
+    r_bd.preparation
+,
+    r_cs.description AS substance
+,
+    r_cs.amount
+,
+    r_cs.unit
+,
+    r_cs.atc_code AS atc_substance
+,
+    r_bd.atc_code AS atc_brand
+,
+    r_bd.external_code AS external_code_brand
+,
+    r_bd.external_code_type AS external_code_type_brand
+,
+        CASE
+            WHEN 
+(c_si.comment_on_start = '?'::text) THEN NULL::timestamp with time zone
+            ELSE c_si.clin_when
+        END AS started
+,
+    c_si.comment_on_start
+,
+        CASE
+            WHEN 
+(c_si.comment_on_start = '?'::text) THEN true
+            ELSE false
+        END AS start_is_unknown
+,
+        CASE
+            WHEN 
+(c_si.comment_on_start IS NULL) THEN false
+            ELSE true
+        END AS start_is_approximate
+,
+    c_si.intake_is_approved_of
+,
+    c_si.harmful_use_type
+,
+    NULL::timestamp with time zone AS last_checked_when
+,
+    c_si.schedule
+,
+    c_si.duration
+,
+    c_si.discontinued
+,
+    c_si.discontinue_reason
+,
+    c_si.is_long_term
+,
+    c_si.aim
+,
+    cep.description AS episode
+,
+    c_hi.description AS health_issue
+,
+    c_si.narrative AS notes
+,
+    r_bd.is_fake AS fake_brand
+,
+        CASE
+            WHEN 
+(c_si.discontinued IS NULL) THEN true
+            ELSE false
+        END AS is_currently_active
+,
+        CASE
+            WHEN 
+(c_si.discontinued IS NOT NULL) THEN true
+            WHEN 
+(c_si.clin_when IS NULL) THEN
+            CASE
+                WHEN 
+(c_si.is_long_term IS TRUE) THEN false
+                ELSE NULL::boolean
+            END
+            WHEN 
+(
+     (c_si.clin_when > now
+           ()
+     ) IS TRUE
+) THEN true
+            WHEN 
+(
+     (
+           (c_si.clin_when + c_si.duration) < now
+           ()
+     ) IS TRUE
+) THEN true
+            WHEN 
+(
+     (
+           (c_si.clin_when + c_si.duration) > now
+           ()
+     ) IS TRUE
+) THEN false
+            ELSE NULL::boolean
+        END AS seems_inactive
+,
+    r_ls2b.fk_brand AS pk_brand
+,
+    r_bd.fk_data_source AS pk_data_source
+,
+    r_ls2b.fk_substance AS pk_substance
+,
+    r_ls2b.pk AS pk_drug_component
+,
+    c_si.fk_encounter AS pk_encounter
+,
+    c_si.fk_episode AS pk_episode
+,
+    cep.fk_health_issue AS pk_health_issue
+,
+    c_si.modified_when
+,
+    c_si.modified_by
+,
+    c_si.row_version
+,
+    c_si.xmin AS xmin_substance_intake
+   
+FROM (
+     (
+           (
+                 (
+                       (clin.substance_intake c_si
+     
+                          JOIN ref.lnk_substance2brand r_ls2b 
+                            ON (
+                                   (c_si.fk_drug_component = r_ls2b.pk)
+                             )
+                       )
+     
+                    JOIN ref.branded_drug r_bd 
+                      ON (
+                             (r_ls2b.fk_brand = r_bd.pk)
+                       )
+                 )
+     
+              JOIN ref.consumable_substance r_cs 
+                ON (
+                       (r_ls2b.fk_substance = r_cs.pk)
+                 )
+           )
+     
+   LEFT JOIN clin.episode cep 
+          ON (
+                 (c_si.fk_episode = cep.pk)
+           )
+     )
+     
+LEFT JOIN clin.health_issue c_hi 
+    ON (
+           (c_hi.pk = cep.fk_health_issue)
+     )
+)
+  
+WHERE (c_si.fk_drug_component IS NOT NULL);</pre>
+	
 
 	<!-- List off permissions -->
 	
@@ -56007,35 +69939,97 @@ D: proven diagnosis (diagnostisch gesichert)
     </p>
 	
         <hr>
-		<h2>Table:
+		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-code2aoe">lnk_code2aoe</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-edc-journal">v_edc_journal</a>
 		</h2>
         
-         <p>Links codes to encounter.aoe.</p>
-        
 
 
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.lnk_code2aoe Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.v_edc_journal Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -56045,12 +70039,12 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>narrative</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -56061,13 +70055,13 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -56077,13 +70071,13 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -56093,13 +70087,13 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>pk_lnk_code2item</td>
+            	<td>pk_health_issue</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('lnk_code2item_root_pk_lnk_code2item_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -56108,56 +70102,32 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr1">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>fk_generic_code</td>
+            	<td>src_pk</td>
             	<td>integer</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>Custom foreign key to ref.coding_system_root.
+				
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
-                  
-                
                 </td>
-            	<td>fk_item</td>
-            	<td>integer</td>
+            	<td>src_table</td>
+            	<td>text</td>
                 <td><i>
 				
-					
-
-					
-                       UNIQUE#1
-                    
-				
-					
-
-					
-				
 
 				
 				
 				</i>
-				<br><br>Foreign key to clin.encounter
+				
 				</td>
 			 </tr>
             
@@ -56165,8 +70135,8 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>code_modifier</td>
-            	<td>text</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -56180,18 +70150,11 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -56200,74 +70163,33 @@ D: proven diagnosis (diagnostisch gesichert)
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table clin.lnk_code2aoe Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#clin.table.lnk-code2item-root">lnk_code2item_root</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-       idx_c_lc2aoe_fk_item fk_item
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-code2episode">lnk_code2episode</a>
-		</h2>
-        
-         <p>Links codes to episodes.</p>
-        
-
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>issue_laterality</td>
+            	<td>text</td>
+                <td><i>
+				
 
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.lnk_code2episode Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -56277,12 +70199,12 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -56293,13 +70215,13 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -56309,13 +70231,13 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>episode</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -56325,13 +70247,13 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>pk_lnk_code2item</td>
-            	<td>integer</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('lnk_code2item_root_pk_lnk_code2item_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -56340,56 +70262,32 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr1">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>fk_generic_code</td>
-            	<td>integer</td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>Custom foreign key to ref.coding_system_root.
+				
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
-                  
-                
                 </td>
-            	<td>fk_item</td>
-            	<td>integer</td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
-					
-
-					
-                       UNIQUE#1
-                    
-				
-					
-
-					
-				
 
 				
 				
 				</i>
-				<br><br>Foreign key to clin.episode
+				
 				</td>
 			 </tr>
             
@@ -56397,7 +70295,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>code_modifier</td>
+            	<td>encounter_type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -56412,18 +70310,11 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>encounter_l10n_type</td>
+            	<td>text</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -56436,17 +70327,8 @@ D: proven diagnosis (diagnostisch gesichert)
 
         <!-- Inherits -->
 		
-        <p>Table clin.lnk_code2episode Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#clin.table.lnk-code2item-root">lnk_code2item_root</a>, 
-        
-        </p>
-		
 
 		
-		
-		
 
         <!-- Constraint List -->
 		
@@ -56456,11 +70338,91 @@ D: proven diagnosis (diagnostisch gesichert)
 
     <!-- Indexes -->
     
-       idx_c_lc2epi_fk_item fk_item
-    
 
 	<!-- View Definition -->
 	
+	<pre>
+SELECT c_p.fk_identity AS pk_patient
+,
+    c_p.modified_when
+,
+    c_p.modified_when AS clin_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_p.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (c_p.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    's'::text AS soap_cat
+,
+    
+(_
+     ('EDC'::text) || to_char
+     (
+           (c_p.edc)::timestamp with time zone
+           ,': YYYY Mon DD'::text
+     )
+) AS narrative
+,
+    
+(
+SELECT c_e.pk
+           
+  FROM clin.encounter c_e
+          
+ WHERE (c_e.fk_patient = c_p.fk_identity)
+          
+ORDER BY c_e.started DESC
+         LIMIT 1
+) AS pk_encounter
+,
+    NULL::integer AS pk_episode
+,
+    NULL::integer AS pk_health_issue
+,
+    c_p.pk AS src_pk
+,
+    'clin.patient'::text AS src_table
+,
+    c_p.row_version
+,
+    NULL::text AS health_issue
+,
+    NULL::text AS issue_laterality
+,
+    NULL::boolean AS issue_active
+,
+    NULL::boolean AS issue_clinically_relevant
+,
+    NULL::boolean AS issue_confidential
+,
+    NULL::text AS episode
+,
+    NULL::boolean AS episode_open
+,
+    NULL::timestamp with time zone AS encounter_started
+,
+    NULL::timestamp with time zone AS encounter_last_affirmed
+,
+    NULL::text AS encounter_type
+,
+    NULL::text AS encounter_l10n_type
+   
+FROM clin.patient c_p
+  
+WHERE (c_p.edc IS NOT NULL);</pre>
+	
 
 	<!-- List off permissions -->
 	
@@ -56471,17 +70433,20 @@ D: proven diagnosis (diagnostisch gesichert)
     </p>
 	
         <hr>
-		<h2>Table:
+		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-code2fhx">lnk_code2fhx</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-emr-journal">v_emr_journal</a>
 		</h2>
         
-         <p>Links codes to family history items.</p>
+         <p>Clinical patient data formatted into one string per
+	 clinical entity even if it constains several user-
+	 visible fields. Mainly useful for display as a simple
+	 EMR journal.</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.lnk_code2fhx Structure</caption>
+                <caption>clin.v_emr_journal Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -56493,35 +70458,19 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
+            	<td>pk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>row_version</td>
-            	<td>integer</td>
-                <td><i>
 				
-
-				NOT NULL
 				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -56530,24 +70479,8 @@ D: proven diagnosis (diagnostisch gesichert)
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
-				</i>
 				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>modified_by</td>
-            	<td>name</td>
-                <td><i>
 				
-
-				NOT NULL
-				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -56557,13 +70490,13 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>pk_lnk_code2item</td>
-            	<td>integer</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('lnk_code2item_root_pk_lnk_code2item_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -56572,56 +70505,32 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr1">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>fk_generic_code</td>
-            	<td>integer</td>
+            	<td>modified_by</td>
+            	<td>text</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>Custom foreign key to ref.coding_system_root.
+				
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.family-history">clin.family_history.pk</a>
-                  
-                
                 </td>
-            	<td>fk_item</td>
-            	<td>integer</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
-					
-
-					
-                       UNIQUE#1
-                    
-				
-					
-
-					
-				
 
 				
 				
 				</i>
-				<br><br>Foreign key to clin.family_history
+				
 				</td>
 			 </tr>
             
@@ -56629,7 +70538,7 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>code_modifier</td>
+            	<td>narrative</td>
             	<td>text</td>
                 <td><i>
 				
@@ -56644,18 +70553,11 @@ D: proven diagnosis (diagnostisch gesichert)
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -56664,89 +70566,16 @@ D: proven diagnosis (diagnostisch gesichert)
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table clin.lnk_code2fhx Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#clin.table.lnk-code2item-root">lnk_code2item_root</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-       idx_c_lc2fhx_fk_item fk_item
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-code2h-issue">lnk_code2h_issue</a>
-		</h2>
-        
-         <p>Links codes to health issues.</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.lnk_code2h_issue Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
-				</i>
-				
-				</td>
-			 </tr>
-            
             <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>row_version</td>
+            	<td>pk_episode</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -56757,111 +70586,71 @@ D: proven diagnosis (diagnostisch gesichert)
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
-				</i>
 				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>modified_by</td>
-            	<td>name</td>
-                <td><i>
 				
-
-				NOT NULL
-				DEFAULT "current_user"()
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>pk_lnk_code2item</td>
+            	<td>src_pk</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('lnk_code2item_root_pk_lnk_code2item_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>fk_generic_code</td>
-            	<td>integer</td>
+            	<td>src_table</td>
+            	<td>text</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>Custom foreign key to ref.coding_system_root.
+				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
-				<td>
-                
-                  
-                
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.health-issue">clin.health_issue.pk</a>
-                  
+            <tr class="tr1">
+				<td>
                 
                 </td>
-            	<td>fk_item</td>
+            	<td>row_version</td>
             	<td>integer</td>
                 <td><i>
 				
-					
-
-					
-                       UNIQUE#1
-                    
-				
-					
-
-					
-				
 
 				
 				
 				</i>
-				<br><br>Foreign key to clin.health_issue
+				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>code_modifier</td>
+            	<td>health_issue</td>
             	<td>text</td>
                 <td><i>
 				
@@ -56873,21 +70662,14 @@ D: proven diagnosis (diagnostisch gesichert)
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>issue_laterality</td>
+            	<td>character varying</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -56896,80 +70678,17 @@ D: proven diagnosis (diagnostisch gesichert)
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table clin.lnk_code2h_issue Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#clin.table.lnk-code2item-root">lnk_code2item_root</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-       idx_c_lc2iss_fk_item fk_item
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-code2item-root">lnk_code2item_root</a>
-		</h2>
-        
-         <p>The parent table of all tables linking codes to EMR structures.
-Coding tables check this table for existence of their PK in
-.fk_generic_code in order to prevent cascading DELETEs/UPDATEs
-from breaking referential integrity.
-EMR structure tables foreign key into children of this table in
-order to link structures to codes.
-</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.lnk_code2item_root Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -56979,12 +70698,12 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -56995,13 +70714,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -57011,13 +70730,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>episode</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -57026,18 +70745,11 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk_lnk_code2item</td>
-            	<td>serial</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -57050,15 +70762,15 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>fk_generic_code</td>
-            	<td>integer</td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>Custom foreign key to ref.coding_system_root.pk_coding_system.
+				
 				</td>
 			 </tr>
             
@@ -57066,15 +70778,15 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>fk_item</td>
-            	<td>integer</td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>Foreign key to clin.* tables
+				
 				</td>
 			 </tr>
             
@@ -57082,7 +70794,7 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>code_modifier</td>
+            	<td>encounter_type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -57090,7 +70802,23 @@ order to link structures to codes.
 				
 				
 				</i>
-				<br><br>Usage specific modifier on the base code, say, certainty or laterality of ICD-10 codes.
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>encounter_l10n_type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
 				</td>
 			 </tr>
             
@@ -57098,17 +70826,8 @@ order to link structures to codes.
 
         <!-- Inherits -->
 		
-        <p>Table clin.lnk_code2item_root Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
 
 		
-		
-		
 
         <!-- Constraint List -->
 		
@@ -57121,6 +70840,855 @@ order to link structures to codes.
 
 	<!-- View Definition -->
 	
+	<pre>
+SELECT v_pat_narrative_journal.pk_patient
+,
+    v_pat_narrative_journal.modified_when
+,
+    v_pat_narrative_journal.clin_when
+,
+    v_pat_narrative_journal.modified_by
+,
+    v_pat_narrative_journal.soap_cat
+,
+    v_pat_narrative_journal.narrative
+,
+    v_pat_narrative_journal.pk_encounter
+,
+    v_pat_narrative_journal.pk_episode
+,
+    v_pat_narrative_journal.pk_health_issue
+,
+    v_pat_narrative_journal.src_pk
+,
+    v_pat_narrative_journal.src_table
+,
+    v_pat_narrative_journal.row_version
+,
+    v_pat_narrative_journal.health_issue
+,
+    v_pat_narrative_journal.issue_laterality
+,
+    v_pat_narrative_journal.issue_active
+,
+    v_pat_narrative_journal.issue_clinically_relevant
+,
+    v_pat_narrative_journal.issue_confidential
+,
+    v_pat_narrative_journal.episode
+,
+    v_pat_narrative_journal.episode_open
+,
+    v_pat_narrative_journal.encounter_started
+,
+    v_pat_narrative_journal.encounter_last_affirmed
+,
+    v_pat_narrative_journal.encounter_type
+,
+    v_pat_narrative_journal.encounter_l10n_type
+   
+FROM clin.v_pat_narrative_journal
+
+UNION ALL
+ 
+SELECT v_health_issues_journal.pk_patient
+,
+    v_health_issues_journal.modified_when
+,
+    v_health_issues_journal.clin_when
+,
+    v_health_issues_journal.modified_by
+,
+    v_health_issues_journal.soap_cat
+,
+    v_health_issues_journal.narrative
+,
+    v_health_issues_journal.pk_encounter
+,
+    v_health_issues_journal.pk_episode
+,
+    v_health_issues_journal.pk_health_issue
+,
+    v_health_issues_journal.src_pk
+,
+    v_health_issues_journal.src_table
+,
+    v_health_issues_journal.row_version
+,
+    v_health_issues_journal.health_issue
+,
+    v_health_issues_journal.issue_laterality
+,
+    v_health_issues_journal.issue_active
+,
+    v_health_issues_journal.issue_clinically_relevant
+,
+    v_health_issues_journal.issue_confidential
+,
+    v_health_issues_journal.episode
+,
+    v_health_issues_journal.episode_open
+,
+    v_health_issues_journal.encounter_started
+,
+    v_health_issues_journal.encounter_last_affirmed
+,
+    v_health_issues_journal.encounter_type
+,
+    v_health_issues_journal.encounter_l10n_type
+   
+FROM clin.v_health_issues_journal
+
+UNION ALL
+ 
+SELECT v_pat_encounters_journal.pk_patient
+,
+    v_pat_encounters_journal.modified_when
+,
+    v_pat_encounters_journal.clin_when
+,
+    v_pat_encounters_journal.modified_by
+,
+    v_pat_encounters_journal.soap_cat
+,
+    v_pat_encounters_journal.narrative
+,
+    v_pat_encounters_journal.pk_encounter
+,
+    v_pat_encounters_journal.pk_episode
+,
+    v_pat_encounters_journal.pk_health_issue
+,
+    v_pat_encounters_journal.src_pk
+,
+    v_pat_encounters_journal.src_table
+,
+    v_pat_encounters_journal.row_version
+,
+    v_pat_encounters_journal.health_issue
+,
+    v_pat_encounters_journal.issue_laterality
+,
+    v_pat_encounters_journal.issue_active
+,
+    v_pat_encounters_journal.issue_clinically_relevant
+,
+    v_pat_encounters_journal.issue_confidential
+,
+    v_pat_encounters_journal.episode
+,
+    v_pat_encounters_journal.episode_open
+,
+    v_pat_encounters_journal.encounter_started
+,
+    v_pat_encounters_journal.encounter_last_affirmed
+,
+    v_pat_encounters_journal.encounter_type
+,
+    v_pat_encounters_journal.encounter_l10n_type
+   
+FROM clin.v_pat_encounters_journal
+
+UNION ALL
+ 
+SELECT v_pat_episodes_journal.pk_patient
+,
+    v_pat_episodes_journal.modified_when
+,
+    v_pat_episodes_journal.clin_when
+,
+    v_pat_episodes_journal.modified_by
+,
+    v_pat_episodes_journal.soap_cat
+,
+    v_pat_episodes_journal.narrative
+,
+    v_pat_episodes_journal.pk_encounter
+,
+    v_pat_episodes_journal.pk_episode
+,
+    v_pat_episodes_journal.pk_health_issue
+,
+    v_pat_episodes_journal.src_pk
+,
+    v_pat_episodes_journal.src_table
+,
+    v_pat_episodes_journal.row_version
+,
+    v_pat_episodes_journal.health_issue
+,
+    v_pat_episodes_journal.issue_laterality
+,
+    v_pat_episodes_journal.issue_active
+,
+    v_pat_episodes_journal.issue_clinically_relevant
+,
+    v_pat_episodes_journal.issue_confidential
+,
+    v_pat_episodes_journal.episode
+,
+    v_pat_episodes_journal.episode_open
+,
+    v_pat_episodes_journal.encounter_started
+,
+    v_pat_episodes_journal.encounter_last_affirmed
+,
+    v_pat_episodes_journal.encounter_type
+,
+    v_pat_episodes_journal.encounter_l10n_type
+   
+FROM clin.v_pat_episodes_journal
+
+UNION ALL
+ 
+SELECT v_family_history_journal.pk_patient
+,
+    v_family_history_journal.modified_when
+,
+    v_family_history_journal.clin_when
+,
+    v_family_history_journal.modified_by
+,
+    v_family_history_journal.soap_cat
+,
+    v_family_history_journal.narrative
+,
+    v_family_history_journal.pk_encounter
+,
+    v_family_history_journal.pk_episode
+,
+    v_family_history_journal.pk_health_issue
+,
+    v_family_history_journal.src_pk
+,
+    v_family_history_journal.src_table
+,
+    v_family_history_journal.row_version
+,
+    v_family_history_journal.health_issue
+,
+    v_family_history_journal.issue_laterality
+,
+    v_family_history_journal.issue_active
+,
+    v_family_history_journal.issue_clinically_relevant
+,
+    v_family_history_journal.issue_confidential
+,
+    v_family_history_journal.episode
+,
+    v_family_history_journal.episode_open
+,
+    v_family_history_journal.encounter_started
+,
+    v_family_history_journal.encounter_last_affirmed
+,
+    v_family_history_journal.encounter_type
+,
+    v_family_history_journal.encounter_l10n_type
+   
+FROM clin.v_family_history_journal
+
+UNION ALL
+ 
+SELECT v_pat_allergies_journal.pk_patient
+,
+    v_pat_allergies_journal.modified_when
+,
+    v_pat_allergies_journal.clin_when
+,
+    v_pat_allergies_journal.modified_by
+,
+    v_pat_allergies_journal.soap_cat
+,
+    v_pat_allergies_journal.narrative
+,
+    v_pat_allergies_journal.pk_encounter
+,
+    v_pat_allergies_journal.pk_episode
+,
+    v_pat_allergies_journal.pk_health_issue
+,
+    v_pat_allergies_journal.src_pk
+,
+    v_pat_allergies_journal.src_table
+,
+    v_pat_allergies_journal.row_version
+,
+    v_pat_allergies_journal.health_issue
+,
+    v_pat_allergies_journal.issue_laterality
+,
+    v_pat_allergies_journal.issue_active
+,
+    v_pat_allergies_journal.issue_clinically_relevant
+,
+    v_pat_allergies_journal.issue_confidential
+,
+    v_pat_allergies_journal.episode
+,
+    v_pat_allergies_journal.episode_open
+,
+    v_pat_allergies_journal.encounter_started
+,
+    v_pat_allergies_journal.encounter_last_affirmed
+,
+    v_pat_allergies_journal.encounter_type
+,
+    v_pat_allergies_journal.encounter_l10n_type
+   
+FROM clin.v_pat_allergies_journal
+
+UNION ALL
+ 
+SELECT v_pat_allergy_state_journal.pk_patient
+,
+    v_pat_allergy_state_journal.modified_when
+,
+    v_pat_allergy_state_journal.clin_when
+,
+    v_pat_allergy_state_journal.modified_by
+,
+    v_pat_allergy_state_journal.soap_cat
+,
+    v_pat_allergy_state_journal.narrative
+,
+    v_pat_allergy_state_journal.pk_encounter
+,
+    v_pat_allergy_state_journal.pk_episode
+,
+    v_pat_allergy_state_journal.pk_health_issue
+,
+    v_pat_allergy_state_journal.src_pk
+,
+    v_pat_allergy_state_journal.src_table
+,
+    v_pat_allergy_state_journal.row_version
+,
+    v_pat_allergy_state_journal.health_issue
+,
+    v_pat_allergy_state_journal.issue_laterality
+,
+    v_pat_allergy_state_journal.issue_active
+,
+    v_pat_allergy_state_journal.issue_clinically_relevant
+,
+    v_pat_allergy_state_journal.issue_confidential
+,
+    v_pat_allergy_state_journal.episode
+,
+    v_pat_allergy_state_journal.episode_open
+,
+    v_pat_allergy_state_journal.encounter_started
+,
+    v_pat_allergy_state_journal.encounter_last_affirmed
+,
+    v_pat_allergy_state_journal.encounter_type
+,
+    v_pat_allergy_state_journal.encounter_l10n_type
+   
+FROM clin.v_pat_allergy_state_journal
+
+UNION ALL
+ 
+SELECT v_test_results_journal.pk_patient
+,
+    v_test_results_journal.modified_when
+,
+    v_test_results_journal.clin_when
+,
+    v_test_results_journal.modified_by
+,
+    v_test_results_journal.soap_cat
+,
+    v_test_results_journal.narrative
+,
+    v_test_results_journal.pk_encounter
+,
+    v_test_results_journal.pk_episode
+,
+    v_test_results_journal.pk_health_issue
+,
+    v_test_results_journal.src_pk
+,
+    v_test_results_journal.src_table
+,
+    v_test_results_journal.row_version
+,
+    v_test_results_journal.health_issue
+,
+    v_test_results_journal.issue_laterality
+,
+    v_test_results_journal.issue_active
+,
+    v_test_results_journal.issue_clinically_relevant
+,
+    v_test_results_journal.issue_confidential
+,
+    v_test_results_journal.episode
+,
+    v_test_results_journal.episode_open
+,
+    v_test_results_journal.encounter_started
+,
+    v_test_results_journal.encounter_last_affirmed
+,
+    v_test_results_journal.encounter_type
+,
+    v_test_results_journal.encounter_l10n_type
+   
+FROM clin.v_test_results_journal
+
+UNION ALL
+ 
+SELECT v_hospital_stays_journal.pk_patient
+,
+    v_hospital_stays_journal.modified_when
+,
+    v_hospital_stays_journal.clin_when
+,
+    v_hospital_stays_journal.modified_by
+,
+    v_hospital_stays_journal.soap_cat
+,
+    v_hospital_stays_journal.narrative
+,
+    v_hospital_stays_journal.pk_encounter
+,
+    v_hospital_stays_journal.pk_episode
+,
+    v_hospital_stays_journal.pk_health_issue
+,
+    v_hospital_stays_journal.src_pk
+,
+    v_hospital_stays_journal.src_table
+,
+    v_hospital_stays_journal.row_version
+,
+    v_hospital_stays_journal.health_issue
+,
+    v_hospital_stays_journal.issue_laterality
+,
+    v_hospital_stays_journal.issue_active
+,
+    v_hospital_stays_journal.issue_clinically_relevant
+,
+    v_hospital_stays_journal.issue_confidential
+,
+    v_hospital_stays_journal.episode
+,
+    v_hospital_stays_journal.episode_open
+,
+    v_hospital_stays_journal.encounter_started
+,
+    v_hospital_stays_journal.encounter_last_affirmed
+,
+    v_hospital_stays_journal.encounter_type
+,
+    v_hospital_stays_journal.encounter_l10n_type
+   
+FROM clin.v_hospital_stays_journal
+
+UNION ALL
+ 
+SELECT v_doc_med_journal.pk_patient
+,
+    v_doc_med_journal.modified_when
+,
+    v_doc_med_journal.clin_when
+,
+    v_doc_med_journal.modified_by
+,
+    v_doc_med_journal.soap_cat
+,
+    v_doc_med_journal.narrative
+,
+    v_doc_med_journal.pk_encounter
+,
+    v_doc_med_journal.pk_episode
+,
+    v_doc_med_journal.pk_health_issue
+,
+    v_doc_med_journal.src_pk
+,
+    v_doc_med_journal.src_table
+,
+    v_doc_med_journal.row_version
+,
+    v_doc_med_journal.health_issue
+,
+    v_doc_med_journal.issue_laterality
+,
+    v_doc_med_journal.issue_active
+,
+    v_doc_med_journal.issue_clinically_relevant
+,
+    v_doc_med_journal.issue_confidential
+,
+    v_doc_med_journal.episode
+,
+    v_doc_med_journal.episode_open
+,
+    v_doc_med_journal.encounter_started
+,
+    v_doc_med_journal.encounter_last_affirmed
+,
+    v_doc_med_journal.encounter_type
+,
+    v_doc_med_journal.encounter_l10n_type
+   
+FROM blobs.v_doc_med_journal
+
+UNION ALL
+ 
+SELECT v_substance_intake_journal.pk_patient
+,
+    v_substance_intake_journal.modified_when
+,
+    v_substance_intake_journal.clin_when
+,
+    v_substance_intake_journal.modified_by
+,
+    v_substance_intake_journal.soap_cat
+,
+    v_substance_intake_journal.narrative
+,
+    v_substance_intake_journal.pk_encounter
+,
+    v_substance_intake_journal.pk_episode
+,
+    v_substance_intake_journal.pk_health_issue
+,
+    v_substance_intake_journal.src_pk
+,
+    v_substance_intake_journal.src_table
+,
+    v_substance_intake_journal.row_version
+,
+    v_substance_intake_journal.health_issue
+,
+    v_substance_intake_journal.issue_laterality
+,
+    v_substance_intake_journal.issue_active
+,
+    v_substance_intake_journal.issue_clinically_relevant
+,
+    v_substance_intake_journal.issue_confidential
+,
+    v_substance_intake_journal.episode
+,
+    v_substance_intake_journal.episode_open
+,
+    v_substance_intake_journal.encounter_started
+,
+    v_substance_intake_journal.encounter_last_affirmed
+,
+    v_substance_intake_journal.encounter_type
+,
+    v_substance_intake_journal.encounter_l10n_type
+   
+FROM clin.v_substance_intake_journal
+
+UNION ALL
+ 
+SELECT v_procedures_journal.pk_patient
+,
+    v_procedures_journal.modified_when
+,
+    v_procedures_journal.clin_when
+,
+    v_procedures_journal.modified_by
+,
+    v_procedures_journal.soap_cat
+,
+    v_procedures_journal.narrative
+,
+    v_procedures_journal.pk_encounter
+,
+    v_procedures_journal.pk_episode
+,
+    v_procedures_journal.pk_health_issue
+,
+    v_procedures_journal.src_pk
+,
+    v_procedures_journal.src_table
+,
+    v_procedures_journal.row_version
+,
+    v_procedures_journal.health_issue
+,
+    v_procedures_journal.issue_laterality
+,
+    v_procedures_journal.issue_active
+,
+    v_procedures_journal.issue_clinically_relevant
+,
+    v_procedures_journal.issue_confidential
+,
+    v_procedures_journal.episode
+,
+    v_procedures_journal.episode_open
+,
+    v_procedures_journal.encounter_started
+,
+    v_procedures_journal.encounter_last_affirmed
+,
+    v_procedures_journal.encounter_type
+,
+    v_procedures_journal.encounter_l10n_type
+   
+FROM clin.v_procedures_journal
+
+UNION ALL
+ 
+SELECT v_vaccinations_journal.pk_patient
+,
+    v_vaccinations_journal.modified_when
+,
+    v_vaccinations_journal.clin_when
+,
+    v_vaccinations_journal.modified_by
+,
+    v_vaccinations_journal.soap_cat
+,
+    v_vaccinations_journal.narrative
+,
+    v_vaccinations_journal.pk_encounter
+,
+    v_vaccinations_journal.pk_episode
+,
+    v_vaccinations_journal.pk_health_issue
+,
+    v_vaccinations_journal.src_pk
+,
+    v_vaccinations_journal.src_table
+,
+    v_vaccinations_journal.row_version
+,
+    v_vaccinations_journal.health_issue
+,
+    v_vaccinations_journal.issue_laterality
+,
+    v_vaccinations_journal.issue_active
+,
+    v_vaccinations_journal.issue_clinically_relevant
+,
+    v_vaccinations_journal.issue_confidential
+,
+    v_vaccinations_journal.episode
+,
+    v_vaccinations_journal.episode_open
+,
+    v_vaccinations_journal.encounter_started
+,
+    v_vaccinations_journal.encounter_last_affirmed
+,
+    v_vaccinations_journal.encounter_type
+,
+    v_vaccinations_journal.encounter_l10n_type
+   
+FROM clin.v_vaccinations_journal
+
+UNION ALL
+ 
+SELECT v_suppressed_hints_journal.pk_patient
+,
+    v_suppressed_hints_journal.modified_when
+,
+    v_suppressed_hints_journal.clin_when
+,
+    v_suppressed_hints_journal.modified_by
+,
+    v_suppressed_hints_journal.soap_cat
+,
+    v_suppressed_hints_journal.narrative
+,
+    v_suppressed_hints_journal.fk_encounter AS pk_encounter
+,
+    v_suppressed_hints_journal.pk_episode
+,
+    v_suppressed_hints_journal.pk_health_issue
+,
+    v_suppressed_hints_journal.src_pk
+,
+    v_suppressed_hints_journal.src_table
+,
+    v_suppressed_hints_journal.row_version
+,
+    v_suppressed_hints_journal.health_issue
+,
+    v_suppressed_hints_journal.issue_laterality
+,
+    v_suppressed_hints_journal.issue_active
+,
+    v_suppressed_hints_journal.issue_clinically_relevant
+,
+    v_suppressed_hints_journal.issue_confidential
+,
+    v_suppressed_hints_journal.episode
+,
+    v_suppressed_hints_journal.episode_open
+,
+    v_suppressed_hints_journal.encounter_started
+,
+    v_suppressed_hints_journal.encounter_last_affirmed
+,
+    v_suppressed_hints_journal.encounter_type
+,
+    v_suppressed_hints_journal.encounter_l10n_type
+   
+FROM clin.v_suppressed_hints_journal
+
+UNION ALL
+ 
+SELECT v_external_care_journal.pk_patient
+,
+    v_external_care_journal.modified_when
+,
+    v_external_care_journal.clin_when
+,
+    v_external_care_journal.modified_by
+,
+    v_external_care_journal.soap_cat
+,
+    v_external_care_journal.narrative
+,
+    v_external_care_journal.pk_encounter
+,
+    v_external_care_journal.pk_episode
+,
+    v_external_care_journal.pk_health_issue
+,
+    v_external_care_journal.src_pk
+,
+    v_external_care_journal.src_table
+,
+    v_external_care_journal.row_version
+,
+    v_external_care_journal.health_issue
+,
+    v_external_care_journal.issue_laterality
+,
+    v_external_care_journal.issue_active
+,
+    v_external_care_journal.issue_clinically_relevant
+,
+    v_external_care_journal.issue_confidential
+,
+    v_external_care_journal.episode
+,
+    v_external_care_journal.episode_open
+,
+    v_external_care_journal.encounter_started
+,
+    v_external_care_journal.encounter_last_affirmed
+,
+    v_external_care_journal.encounter_type
+,
+    v_external_care_journal.encounter_l10n_type
+   
+FROM clin.v_external_care_journal
+
+UNION ALL
+ 
+SELECT v_edc_journal.pk_patient
+,
+    v_edc_journal.modified_when
+,
+    v_edc_journal.clin_when
+,
+    v_edc_journal.modified_by
+,
+    v_edc_journal.soap_cat
+,
+    v_edc_journal.narrative
+,
+    v_edc_journal.pk_encounter
+,
+    v_edc_journal.pk_episode
+,
+    v_edc_journal.pk_health_issue
+,
+    v_edc_journal.src_pk
+,
+    v_edc_journal.src_table
+,
+    v_edc_journal.row_version
+,
+    v_edc_journal.health_issue
+,
+    v_edc_journal.issue_laterality
+,
+    v_edc_journal.issue_active
+,
+    v_edc_journal.issue_clinically_relevant
+,
+    v_edc_journal.issue_confidential
+,
+    v_edc_journal.episode
+,
+    v_edc_journal.episode_open
+,
+    v_edc_journal.encounter_started
+,
+    v_edc_journal.encounter_last_affirmed
+,
+    v_edc_journal.encounter_type
+,
+    v_edc_journal.encounter_l10n_type
+   
+FROM clin.v_edc_journal
+
+UNION ALL
+ 
+SELECT v_reminders_journal.pk_patient
+,
+    v_reminders_journal.modified_when
+,
+    v_reminders_journal.clin_when
+,
+    v_reminders_journal.modified_by
+,
+    v_reminders_journal.soap_cat
+,
+    v_reminders_journal.narrative
+,
+    v_reminders_journal.pk_encounter
+,
+    v_reminders_journal.pk_episode
+,
+    v_reminders_journal.pk_health_issue
+,
+    v_reminders_journal.src_pk
+,
+    v_reminders_journal.src_table
+,
+    v_reminders_journal.row_version
+,
+    v_reminders_journal.health_issue
+,
+    v_reminders_journal.issue_laterality
+,
+    v_reminders_journal.issue_active
+,
+    v_reminders_journal.issue_clinically_relevant
+,
+    v_reminders_journal.issue_confidential
+,
+    v_reminders_journal.episode
+,
+    v_reminders_journal.episode_open
+,
+    v_reminders_journal.encounter_started
+,
+    v_reminders_journal.encounter_last_affirmed
+,
+    v_reminders_journal.encounter_type
+,
+    v_reminders_journal.encounter_l10n_type
+   
+FROM clin.v_reminders_journal;</pre>
+	
 
 	<!-- List off permissions -->
 	
@@ -57131,17 +71699,15 @@ order to link structures to codes.
     </p>
 	
         <hr>
-		<h2>Table:
+		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-code2narrative">lnk_code2narrative</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-export-items">v_export_items</a>
 		</h2>
         
-         <p>Links codes to SOAP narrative.</p>
-        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.lnk_code2narrative Structure</caption>
+                <caption>clin.v_export_items Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -57153,13 +71719,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
+            	<td>pk_export_item</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -57169,12 +71735,12 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
+            	<td>pk_identity</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -57185,13 +71751,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>created_by</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -57201,13 +71767,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>created_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -57217,13 +71783,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>pk_lnk_code2item</td>
-            	<td>integer</td>
+            	<td>designation</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('lnk_code2item_root_pk_lnk_code2item_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -57232,56 +71798,32 @@ order to link structures to codes.
             <tr class="tr1">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>fk_generic_code</td>
-            	<td>integer</td>
+            	<td>description</td>
+            	<td>text</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>Custom foreign key to ref.coding_system_root.
+				
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.clin-narrative">clin.clin_narrative.pk</a>
-                  
-                
                 </td>
-            	<td>fk_item</td>
+            	<td>pk_doc_obj</td>
             	<td>integer</td>
                 <td><i>
 				
-					
-
-					
-                       UNIQUE#1
-                    
-				
-					
-
-					
-				
 
 				
 				
 				</i>
-				<br><br>Foreign key to clin.clin_narrative
+				
 				</td>
 			 </tr>
             
@@ -57289,7 +71831,7 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>code_modifier</td>
+            	<td>md5_sum</td>
             	<td>text</td>
                 <td><i>
 				
@@ -57304,18 +71846,11 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>size</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -57324,89 +71859,16 @@ order to link structures to codes.
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table clin.lnk_code2narrative Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#clin.table.lnk-code2item-root">lnk_code2item_root</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-       idx_c_lc2narr_fk_item fk_item
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-code2procedure">lnk_code2procedure</a>
-		</h2>
-        
-         <p>Links codes to procedures. OPS comes to mind.</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.lnk_code2procedure Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
-				</i>
-				
-				</td>
-			 </tr>
-            
             <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>filename</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -57417,13 +71879,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>xmin_export_item</td>
+            	<td>xid</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -57433,13 +71895,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>title</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -57449,13 +71911,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>pk_lnk_code2item</td>
-            	<td>integer</td>
+            	<td>firstnames</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('lnk_code2item_root_pk_lnk_code2item_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -57464,56 +71926,32 @@ order to link structures to codes.
             <tr class="tr1">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>fk_generic_code</td>
-            	<td>integer</td>
+            	<td>lastnames</td>
+            	<td>text</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>Custom foreign key to ref.coding_system_root.
+				
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.procedure">clin.procedure.pk</a>
-                  
-                
                 </td>
-            	<td>fk_item</td>
-            	<td>integer</td>
+            	<td>preferred</td>
+            	<td>text</td>
                 <td><i>
 				
-					
-
-					
-                       UNIQUE#1
-                    
-				
-					
-
-					
-				
 
 				
 				
 				</i>
-				<br><br>Foreign key to clin.procedure
+				
 				</td>
 			 </tr>
             
@@ -57521,7 +71959,7 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>code_modifier</td>
+            	<td>gender</td>
             	<td>text</td>
                 <td><i>
 				
@@ -57536,18 +71974,11 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>dob</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -57560,17 +71991,8 @@ order to link structures to codes.
 
         <!-- Inherits -->
 		
-        <p>Table clin.lnk_code2procedure Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#clin.table.lnk-code2item-root">lnk_code2item_root</a>, 
-        
-        </p>
-		
 
 		
-		
-		
 
         <!-- Constraint List -->
 		
@@ -57580,11 +72002,141 @@ order to link structures to codes.
 
     <!-- Indexes -->
     
-       idx_c_lc2proc_fk_item fk_item
-    
 
 	<!-- View Definition -->
 	
+	<pre>
+SELECT inner_export_items.pk_export_item
+,
+    inner_export_items.pk_identity
+,
+    inner_export_items.created_by
+,
+    inner_export_items.created_when
+,
+    inner_export_items.designation
+,
+    inner_export_items.description
+,
+    inner_export_items.pk_doc_obj
+,
+    inner_export_items.md5_sum
+,
+    inner_export_items.size
+,
+    inner_export_items.filename
+,
+    inner_export_items.xmin_export_item
+,
+    d_vp.title
+,
+    d_vp.firstnames
+,
+    d_vp.lastnames
+,
+    d_vp.preferred
+,
+    d_vp.gender
+,
+    d_vp.dob
+   
+FROM (
+     (
+      SELECT c_ei.pk AS pk_export_item
+           ,
+            COALESCE
+           (c_ei.fk_identity
+                 , (
+                  SELECT encounter.fk_patient
+                   
+                    FROM clin.encounter
+                  
+                   WHERE (encounter.pk = 
+                             (
+                              SELECT doc_med.fk_encounter
+                           
+                                FROM blobs.doc_med
+                          
+                               WHERE (doc_med.pk = 
+                                         (
+                                          SELECT doc_obj.fk_doc
+                                   
+                                            FROM blobs.doc_obj
+                                  
+                                           WHERE (doc_obj.pk = c_ei.fk_doc_obj)
+                                         )
+                                   )
+                             )
+                       )
+                 )
+           ) AS pk_identity
+           ,
+            COALESCE
+           (
+                 (
+                  SELECT staff.short_alias
+                   
+                    FROM dem.staff
+                  
+                   WHERE (staff.db_user = c_ei.created_by)
+                 )
+                 , (c_ei.created_by)::text
+           ) AS created_by
+           ,
+            c_ei.created_when
+           ,
+            c_ei.designation
+           ,
+            c_ei.description
+           ,
+            c_ei.fk_doc_obj AS pk_doc_obj
+           ,
+            md5
+           (COALESCE
+                 (c_ei.data
+                       , COALESCE
+                       (
+                             (
+                              SELECT b_do.data
+                   
+                                FROM blobs.doc_obj b_do
+                  
+                               WHERE (b_do.pk = c_ei.fk_doc_obj)
+                             )
+                             ,'\x'::bytea
+                       )
+                 )
+           ) AS md5_sum
+           ,
+            octet_length
+           (COALESCE
+                 (c_ei.data
+                       ,'\x'::bytea
+                 )
+           ) AS size
+           ,
+            COALESCE
+           (c_ei.filename
+                 , (
+                  SELECT b_do.filename
+                   
+                    FROM blobs.doc_obj b_do
+                  
+                   WHERE (b_do.pk = c_ei.fk_doc_obj)
+                 )
+           ) AS filename
+           ,
+            c_ei.xmin AS xmin_export_item
+           
+        FROM clin.export_item c_ei
+     ) inner_export_items
+     
+  JOIN dem.v_all_persons d_vp 
+    ON (
+           (d_vp.pk_identity = inner_export_items.pk_identity)
+     )
+);</pre>
+	
 
 	<!-- List off permissions -->
 	
@@ -57595,35 +72147,65 @@ order to link structures to codes.
     </p>
 	
         <hr>
-		<h2>Table:
+		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-code2rfe">lnk_code2rfe</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-external-care">v_external_care</a>
 		</h2>
         
-         <p>Links codes to encounters.</p>
-        
 
 
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.lnk_code2rfe Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.v_external_care Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_external_care</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_identity</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
+            	<td>issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -57633,12 +72215,12 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>provider</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -57649,13 +72231,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>unit</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -57665,13 +72247,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>organization</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -57681,13 +72263,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>pk_lnk_code2item</td>
-            	<td>integer</td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('lnk_code2item_root_pk_lnk_code2item_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -57696,56 +72278,64 @@ order to link structures to codes.
             <tr class="tr1">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>fk_generic_code</td>
+            	<td>pk_health_issue</td>
             	<td>integer</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>Custom foreign key to ref.coding_system_root.
+				
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
-                  
-                
                 </td>
-            	<td>fk_item</td>
+            	<td>pk_org_unit</td>
             	<td>integer</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-					
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
+                <td><i>
+				
 
-					
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>xmin_external_care</td>
+            	<td>xid</td>
+                <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>Foreign key to clin.encounter
+				
 				</td>
 			 </tr>
             
@@ -57753,8 +72343,8 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>code_modifier</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -57768,17 +72358,26 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
 
-					
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
 				
 
 				
@@ -57792,17 +72391,8 @@ order to link structures to codes.
 
         <!-- Inherits -->
 		
-        <p>Table clin.lnk_code2rfe Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#clin.table.lnk-code2item-root">lnk_code2item_root</a>, 
-        
-        </p>
-		
 
 		
-		
-		
 
         <!-- Constraint List -->
 		
@@ -57812,11 +72402,70 @@ order to link structures to codes.
 
     <!-- Indexes -->
     
-       idx_c_lc2rfe_fk_item fk_item
-    
 
 	<!-- View Definition -->
 	
+	<pre>
+SELECT c_ec.pk AS pk_external_care
+,
+    
+(
+SELECT encounter.fk_patient
+           
+  FROM clin.encounter
+          
+ WHERE (encounter.pk = c_ec.fk_encounter)
+) AS pk_identity
+,
+    COALESCE
+(c_ec.issue
+     , c_hi.description
+) AS issue
+,
+    c_ec.provider
+,
+    d_ou.description AS unit
+,
+    d_o.description AS organization
+,
+    c_ec.comment
+,
+    c_ec.fk_health_issue AS pk_health_issue
+,
+    c_ec.fk_org_unit AS pk_org_unit
+,
+    c_ec.fk_encounter AS pk_encounter
+,
+    c_ec.xmin AS xmin_external_care
+,
+    c_ec.modified_when
+,
+    c_ec.modified_by
+,
+    c_ec.row_version
+   
+FROM (
+     (
+           (clin.external_care c_ec
+     
+         LEFT JOIN clin.health_issue c_hi 
+                ON (
+                       (c_hi.pk = c_ec.fk_health_issue)
+                 )
+           )
+     
+   LEFT JOIN dem.org_unit d_ou 
+          ON (
+                 (c_ec.fk_org_unit = d_ou.pk)
+           )
+     )
+     
+LEFT JOIN dem.org d_o 
+    ON (
+           (d_ou.fk_org = d_o.pk)
+     )
+);</pre>
+	
 
 	<!-- List off permissions -->
 	
@@ -57827,17 +72476,15 @@ order to link structures to codes.
     </p>
 	
         <hr>
-		<h2>Table:
+		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-code2tst-pnl">lnk_code2tst_pnl</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-external-care-journal">v_external_care_journal</a>
 		</h2>
         
-         <p>Links codes to test panels.</p>
-        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.lnk_code2tst_pnl Structure</caption>
+                <caption>clin.v_external_care_journal Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -57849,13 +72496,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
+            	<td>pk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -57865,12 +72512,12 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -57881,13 +72528,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
+            	<td>clin_when</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -57898,12 +72545,12 @@ order to link structures to codes.
                 
                 </td>
             	<td>modified_by</td>
-            	<td>name</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -57913,13 +72560,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>pk_lnk_code2item</td>
-            	<td>integer</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('lnk_code2item_root_pk_lnk_code2item_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -57928,56 +72575,32 @@ order to link structures to codes.
             <tr class="tr1">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>fk_generic_code</td>
-            	<td>integer</td>
+            	<td>narrative</td>
+            	<td>text</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>Custom foreign key to ref.coding_system_root.
+				
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.test-panel">clin.test_panel.pk</a>
-                  
-                
                 </td>
-            	<td>fk_item</td>
+            	<td>pk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
-					
-
-					
-                       UNIQUE#1
-                    
-				
-					
-
-					
-				
 
 				
 				
 				</i>
-				<br><br>Foreign key to clin.test_panel
+				
 				</td>
 			 </tr>
             
@@ -57985,8 +72608,8 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>code_modifier</td>
-            	<td>text</td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -58000,18 +72623,11 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -58020,142 +72636,78 @@ order to link structures to codes.
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table clin.lnk_code2tst_pnl Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#clin.table.lnk-code2item-root">lnk_code2item_root</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-       idx_c_lc2tp_fk_item fk_item
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-constraint2vacc-course">lnk_constraint2vacc_course</a>
-		</h2>
-        
-         <p>links constraints to courses</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.lnk_constraint2vacc_course Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
+            	<td>src_pk</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>src_table</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>issue_laterality</td>
+            	<td>character varying(2)</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -58164,140 +72716,49 @@ order to link structures to codes.
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.vaccination-course">clin.vaccination_course.pk</a>
-                  
-                
-                  
-                
                 </td>
-            	<td>fk_vaccination_course</td>
-            	<td>integer</td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
-					
-
-					
-				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.vaccination-course-constraint">clin.vaccination_course_constraint.pk</a>
-                  
-                
-                  
-                
                 </td>
-            	<td>fk_constraint</td>
-            	<td>integer</td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
-					
-
-					
-				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
 				
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table clin.lnk_constraint2vacc_course Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-pat2vaccination-course">lnk_pat2vaccination_course</a>
-		</h2>
-        
-         <p>links patients to vaccination courses they are actually on,
-	 this allows for per-patient selection of courses to be
-	 followed, eg. children at different ages may be on different
-	 vaccination courses or some people are on a course due
-	 to a trip abroad while most others are not</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.lnk_pat2vaccination_course Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -58307,12 +72768,12 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>episode</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -58323,13 +72784,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -58339,13 +72800,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -58354,18 +72815,11 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                
-                </td>
-            	<td>pk</td>
-            	<td>serial</td>
+                </td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -58377,29 +72831,13 @@ order to link structures to codes.
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.patient">clin.patient.fk_identity</a>
-                  
-                
-                  
-                
                 </td>
-            	<td>fk_patient</td>
-            	<td>integer</td>
+            	<td>encounter_type</td>
+            	<td>text</td>
                 <td><i>
 				
-					
-
-					
-				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
 				
@@ -58409,29 +72847,13 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.vaccination-course">clin.vaccination_course.pk</a>
-                  
-                
-                  
-                
                 </td>
-            	<td>fk_course</td>
-            	<td>integer</td>
+            	<td>encounter_l10n_type</td>
+            	<td>text</td>
                 <td><i>
 				
-					
-
-					
-				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
 				
@@ -58442,17 +72864,8 @@ order to link structures to codes.
 
         <!-- Inherits -->
 		
-        <p>Table clin.lnk_pat2vaccination_course Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
 
 		
-		
-		
 
         <!-- Constraint List -->
 		
@@ -58465,6 +72878,156 @@ order to link structures to codes.
 
 	<!-- View Definition -->
 	
+	<pre>
+SELECT c_enc.fk_patient AS pk_patient
+,
+    c_ec.modified_when
+,
+    c_ec.modified_when AS clin_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_ec.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (c_ec.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    's'::text AS soap_cat
+,
+    
+(
+     (
+           (
+                 (
+                       (
+                             (
+                                   (
+                                         (
+                                               (
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (_
+                                                                             ('External care'::text) || COALESCE
+                                                                             (
+                                                                                   (
+                                                                                         (
+                                                                                               (' '::text || _
+                                                                                                     ('by'::text)
+                                                                                               ) || ' '::text
+                                                                                         ) || c_ec.provider
+                                                                                   )
+                                                                                   ,''::text
+                                                                             )
+                                                                       ) || ' @ '::text
+                                                                 ) || d_ou.description
+                                                           ) || ' '::text
+                                                     ) || _
+                                                     ('of'::text)
+                                               ) || ' '::text
+                                         ) || d_o.description
+                                   ) || '
+'::text
+                             ) || _
+                             ('Issue:'::text)
+                       ) || ' '::text
+                 ) || COALESCE
+                 (c_hi.description
+                       , c_ec.issue
+                 )
+           ) || '
+'::text
+     ) || COALESCE
+     (
+           (
+                 (_
+                       ('Comment:'::text) || ' '::text
+                 ) || c_ec.comment
+           )
+           ,''::text
+     )
+) AS narrative
+,
+    c_ec.fk_encounter AS pk_encounter
+,
+    NULL::integer AS pk_episode
+,
+    c_ec.fk_health_issue AS pk_health_issue
+,
+    c_ec.pk AS src_pk
+,
+    'clin.external_care'::text AS src_table
+,
+    c_ec.row_version
+,
+    c_hi.description AS health_issue
+,
+    c_hi.laterality AS issue_laterality
+,
+    c_hi.is_active AS issue_active
+,
+    c_hi.clinically_relevant AS issue_clinically_relevant
+,
+    c_hi.is_confidential AS issue_confidential
+,
+    NULL::text AS episode
+,
+    NULL::boolean AS episode_open
+,
+    c_enc.started AS encounter_started
+,
+    c_enc.last_affirmed AS encounter_last_affirmed
+,
+    c_ety.description AS encounter_type
+,
+    _
+(c_ety.description) AS encounter_l10n_type
+   
+FROM (
+     (
+           (
+                 (
+                       (clin.external_care c_ec
+     
+                          JOIN clin.encounter c_enc 
+                            ON (
+                                   (c_ec.fk_encounter = c_enc.pk)
+                             )
+                       )
+     
+                    JOIN clin.encounter_type c_ety 
+                      ON (
+                             (c_enc.fk_type = c_ety.pk)
+                       )
+                 )
+     
+         LEFT JOIN clin.health_issue c_hi 
+                ON (
+                       (c_ec.fk_health_issue = c_hi.pk)
+                 )
+           )
+     
+   LEFT JOIN dem.org_unit d_ou 
+          ON (
+                 (c_ec.fk_org_unit = d_ou.pk)
+           )
+     )
+     
+LEFT JOIN dem.org d_o 
+    ON (
+           (d_ou.fk_org = d_o.pk)
+     )
+);</pre>
+	
 
 	<!-- List off permissions -->
 	
@@ -58475,15 +73038,17 @@ order to link structures to codes.
     </p>
 	
         <hr>
-		<h2>Table:
+		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-substance2episode">lnk_substance2episode</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-family-history">v_family_history</a>
 		</h2>
         
+         <p>family history denormalized</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.lnk_substance2episode Structure</caption>
+                <caption>clin.v_family_history Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -58495,13 +73060,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
+            	<td>pk_family_history</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -58511,12 +73076,12 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
+            	<td>pk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -58527,13 +73092,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -58543,13 +73108,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>relation</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -58558,18 +73123,11 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>l10n_relation</td>
+            	<td>text</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -58581,19 +73139,11 @@ order to link structures to codes.
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
-                  
-                
                 </td>
-            	<td>fk_episode</td>
-            	<td>integer</td>
+            	<td>condition</td>
+            	<td>text</td>
                 <td><i>
 				
-					
-
-					
-				
 
 				
 				
@@ -58605,19 +73155,11 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.substance-intake">clin.substance_intake.pk</a>
-                  
-                
                 </td>
-            	<td>fk_substance</td>
-            	<td>integer</td>
+            	<td>age_noted</td>
+            	<td>text</td>
                 <td><i>
 				
-					
-
-					
-				
 
 				
 				
@@ -58626,72 +73168,33 @@ order to link structures to codes.
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table clin.lnk_substance2episode Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-tst2norm">lnk_tst2norm</a>
-		</h2>
-        
-         <p>links test result evaluation norms to tests</p>
-        
-
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>age_of_death</td>
+            	<td>interval</td>
+                <td><i>
+				
 
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.lnk_tst2norm Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
+            	<td>contributed_to_death</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -58701,12 +73204,12 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -58717,13 +73220,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>episode</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -58733,13 +73236,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>when_known_to_patient</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -58748,18 +73251,11 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>id</td>
-            	<td>serial</td>
+            	<td>name_relative</td>
+            	<td>text</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -58771,193 +73267,107 @@ order to link structures to codes.
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.test-type">clin.test_type.pk</a>
-                  
-                
-                  
-                
                 </td>
-            	<td>id_test</td>
-            	<td>integer</td>
+            	<td>dob_relative</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
-					
-
-					
-				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>which test does the linked norm apply to
+				
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>id_norm</td>
-            	<td>integer</td>
+            	<td>is_genetic_relative</td>
+            	<td>boolean</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>the norm to apply to the linked test
+				
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table clin.lnk_tst2norm Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-type2item">lnk_type2item</a>
-		</h2>
-        
-         <p>allow to link many-to-many between clin.clin_root_item and clin.clin_item_type</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.lnk_type2item Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
+            	<td>pk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>row_version</td>
+            	<td>pk_episode</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>pk_fhx_relation_type</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -58966,64 +73376,35 @@ order to link structures to codes.
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.clin-item-type">clin.clin_item_type.pk</a>
-                  
-                
-                  
-                
                 </td>
-            	<td>fk_type</td>
-            	<td>integer</td>
+            	<td>pk_generic_codes</td>
+            	<td>integer[]</td>
                 <td><i>
 				
-					
-
-					
-				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>fk_item</td>
-            	<td>integer</td>
+            	<td>xmin_family_history</td>
+            	<td>xid</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>the item this type is linked to,
-	 since PostgreSQL apparently cannot reference a value
-	 inserted from a child table (?) we must simulate
-	 referential integrity checks with a custom trigger,
-	 this, however, does not deal with update/delete
-	 cascading :-(
+				
 				</td>
 			 </tr>
             
@@ -59031,17 +73412,8 @@ order to link structures to codes.
 
         <!-- Inherits -->
 		
-        <p>Table clin.lnk_type2item Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
 
 		
-		
-		
 
         <!-- Constraint List -->
 		
@@ -59054,6 +73426,85 @@ order to link structures to codes.
 
 	<!-- View Definition -->
 	
+	<pre>
+SELECT c_fh.pk AS pk_family_history
+,
+    cenc.fk_patient AS pk_patient
+,
+    c_fh.soap_cat
+,
+    c_fhrt.description AS relation
+,
+    _
+(c_fhrt.description) AS l10n_relation
+,
+    c_fh.narrative AS condition
+,
+    c_fh.age_noted
+,
+    c_fh.age_of_death
+,
+    c_fh.contributed_to_death
+,
+    c_fh.comment
+,
+    cep.description AS episode
+,
+    c_fh.clin_when AS when_known_to_patient
+,
+    c_fh.name_relative
+,
+    c_fh.dob_relative
+,
+    c_fhrt.is_genetic AS is_genetic_relative
+,
+    c_fh.fk_encounter AS pk_encounter
+,
+    c_fh.fk_episode AS pk_episode
+,
+    cep.fk_health_issue AS pk_health_issue
+,
+    c_fhrt.pk AS pk_fhx_relation_type
+,
+    c_fh.modified_when
+,
+    COALESCE
+(
+     (
+      SELECT array_agg
+           (c_lc2fhx.fk_generic_code) AS array_agg
+           
+        FROM clin.lnk_code2fhx c_lc2fhx
+          
+       WHERE (c_lc2fhx.fk_item = c_fh.pk)
+     )
+     , ARRAY[]::integer[]
+) AS pk_generic_codes
+,
+    c_fh.xmin AS xmin_family_history
+   
+FROM (
+     (
+           (clin.family_history c_fh
+     
+              JOIN clin.encounter cenc 
+                ON (
+                       (c_fh.fk_encounter = cenc.pk)
+                 )
+           )
+     
+        JOIN clin.episode cep 
+          ON (
+                 (c_fh.fk_episode = cep.pk)
+           )
+     )
+     
+LEFT JOIN clin.fhx_relation_type c_fhrt 
+    ON (
+           (c_fh.fk_relation_type = c_fhrt.pk)
+     )
+);</pre>
+	
 
 	<!-- List off permissions -->
 	
@@ -59064,19 +73515,15 @@ order to link structures to codes.
     </p>
 	
         <hr>
-		<h2>Table:
+		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-vaccination-course2schedule">lnk_vaccination_course2schedule</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-family-history-journal">v_family_history_journal</a>
 		</h2>
         
-         <p>this table links vaccination courses for a single epitope
-	 into schedules defined and recommended by a vaccination
-	 council or similar entity</p>
-        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.lnk_vaccination_course2schedule Structure</caption>
+                <caption>clin.v_family_history_journal Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -59088,13 +73535,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
+            	<td>pk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -59104,12 +73551,12 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -59120,13 +73567,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
+            	<td>clin_when</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -59137,12 +73584,12 @@ order to link structures to codes.
                 
                 </td>
             	<td>modified_by</td>
-            	<td>name</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -59151,18 +73598,11 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -59174,29 +73614,13 @@ order to link structures to codes.
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.vaccination-course">clin.vaccination_course.pk</a>
-                  
-                
-                  
-                
                 </td>
-            	<td>fk_course</td>
-            	<td>integer</td>
+            	<td>narrative</td>
+            	<td>text</td>
                 <td><i>
 				
-					
-
-					
-				
-					
 
-					
-                       UNIQUE
-                    
 				
-
-				NOT NULL
 				
 				</i>
 				
@@ -59206,93 +73630,46 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.vaccination-schedule">clin.vaccination_schedule.pk</a>
-                  
-                
                 </td>
-            	<td>fk_schedule</td>
+            	<td>pk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
-					
 
-					
 				
-
-				NOT NULL
 				
 				</i>
 				
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table clin.lnk_vaccination_course2schedule Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.lnk-vaccine2inds">lnk_vaccine2inds</a>
-		</h2>
-        
-         <p>links vaccines to their indications</p>
-        
-
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
 
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.lnk_vaccine2inds Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
+            	<td>pk_health_issue</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -59302,12 +73679,12 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
+            	<td>src_pk</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -59318,13 +73695,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>src_table</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -59334,13 +73711,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -59349,18 +73726,11 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>id</td>
-            	<td>serial</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -59372,29 +73742,13 @@ order to link structures to codes.
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.vaccine">clin.vaccine.pk</a>
-                  
-                
-                  
-                
                 </td>
-            	<td>fk_vaccine</td>
-            	<td>integer</td>
+            	<td>issue_laterality</td>
+            	<td>character varying(2)</td>
                 <td><i>
 				
-					
-
-					
-				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
 				
@@ -59404,109 +73758,75 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.vacc-indication">clin.vacc_indication.id</a>
-                  
-                
-                  
-                
                 </td>
-            	<td>fk_indication</td>
-            	<td>integer</td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
-					
 
-					
 				
-					
-
-					
-                       UNIQUE#1
-                    
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
+                <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
 				</td>
 			 </tr>
             
-        </table>
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
+                <td><i>
+				
 
-        <!-- Inherits -->
-		
-        <p>Table clin.lnk_vaccine2inds Inherits
-        
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
             
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.meta-test-type">meta_test_type</a>
-		</h2>
-        
-         <p>this table merges test types from various test orgs
-	 which are intended to measure the same value but have
-	 differing names into one logical test type,
-	 this is not intended to be used for aggregating
-	 semantically different test types into "profiles"</p>
-        
-
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>episode</td>
+            	<td>text</td>
+                <td><i>
+				
 
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.meta_test_type Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -59518,21 +73838,13 @@ order to link structures to codes.
             <tr class="tr1">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>abbrev</td>
-            	<td>text</td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
 				
@@ -59542,21 +73854,13 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>name</td>
-            	<td>text</td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
 				
@@ -59567,7 +73871,7 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>loinc</td>
+            	<td>encounter_type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -59583,7 +73887,7 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>comment</td>
+            	<td>encounter_l10n_type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -59601,27 +73905,233 @@ order to link structures to codes.
 		
 
 		
-		
-		
 
         <!-- Constraint List -->
 		
 
         <!-- Foreign Key Discovery -->
 		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.test-type">clin.test_type</a></li>
-			</ul>
-		
-		
 
     <!-- Indexes -->
     
 
 	<!-- View Definition -->
 	
+	<pre>
+SELECT c_enc.fk_patient AS pk_patient
+,
+    c_fh.modified_when
+,
+    c_fh.clin_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_fh.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (c_fh.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    c_fh.soap_cat
+,
+    
+(
+     (
+           (
+                 (
+                       (
+                             (
+                                   (
+                                         (
+                                               (
+                                                     (
+                                                           (
+                                                                 (_
+                                                                       (c_fhrt.description) || COALESCE
+                                                                       (
+                                                                             (' @ '::text || c_fh.age_noted)
+                                                                             ,''::text
+                                                                       )
+                                                                 ) || ': '::text
+                                                           ) || c_fh.narrative
+                                                     ) || '
+'::text
+                                               ) || ' '::text
+                                         ) ||
+        CASE
+            WHEN 
+                                         (c_fh.contributed_to_death IS TRUE) THEN 
+                                         (_
+                                               ('contributed to death'::text) || ' '::text
+                                         )
+            ELSE ''::text
+        END
+                                   ) || COALESCE
+                                   (
+                                         ('@ '::text || 
+                                               (justify_interval
+                                                     (c_fh.age_of_death)
+                                               )::text
+                                         )
+                                         ,''::text
+                                   )
+                             ) || '
+'::text
+                       ) || COALESCE
+                       (
+                             (
+                                   (' '::text || c_fh.name_relative) || 
+                                 ','::text
+                             )
+                             ,''::text
+                       )
+                 ) || COALESCE
+                 (
+                       (' '::text || to_char
+                             (c_fh.dob_relative
+                                   ,'YYYY-MM-DD'::text
+                             )
+                       )
+                       ,''::text
+                 )
+           ) || COALESCE
+           (
+                 ('
+ '::text || c_fh.comment)
+                 ,''::text
+           )
+     ) || COALESCE
+     (
+           (
+                 (';
+'::text || array_to_string
+                       (
+                             (
+                              SELECT array_agg
+                                   (
+                                         (
+                                               (
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (
+                                                                             (
+                                                                                   (r_csr.code || 
+                                                                                      ' ('::text) || r_ds.name_short
+                                                                                   ) || ' - '::text
+                                                                             ) || r_ds.version
+                                                                       ) || ' - '::text
+                                                                 ) || r_ds.lang
+                                                           ) || 
+                                                 '): '::text
+                                               ) || r_csr.term
+                                         )
+                                   ) AS array_agg
+           
+                                FROM (
+                                         (clin.lnk_code2fhx c_lc2fhx
+             
+                                            JOIN ref.coding_system_root r_csr 
+                                              ON (
+                                                     (c_lc2fhx.fk_generic_code = r_csr.pk_coding_system)
+                                               )
+                                         )
+             
+                                      JOIN ref.data_source r_ds 
+                                        ON (
+                                               (r_ds.pk = r_csr.fk_data_source)
+                                         )
+                                   )
+          
+                               WHERE (c_lc2fhx.fk_item = c_fh.pk)
+                             )
+                             ,'; '::text
+                       )
+                 ) || ';'::text
+           )
+           ,''::text
+     )
+) AS narrative
+,
+    c_fh.fk_encounter AS pk_encounter
+,
+    c_fh.fk_episode AS pk_episode
+,
+    c_epi.fk_health_issue AS pk_health_issue
+,
+    c_fh.pk AS src_pk
+,
+    'clin.family_history'::text AS src_table
+,
+    c_fh.row_version
+,
+    c_hi.description AS health_issue
+,
+    c_hi.laterality AS issue_laterality
+,
+    c_hi.is_active AS issue_active
+,
+    c_hi.clinically_relevant AS issue_clinically_relevant
+,
+    c_hi.is_confidential AS issue_confidential
+,
+    c_epi.description AS episode
+,
+    c_epi.is_open AS episode_open
+,
+    c_enc.started AS encounter_started
+,
+    c_enc.last_affirmed AS encounter_last_affirmed
+,
+    c_ety.description AS encounter_type
+,
+    _
+(c_ety.description) AS encounter_l10n_type
+   
+FROM (
+     (
+           (
+                 (
+                       (clin.family_history c_fh
+     
+                          JOIN clin.encounter c_enc 
+                            ON (
+                                   (c_fh.fk_encounter = c_enc.pk)
+                             )
+                       )
+     
+                    JOIN clin.encounter_type c_ety 
+                      ON (
+                             (c_enc.fk_type = c_ety.pk)
+                       )
+                 )
+     
+              JOIN clin.episode c_epi 
+                ON (
+                       (c_fh.fk_episode = c_epi.pk)
+                 )
+           )
+     
+   LEFT JOIN clin.fhx_relation_type c_fhrt 
+          ON (
+                 (c_fh.fk_relation_type = c_fhrt.pk)
+           )
+     )
+     
+LEFT JOIN clin.health_issue c_hi 
+    ON (
+           (c_epi.fk_health_issue = c_hi.pk)
+     )
+);</pre>
+	
 
 	<!-- List off permissions -->
 	
@@ -59632,17 +74142,15 @@ order to link structures to codes.
     </p>
 	
         <hr>
-		<h2>Table:
+		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.patient">patient</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-health-issues">v_health_issues</a>
 		</h2>
         
-         <p>A table to hold unique-per-identity *clinical* items, such as Expected Due Date.</p>
-        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.patient Structure</caption>
+                <caption>clin.v_health_issues Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -59654,13 +74162,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
+            	<td>pk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -59670,12 +74178,12 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
+            	<td>pk_health_issue</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -59686,13 +74194,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>description</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -59702,13 +74210,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>summary</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -59717,18 +74225,11 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>laterality</td>
+            	<td>character varying(2)</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -59740,32 +74241,16 @@ order to link structures to codes.
             <tr class="tr1">
 				<td>
                 
-                  
-                
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.identity">dem.identity.pk</a>
-                  
-                
                 </td>
-            	<td>fk_identity</td>
-            	<td>integer</td>
+            	<td>age_noted</td>
+            	<td>interval</td>
                 <td><i>
 				
-					
-
-					
-                       UNIQUE
-                    
-				
-					
 
-					
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>the dem.identity.pk of this patient
+				
 				</td>
 			 </tr>
             
@@ -59773,8 +74258,8 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>edc</td>
-            	<td>date</td>
+            	<td>is_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -59785,122 +74270,16 @@ order to link structures to codes.
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table clin.patient Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.patient Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>clin_patient_sane_edc</td>
-                <td>CHECK (((edc IS NULL) OR ((clin.get_dod(fk_identity) IS NULL) AND ((clin.get_dob(fk_identity) IS NULL) OR (edc > (clin.get_dob(fk_identity) + '5 years'::interval))))))</td>
-            </tr>
-			
-		</table>
-		
-
-        <!-- Foreign Key Discovery -->
-		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.export-item">clin.export_item</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.incoming-data-unmatched">clin.incoming_data_unmatched</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.lnk-pat2vaccination-course">clin.lnk_pat2vaccination_course</a></li>
-			</ul>
-		
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.procedure">procedure</a>
-		</h2>
-        
-         <p>This table holds procedure/operations performed on the patient
- both in hospital or in community care.</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.procedure Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
-				</i>
-				
-				</td>
-			 </tr>
-            
             <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -59911,13 +74290,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>is_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -59927,13 +74306,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>is_cause_of_death</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -59943,13 +74322,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
+            	<td>pk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('clin_root_item_pk_item_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -59959,13 +74338,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
+            	<td>modified_when</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -59974,21 +74353,13 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
-                  
-                
                 </td>
-            	<td>fk_encounter</td>
-            	<td>integer</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
-					
 
-					
 				
-
-				NOT NULL
 				
 				</i>
 				
@@ -59998,21 +74369,13 @@ order to link structures to codes.
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
-                  
-                
                 </td>
-            	<td>fk_episode</td>
+            	<td>row_version</td>
             	<td>integer</td>
                 <td><i>
 				
-					
 
-					
 				
-
-				NOT NULL
 				
 				</i>
 				
@@ -60023,7 +74386,7 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>narrative</td>
+            	<td>grouping</td>
             	<td>text</td>
                 <td><i>
 				
@@ -60031,7 +74394,7 @@ order to link structures to codes.
 				
 				
 				</i>
-				<br><br>Which procedure/operation was performed.
+				
 				</td>
 			 </tr>
             
@@ -60039,13 +74402,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
+            	<td>diagnostic_certainty_classification</td>
             	<td>text</td>
                 <td><i>
 				
 
 				
-				DEFAULT 'p'::text
+				
 				</i>
 				
 				</td>
@@ -60054,18 +74417,11 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>has_open_episode</td>
+            	<td>boolean</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -60077,83 +74433,32 @@ order to link structures to codes.
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.hospital-stay">clin.hospital_stay.pk</a>
-                  
-                
-                </td>
-            	<td>fk_hospital_stay</td>
-            	<td>integer</td>
-                <td><i>
-				
-					
-
-					
-				
-
-				
-				
-				</i>
-				<br><br>At which hospital was the procedure performed,
- unless clin_where is not null,
- if null it was an ambulatory procedure.
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
                 </td>
-            	<td>clin_end</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_generic_codes</td>
+            	<td>integer[]</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>When did this procedure end/is expected to end.
-- NULL if unknown or .clin_when (=start) is sufficient (eg. insignificant duration)
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>is_ongoing</td>
-            	<td>boolean</td>
-                <td><i>
 				
-
-				NOT NULL
-				DEFAULT false
-				</i>
-				<br><br>Whether this procedure is still going on (such as desensibilisation, chemotherapy, etc).
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.org-unit">dem.org_unit.pk</a>
-                  
-                
                 </td>
-            	<td>fk_org_unit</td>
-            	<td>integer</td>
+            	<td>xmin_health_issue</td>
+            	<td>xid</td>
                 <td><i>
 				
-					
-
-					
-				
 
 				
 				
 				</i>
-				<br><br>links to the or unit the procedure was performed at
+				
 				</td>
 			 </tr>
             
@@ -60161,80 +74466,91 @@ order to link structures to codes.
 
         <!-- Inherits -->
 		
-        <p>Table clin.procedure Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin_root_item</a>, 
-        
-        </p>
-		
 
 		
-		
-		
 
         <!-- Constraint List -->
 		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.procedure Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>clin_procedure_lnk_org_or_stay</td>
-                <td>CHECK ((((fk_hospital_stay IS NULL) AND (fk_org_unit IS NOT NULL)) OR ((fk_hospital_stay IS NOT NULL) AND (fk_org_unit IS NULL))))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>clin_root_item_sane_soap_cat</td>
-                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>procedure_sane_end</td>
-                <td>CHECK (((clin_end IS NULL) OR (clin_end >= clin_when)))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>procedure_sane_ongoing</td>
-                <td>CHECK (((is_ongoing IS FALSE) OR ((clin_end IS NULL) OR (clin_end > now()))))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>sane_procedure</td>
-                <td>CHECK ((gm.is_null_or_blank_string(narrative) IS FALSE))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>sane_soap_cat</td>
-                <td>CHECK ((soap_cat = ANY (ARRAY['a'::text, 'p'::text])))</td>
-            </tr>
-			
-		</table>
-		
 
         <!-- Foreign Key Discovery -->
 		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2procedure">clin.lnk_code2procedure</a></li>
-			</ul>
-		
-		
 
     <!-- Indexes -->
     
-       idx_clin_procedure_fk_encounter fk_encounter
-    
-       idx_clin_procedure_fk_episode fk_episode
-    
 
 	<!-- View Definition -->
 	
+	<pre>
+SELECT (
+SELECT encounter.fk_patient
+           
+  FROM clin.encounter
+          
+ WHERE (encounter.pk = c_hi.fk_encounter)
+) AS pk_patient
+,
+    c_hi.pk AS pk_health_issue
+,
+    c_hi.description
+,
+    c_hi.summary
+,
+    c_hi.laterality
+,
+    c_hi.age_noted
+,
+    c_hi.is_active
+,
+    c_hi.clinically_relevant
+,
+    c_hi.is_confidential
+,
+    c_hi.is_cause_of_death
+,
+    c_hi.fk_encounter AS pk_encounter
+,
+    c_hi.modified_when
+,
+    c_hi.modified_by
+,
+    c_hi.row_version
+,
+    c_hi.grouping
+,
+    c_hi.diagnostic_certainty_classification
+,
+    
+(EXISTS 
+     (
+      SELECT 1
+           
+        FROM clin.episode c_ep
+          
+       WHERE (
+                 (c_ep.fk_health_issue = c_hi.pk)
+               AND (c_ep.is_open IS TRUE)
+           )
+         LIMIT 1
+     )
+) AS has_open_episode
+,
+    COALESCE
+(
+     (
+      SELECT array_agg
+           (c_lc2h.fk_generic_code) AS array_agg
+           
+        FROM clin.lnk_code2h_issue c_lc2h
+          
+       WHERE (c_lc2h.fk_item = c_hi.pk)
+     )
+     , ARRAY[]::integer[]
+) AS pk_generic_codes
+,
+    c_hi.xmin AS xmin_health_issue
+   
+FROM clin.health_issue c_hi;</pre>
+	
 
 	<!-- List off permissions -->
 	
@@ -60245,18 +74561,15 @@ order to link structures to codes.
     </p>
 	
         <hr>
-		<h2>Table:
+		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.review-root">review_root</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-health-issues-journal">v_health_issues_journal</a>
 		</h2>
         
-         <p>this table tracks whether a particular clinical item
-	 was reviewed by a clinician or not</p>
-        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.review_root Structure</caption>
+                <caption>clin.v_health_issues_journal Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -60268,35 +74581,19 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
+            	<td>pk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>row_version</td>
-            	<td>integer</td>
-                <td><i>
 				
-
-				NOT NULL
 				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -60305,45 +74602,6 @@ order to link structures to codes.
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>modified_by</td>
-            	<td>name</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT "current_user"()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                  
-                
-                </td>
-            	<td>pk</td>
-            	<td>serial</td>
-                <td><i>
-				
-					PRIMARY KEY
-					
-
-					
-				
-
 				
 				
 				</i>
@@ -60351,60 +74609,19 @@ order to link structures to codes.
 				</td>
 			 </tr>
             
-            <tr class="tr1">
-				<td>
-                
-                  
-                
-                </td>
-            	<td>fk_reviewed_row</td>
-            	<td>integer</td>
-                <td><i>
-				
-					
-
-					
-                       UNIQUE#1
-                    
-				
-
-				NOT NULL
-				
-				</i>
-				<br><br>the row the review status is for: to be qualified
-	 as a proper foreign key in child tables
-				</td>
-			 </tr>
-            
             <tr class="tr0">
 				<td>
                 
-                  
-                
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.pk</a>
-                  
-                
                 </td>
-            	<td>fk_reviewer</td>
-            	<td>integer</td>
-                <td><i>
-				
-					
-
-					
-                       UNIQUE#1
-                    
-				
-					
-
-					
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>who has reviewed the item
+				
 				</td>
 			 </tr>
             
@@ -60412,17 +74629,15 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>is_technically_abnormal</td>
-            	<td>boolean</td>
+            	<td>modified_by</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>whether test provider flagged this result as abnormal,
-	 *not* a clinical assessment but rather a technical one
-	 LDT: exist(8422)
+				
 				</td>
 			 </tr>
             
@@ -60430,18 +74645,15 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>clinically_relevant</td>
-            	<td>boolean</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>whether this result is considered relevant clinically,
-	 need not correspond to the value of "techically_abnormal"
-	 since abnormal values may be irrelevant while normal
-	 ones can be of significance
+				
 				</td>
 			 </tr>
             
@@ -60449,7 +74661,7 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>comment</td>
+            	<td>narrative</td>
             	<td>text</td>
                 <td><i>
 				
@@ -60461,72 +74673,17 @@ order to link structures to codes.
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table clin.review_root Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.reviewed-test-results">reviewed_test_results</a>
-		</h2>
-        
-         <p>review table for test results</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.reviewed_test_results Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
+            	<td>pk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -60536,12 +74693,12 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
+            	<td>pk_episode</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -60552,13 +74709,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -60568,13 +74725,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>src_pk</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -60583,21 +74740,14 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>integer</td>
+            	<td>src_table</td>
+            	<td>text</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
 
-					
 				
-
 				
-				DEFAULT nextval('review_root_pk_seq'::regclass)
 				</i>
 				
 				</td>
@@ -60606,37 +74756,13 @@ order to link structures to codes.
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.test-result">clin.test_result.pk</a>
-                  
-                
-                  
-                
-                  
-                
                 </td>
-            	<td>fk_reviewed_row</td>
+            	<td>row_version</td>
             	<td>integer</td>
                 <td><i>
 				
-					
-
-					
-				
-					
-
-					
-                       UNIQUE#1
-                    
-				
-					
 
-					
-                       UNIQUE
-                    
 				
-
-				NOT NULL
 				
 				</i>
 				
@@ -60646,30 +74772,14 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.pk</a>
-                  
-                
                 </td>
-            	<td>fk_reviewer</td>
-            	<td>integer</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-					
-
-					
 				
-
-				NOT NULL
-				DEFAULT f_fk_reviewer_default()
 				</i>
 				
 				</td>
@@ -60679,12 +74789,12 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>is_technically_abnormal</td>
-            	<td>boolean</td>
+            	<td>issue_laterality</td>
+            	<td>character varying(2)</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -60695,12 +74805,12 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>clinically_relevant</td>
+            	<td>issue_active</td>
             	<td>boolean</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -60711,8 +74821,8 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -60723,76 +74833,14 @@ order to link structures to codes.
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table clin.reviewed_test_results Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#clin.table.review-root">review_root</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-       idx_rtr_fk_reviewer fk_reviewer
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.soap-cat-ranks">soap_cat_ranks</a>
-		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.soap_cat_ranks Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -60805,12 +74853,12 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>rank</td>
-            	<td>integer</td>
+            	<td>episode</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -60821,8 +74869,8 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
-            	<td>character(1)</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -60833,212 +74881,383 @@ order to link structures to codes.
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.soap_cat_ranks Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>clin_soap_cat_ranks_sane_cats</td>
-                <td>CHECK (((soap_cat IS NULL) OR (lower((soap_cat)::text) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
-            </tr>
-			
             <tr class="tr1">
-				<td>clin_soap_cat_ranks_sane_ranks</td>
-                <td>CHECK ((rank = ANY (ARRAY[1, 2, 3, 4, 5, 6])))</td>
-            </tr>
-			
-		</table>
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.substance-intake">substance_intake</a>
-		</h2>
-        
-         <p>The substances a patient is actually currently taking.</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.substance_intake Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>encounter_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>encounter_l10n_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_item</td>
-            	<td>integer</td>
-                <td><i>
-				
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT c_enc.fk_patient AS pk_patient
+,
+    c_hi.modified_when
+,
+    COALESCE
+(
+     (
+      SELECT (identity.dob + c_hi.age_noted)
+           
+        FROM dem.identity
+          
+       WHERE (identity.pk = 
+                 (
+                  SELECT encounter.fk_patient
+                   
+                    FROM clin.encounter
+                  
+                   WHERE (encounter.pk = c_hi.fk_encounter)
+                 )
+           )
+     )
+     , c_enc.started
+) AS clin_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_hi.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (c_hi.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    'a'::text AS soap_cat
+,
+    
+(
+     (
+           (
+                 (
+                       (
+                             (
+                                   (
+                                         (
+                                               (
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (_
+                                                                             ('Health Issue'::text) || 
+                                                                          ' ('::text) ||
+        CASE
+            WHEN c_hi.is_active THEN _
+                                                                             ('active'::text)
+            ELSE _
+                                                                             ('inactive'::text)
+        END
+                                                                       ) || 
+                                                                    ', '::text
+                                                                 ) ||
+        CASE
+            WHEN c_hi.clinically_relevant THEN _
+                                                                 ('clinically relevant'::text)
+            ELSE _
+                                                                 ('clinically not relevant'::text)
+        END
+                                                           ) || COALESCE
+                                                           (
+                                                                 (
+                                                                    ', '::text || c_hi.diagnostic_certainty_classification
+                                                                 )
+                                                                 ,''::text
+                                                           )
+                                                     ) || 
+                                           '): '::text
+                                         ) || c_hi.description
+                                   ) || COALESCE
+                                   (
+                                         (
+                                               (
+                                                     (
+                                                           (';
+'::text || _
+                                                                 ('noted at age'::text)
+                                                           ) || ': '::text
+                                                     ) || 
+                                                     (c_hi.age_noted)::text
+                                               ) || ';
+'::text
+                                         )
+                                         ,';
+'::text
+                                   )
+                             ) || COALESCE
+                             (
+                                   (
+                                         (
+                                               (_
+                                                     ('Laterality'::text) || ': '::text
+                                               ) || 
+                                               (c_hi.laterality)::text
+                                         ) || ' / '::text
+                                   )
+                                   ,''::text
+                             )
+                       ) ||
+        CASE
+            WHEN c_hi.is_confidential THEN 
+                       (_
+                             ('confidential'::text) || ' / '::text
+                       )
+            ELSE ''::text
+        END
+                 ) ||
+        CASE
+            WHEN c_hi.is_cause_of_death THEN _
+                 ('cause of death'::text)
+            ELSE ''::text
+        END
+           ) || COALESCE
+           (
+                 (
+                       (
+                             (';
+'::text || _
+                                   ('Summary'::text)
+                             ) || ':
+'::text
+                       ) || c_hi.summary
+                 )
+                 ,''::text
+           )
+     ) || COALESCE
+     (
+           (
+                 (';
+'::text || array_to_string
+                       (
+                             (
+                              SELECT array_agg
+                                   (
+                                         (
+                                               (
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (
+                                                                             (
+                                                                                   (r_csr.code || 
+                                                                                      ' ('::text) || r_ds.name_short
+                                                                                   ) || ' - '::text
+                                                                             ) || r_ds.version
+                                                                       ) || ' - '::text
+                                                                 ) || r_ds.lang
+                                                           ) || 
+                                                 '): '::text
+                                               ) || r_csr.term
+                                         )
+                                   ) AS array_agg
+           
+                                FROM (
+                                         (clin.lnk_code2h_issue c_lc2h
+             
+                                            JOIN ref.coding_system_root r_csr 
+                                              ON (
+                                                     (c_lc2h.fk_generic_code = r_csr.pk_coding_system)
+                                               )
+                                         )
+             
+                                      JOIN ref.data_source r_ds 
+                                        ON (
+                                               (r_ds.pk = r_csr.fk_data_source)
+                                         )
+                                   )
+          
+                               WHERE (c_lc2h.fk_item = c_hi.pk)
+                             )
+                             ,'; '::text
+                       )
+                 ) || ';'::text
+           )
+           ,''::text
+     )
+) AS narrative
+,
+    c_hi.fk_encounter AS pk_encounter
+,
+    NULL::integer AS pk_episode
+,
+    c_hi.pk AS pk_health_issue
+,
+    c_hi.pk AS src_pk
+,
+    'clin.health_issue'::text AS src_table
+,
+    c_hi.row_version
+,
+    c_hi.description AS health_issue
+,
+    c_hi.laterality AS issue_laterality
+,
+    c_hi.is_active AS issue_active
+,
+    c_hi.clinically_relevant AS issue_clinically_relevant
+,
+    c_hi.is_confidential AS issue_confidential
+,
+    NULL::text AS episode
+,
+    NULL::boolean AS episode_open
+,
+    c_enc.started AS encounter_started
+,
+    c_enc.last_affirmed AS encounter_last_affirmed
+,
+    c_ety.description AS encounter_type
+,
+    _
+(c_ety.description) AS encounter_l10n_type
+   
+FROM (
+     (clin.health_issue c_hi
+     
+        JOIN clin.encounter c_enc 
+          ON (
+                 (c_hi.fk_encounter = c_enc.pk)
+           )
+     )
+     
+  JOIN clin.encounter_type c_ety 
+    ON (
+           (c_enc.fk_type = c_ety.pk)
+     )
+);</pre>
+	
+
+	<!-- List off permissions -->
+	
 
-				NOT NULL
-				DEFAULT nextval('clin_root_item_pk_item_seq'::regclass)
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-hospital-stays">v_hospital_stays</a>
+		</h2>
+        
 
-				NOT NULL
-				DEFAULT now()
-				</i>
-				<br><br>When was this substance started.
-				</td>
-			 </tr>
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.v_hospital_stays Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
-                  
-                
                 </td>
-            	<td>fk_encounter</td>
+            	<td>pk_hospital_stay</td>
             	<td>integer</td>
                 <td><i>
 				
-					
 
-					
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>The encounter use of this substance was documented under.
+				
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
-                  
-                
                 </td>
-            	<td>fk_episode</td>
+            	<td>pk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
-					
 
-					
 				
-
-				NOT NULL
 				
 				</i>
 				
@@ -61049,7 +75268,7 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>narrative</td>
+            	<td>hospital</td>
             	<td>text</td>
                 <td><i>
 				
@@ -61057,7 +75276,7 @@ order to link structures to codes.
 				
 				
 				</i>
-				<br><br>Any notes on this substance use.
+				
 				</td>
 			 </tr>
             
@@ -61065,13 +75284,13 @@ order to link structures to codes.
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
+            	<td>ward</td>
             	<td>text</td>
                 <td><i>
 				
 
 				
-				DEFAULT 'p'::text
+				
 				</i>
 				
 				</td>
@@ -61080,18 +75299,11 @@ order to link structures to codes.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -61103,28 +75315,16 @@ order to link structures to codes.
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#ref.table.consumable-substance">ref.consumable_substance.pk</a>
-                  
-                
                 </td>
-            	<td>fk_substance</td>
-            	<td>integer</td>
+            	<td>admission</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
-					
-
-					
-				
 
 				
 				
 				</i>
-				<br><br>Links to a substance the patient is taking.
-********************************************* 
-DO NOT TRY TO USE THIS TO FIND OUT THE BRAND.
-IT WILL BE WRONG.
-*********************************************
+				
 				</td>
 			 </tr>
             
@@ -61132,15 +75332,15 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>preparation</td>
-            	<td>text</td>
+            	<td>discharge</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>How this substance is delivered, tablet, pill, liquid, cream.
+				
 				</td>
 			 </tr>
             
@@ -61148,7 +75348,7 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>schedule</td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -61156,8 +75356,7 @@ IT WILL BE WRONG.
 				
 				
 				</i>
-				<br><br>The schedule, if any, the substance is to be taken by.
- An XML snippet to be interpreted by the middleware.
+				
 				</td>
 			 </tr>
             
@@ -61165,7 +75364,7 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>aim</td>
+            	<td>episode</td>
             	<td>text</td>
                 <td><i>
 				
@@ -61173,39 +75372,7 @@ IT WILL BE WRONG.
 				
 				
 				</i>
-				<br><br>The aim of taking this substance.
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>duration</td>
-            	<td>interval</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				<br><br>How long is this substances intended to be taken.
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>intake_is_approved_of</td>
-            	<td>boolean</td>
-                <td><i>
-				
-
-				NOT NULL
 				
-				</i>
-				<br><br>Whether or not intake of this substance is recommended/approved of by the provider
 				</td>
 			 </tr>
             
@@ -61213,15 +75380,15 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>is_long_term</td>
-            	<td>boolean</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>whether this is expected to be a regular/ongoing/chronic/long-term/repeat/permament/perpetual/life-long substance intake
+				
 				</td>
 			 </tr>
             
@@ -61229,15 +75396,15 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>discontinued</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>When was this intake discontinued ?
+				
 				</td>
 			 </tr>
             
@@ -61245,200 +75412,67 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>discontinue_reason</td>
-            	<td>text</td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>Why was this intake discontinued ?
+				
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#ref.table.lnk-substance2brand">ref.lnk_substance2brand.pk</a>
-                  
-                
                 </td>
-            	<td>fk_drug_component</td>
+            	<td>pk_health_issue</td>
             	<td>integer</td>
                 <td><i>
 				
-					
-
-					
-				
 
 				
 				
 				</i>
-				<br><br>Links to the component of a branded drug taken by a patient.
+				
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table clin.substance_intake Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin_root_item</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.substance_intake Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>clin_root_item_sane_soap_cat</td>
-                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>clin_subst_intake_either_drug_or_substance</td>
-                <td>CHECK ((((fk_drug_component IS NULL) AND (fk_substance IS NOT NULL)) OR ((fk_drug_component IS NOT NULL) AND (fk_substance IS NULL))))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>clin_subst_intake_sane_prep</td>
-                <td>CHECK ((((fk_drug_component IS NULL) AND (preparation IS NOT NULL)) OR ((fk_drug_component IS NOT NULL) AND (preparation IS NULL))))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>discontinued_after_started</td>
-                <td>CHECK ((((clin_when IS NULL) OR (discontinued IS NULL)) OR ((discontinued >= clin_when) AND (discontinued <= now()))))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>medication_is_plan</td>
-                <td>CHECK ((soap_cat = 'p'::text))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>sane_aim</td>
-                <td>CHECK ((gm.is_null_or_non_empty_string(aim) IS TRUE))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>sane_discontinue_reason</td>
-                <td>CHECK ((((discontinued IS NULL) AND (discontinue_reason IS NULL)) OR ((discontinued IS NOT NULL) AND (gm.is_null_or_non_empty_string(discontinue_reason) IS TRUE))))</td>
-            </tr>
-			
             <tr class="tr1">
-				<td>sane_fk_episode</td>
-                <td>CHECK (((intake_is_approved_of IS FALSE) OR ((intake_is_approved_of IS TRUE) AND (fk_episode IS NOT NULL))))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>sane_schedule</td>
-                <td>CHECK ((gm.is_null_or_non_empty_string(schedule) IS TRUE))</td>
-            </tr>
-			
-		</table>
-		
-
-        <!-- Foreign Key Discovery -->
-		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.lnk-substance2episode">clin.lnk_substance2episode</a></li>
-			</ul>
-		
-		
-
-    <!-- Indexes -->
-    
-       idx_c_subst_int_fk_drug_comp fk_drug_component
-    
-       idx_clin_substance_intake_fk_encounter fk_encounter
-    
-       idx_clin_substance_intake_fk_episode fk_episode
-    
-       idx_fk_substance_curr_med fk_substance
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.suppressed-hint">suppressed_hint</a>
-		</h2>
-        
-         <p>A table to hold hints suppressed per patient</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.suppressed_hint Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
+            	<td>pk_org_unit</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>row_version</td>
+            	<td>pk_org</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -61447,24 +75481,8 @@ IT WILL BE WRONG.
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
-				</i>
 				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>modified_by</td>
-            	<td>name</td>
-                <td><i>
 				
-
-				NOT NULL
-				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -61473,18 +75491,11 @@ IT WILL BE WRONG.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>modified_by</td>
+            	<td>text</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -61496,64 +75507,16 @@ IT WILL BE WRONG.
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
-                  
-                
-                </td>
-            	<td>fk_encounter</td>
-            	<td>integer</td>
-                <td><i>
-				
-					
-
-					
-				
-
-				NOT NULL
-				
-				</i>
-				<br><br>the encounter during which this hint was first suppressed
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                  
-                  <a href="gnumed-entire_schema.html#ref.table.auto-hint">ref.auto_hint.pk</a>
-                  
-                
                 </td>
-            	<td>fk_hint</td>
+            	<td>row_version</td>
             	<td>integer</td>
                 <td><i>
 				
-					
 
-					
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>the hint that is suppressed
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>suppressed_by</td>
-            	<td>name</td>
-                <td><i>
 				
-
-				NOT NULL
-				DEFAULT "current_user"()
-				</i>
-				<br><br>who suppressed this hint
 				</td>
 			 </tr>
             
@@ -61561,47 +75524,15 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>suppressed_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT statement_timestamp()
-				</i>
-				<br><br>when was this hint suppressed
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>rationale</td>
-            	<td>text</td>
+            	<td>xmin_hospital_stay</td>
+            	<td>xid</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>rationale on why this hint is suppressed in this patient
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>md5_sum</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
 				
-				</i>
-				<br><br>md5 of relevant fields of this hint
 				</td>
 			 </tr>
             
@@ -61609,58 +75540,109 @@ IT WILL BE WRONG.
 
         <!-- Inherits -->
 		
-        <p>Table clin.suppressed_hint Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
 
 		
-		
-		
 
         <!-- Constraint List -->
 		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.suppressed_hint Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>clin_suppressed_hint_sane_by</td>
-                <td>CHECK ((length((suppressed_by)::text) > 0))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>clin_suppressed_hint_sane_md5</td>
-                <td>CHECK ((gm.is_null_or_blank_string(md5_sum) IS FALSE))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>clin_suppressed_hint_sane_rationale</td>
-                <td>CHECK ((gm.is_null_or_blank_string(rationale) IS FALSE))</td>
-            </tr>
-			
-		</table>
-		
 
         <!-- Foreign Key Discovery -->
 		
 
     <!-- Indexes -->
     
-       idx_suppressed_hint_fk_encounter fk_encounter
-    
-       idx_suppressed_hint_fk_hint fk_hint
-    
 
 	<!-- View Definition -->
 	
+	<pre>
+SELECT c_hs.pk AS pk_hospital_stay
+,
+    
+(
+SELECT encounter.fk_patient
+           
+  FROM clin.encounter
+          
+ WHERE (encounter.pk = c_hs.fk_encounter)
+) AS pk_patient
+,
+    d_o.description AS hospital
+,
+    d_ou.description AS ward
+,
+    c_hs.narrative AS comment
+,
+    c_hs.clin_when AS admission
+,
+    c_hs.discharge
+,
+    c_hs.soap_cat
+,
+    c_e.description AS episode
+,
+    c_hi.description AS health_issue
+,
+    c_hs.fk_encounter AS pk_encounter
+,
+    c_hs.fk_episode AS pk_episode
+,
+    c_hi.pk AS pk_health_issue
+,
+    c_hs.fk_org_unit AS pk_org_unit
+,
+    d_o.pk AS pk_org
+,
+    c_hs.modified_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_hs.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (c_hs.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    c_hs.row_version
+,
+    c_hs.xmin AS xmin_hospital_stay
+   
+FROM (
+     (
+           (
+                 (clin.hospital_stay c_hs
+     
+               LEFT JOIN clin.episode c_e 
+                      ON (
+                             (c_e.pk = c_hs.fk_episode)
+                       )
+                 )
+     
+         LEFT JOIN clin.health_issue c_hi 
+                ON (
+                       (c_hi.pk = c_e.fk_health_issue)
+                 )
+           )
+     
+   LEFT JOIN dem.org_unit d_ou 
+          ON (
+                 (d_ou.pk = c_hs.fk_org_unit)
+           )
+     )
+     
+LEFT JOIN dem.org d_o 
+    ON (
+           (d_o.pk = d_ou.fk_org)
+     )
+);</pre>
+	
 
 	<!-- List off permissions -->
 	
@@ -61671,17 +75653,15 @@ IT WILL BE WRONG.
     </p>
 	
         <hr>
-		<h2>Table:
+		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.test-org">test_org</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-hospital-stays-journal">v_hospital_stays_journal</a>
 		</h2>
         
-         <p>organisation providing results</p>
-        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.test_org Structure</caption>
+                <caption>clin.v_hospital_stays_journal Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -61693,13 +75673,13 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
+            	<td>pk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -61709,12 +75689,12 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -61725,13 +75705,13 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
+            	<td>clin_when</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -61742,12 +75722,12 @@ IT WILL BE WRONG.
                 
                 </td>
             	<td>modified_by</td>
-            	<td>name</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -61756,18 +75736,11 @@ IT WILL BE WRONG.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -61779,81 +75752,48 @@ IT WILL BE WRONG.
             <tr class="tr1">
 				<td>
                 
-                  
-                
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.org-unit">dem.org_unit.pk</a>
-                  
-                
                 </td>
-            	<td>fk_org_unit</td>
-            	<td>integer</td>
+            	<td>narrative</td>
+            	<td>text</td>
                 <td><i>
 				
-					
-
-					
-                       UNIQUE
-                    
-				
-					
 
-					
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>link to a unit of an organization more closely defining this lab
+				
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.identity">dem.identity.pk</a>
-                  
-                
                 </td>
-            	<td>fk_adm_contact</td>
+            	<td>pk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
-					
-
-					
-				
 
 				
 				
 				</i>
-				<br><br>whom to call for admin questions (modem link, etc.)
+				
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.identity">dem.identity.pk</a>
-                  
-                
                 </td>
-            	<td>fk_med_contact</td>
+            	<td>pk_episode</td>
             	<td>integer</td>
                 <td><i>
 				
-					
-
-					
-				
 
 				
 				
 				</i>
-				<br><br>whom to call for medical questions (result verification,
-	 additional test requests)
+				
 				</td>
 			 </tr>
             
@@ -61861,17 +75801,15 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>useful for, say, dummy records where you want
-	 to mark up stuff like "pharmacy such-and-such"
-	 if you don't have it in your contacts
+				
 				</td>
 			 </tr>
             
@@ -61879,119 +75817,29 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>contact</td>
-            	<td>text</td>
+            	<td>src_pk</td>
+            	<td>integer</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>free-text contact information for this lab
+				
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table clin.test_org Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.test_org Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>sane_comment</td>
-                <td>CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>sane_contact</td>
-                <td>CHECK ((gm.is_null_or_non_empty_string(contact) IS TRUE))</td>
-            </tr>
-			
-		</table>
-		
-
-        <!-- Foreign Key Discovery -->
-		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.lab-request">clin.lab_request</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.test-type">clin.test_type</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#staging.table.lab-request">staging.lab_request</a></li>
-			</ul>
-		
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.test-panel">test_panel</a>
-		</h2>
-        
-         <p>Panels of tests. The same test can appear in several panels.</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.test_panel Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
+            	<td>src_table</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -62006,7 +75854,7 @@ IT WILL BE WRONG.
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -62017,13 +75865,13 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -62033,13 +75881,13 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>issue_laterality</td>
+            	<td>character varying(2)</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -62048,18 +75896,11 @@ IT WILL BE WRONG.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -62072,15 +75913,15 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>description</td>
-            	<td>text</td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>A description/label for this panel.
+				
 				</td>
 			 </tr>
             
@@ -62088,15 +75929,15 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>An arbitrary comment on this panel.
+				
 				</td>
 			 </tr>
             
@@ -62104,111 +75945,29 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>fk_test_types</td>
-            	<td>integer[]</td>
+            	<td>episode</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>Links to test types which belong to this panel.
+				
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table clin.test_panel Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.test_panel Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>clin_test_panel_sane_cmt</td>
-                <td>CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>clin_test_panel_sane_desc</td>
-                <td>CHECK ((gm.is_null_or_blank_string(description) IS FALSE))</td>
-            </tr>
-			
-		</table>
-		
-
-        <!-- Foreign Key Discovery -->
-		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2tst-pnl">clin.lnk_code2tst_pnl</a></li>
-			</ul>
-		
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.test-result">test_result</a>
-		</h2>
-        
-         <p>the results of a single measurement</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.test_result Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -62218,12 +75977,12 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -62234,130 +75993,306 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
+            	<td>encounter_last_affirmed</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
-				</i>
 				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>modified_by</td>
-            	<td>name</td>
-                <td><i>
 				
-
-				NOT NULL
-				DEFAULT "current_user"()
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
-            	<td>integer</td>
+            	<td>encounter_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('clin_root_item_pk_item_seq'::regclass)
-				</i>
 				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
 				
-
-				NOT NULL
-				DEFAULT now()
 				</i>
-				<br><br>the time when this result was *actually* obtained,
-	 if this is a lab result this should be between
-	 lab_request.clin_when and lab_request.results_reported_when,
-	 HL7: OBR.observation_date_time
+				
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter.pk</a>
-                  
-                
                 </td>
-            	<td>fk_encounter</td>
-            	<td>integer</td>
+            	<td>encounter_l10n_type</td>
+            	<td>text</td>
                 <td><i>
 				
-					
 
-					
 				
-
-				NOT NULL
 				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr1">
-				<td>
-                
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.episode">clin.episode.pk</a>
-                  
-                
-                </td>
-            	<td>fk_episode</td>
-            	<td>integer</td>
-                <td><i>
-				
-					
+        </table>
 
-					
-				
+        <!-- Inherits -->
+		
 
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT v_hospital_stays_journal_no_discharge.pk_patient
+,
+    v_hospital_stays_journal_no_discharge.modified_when
+,
+    v_hospital_stays_journal_no_discharge.clin_when
+,
+    v_hospital_stays_journal_no_discharge.modified_by
+,
+    v_hospital_stays_journal_no_discharge.soap_cat
+,
+    v_hospital_stays_journal_no_discharge.narrative
+,
+    v_hospital_stays_journal_no_discharge.pk_encounter
+,
+    v_hospital_stays_journal_no_discharge.pk_episode
+,
+    v_hospital_stays_journal_no_discharge.pk_health_issue
+,
+    v_hospital_stays_journal_no_discharge.src_pk
+,
+    v_hospital_stays_journal_no_discharge.src_table
+,
+    v_hospital_stays_journal_no_discharge.row_version
+,
+    v_hospital_stays_journal_no_discharge.health_issue
+,
+    v_hospital_stays_journal_no_discharge.issue_laterality
+,
+    v_hospital_stays_journal_no_discharge.issue_active
+,
+    v_hospital_stays_journal_no_discharge.issue_clinically_relevant
+,
+    v_hospital_stays_journal_no_discharge.issue_confidential
+,
+    v_hospital_stays_journal_no_discharge.episode
+,
+    v_hospital_stays_journal_no_discharge.episode_open
+,
+    v_hospital_stays_journal_no_discharge.encounter_started
+,
+    v_hospital_stays_journal_no_discharge.encounter_last_affirmed
+,
+    v_hospital_stays_journal_no_discharge.encounter_type
+,
+    v_hospital_stays_journal_no_discharge.encounter_l10n_type
+   
+FROM clin.v_hospital_stays_journal_no_discharge
+
+UNION ALL
+ 
+SELECT v_hospital_stays_journal_one_day.pk_patient
+,
+    v_hospital_stays_journal_one_day.modified_when
+,
+    v_hospital_stays_journal_one_day.clin_when
+,
+    v_hospital_stays_journal_one_day.modified_by
+,
+    v_hospital_stays_journal_one_day.soap_cat
+,
+    v_hospital_stays_journal_one_day.narrative
+,
+    v_hospital_stays_journal_one_day.pk_encounter
+,
+    v_hospital_stays_journal_one_day.pk_episode
+,
+    v_hospital_stays_journal_one_day.pk_health_issue
+,
+    v_hospital_stays_journal_one_day.src_pk
+,
+    v_hospital_stays_journal_one_day.src_table
+,
+    v_hospital_stays_journal_one_day.row_version
+,
+    v_hospital_stays_journal_one_day.health_issue
+,
+    v_hospital_stays_journal_one_day.issue_laterality
+,
+    v_hospital_stays_journal_one_day.issue_active
+,
+    v_hospital_stays_journal_one_day.issue_clinically_relevant
+,
+    v_hospital_stays_journal_one_day.issue_confidential
+,
+    v_hospital_stays_journal_one_day.episode
+,
+    v_hospital_stays_journal_one_day.episode_open
+,
+    v_hospital_stays_journal_one_day.encounter_started
+,
+    v_hospital_stays_journal_one_day.encounter_last_affirmed
+,
+    v_hospital_stays_journal_one_day.encounter_type
+,
+    v_hospital_stays_journal_one_day.encounter_l10n_type
+   
+FROM clin.v_hospital_stays_journal_one_day
+
+UNION ALL
+ 
+SELECT v_hospital_stays_journal_multi_day_adm.pk_patient
+,
+    v_hospital_stays_journal_multi_day_adm.modified_when
+,
+    v_hospital_stays_journal_multi_day_adm.clin_when
+,
+    v_hospital_stays_journal_multi_day_adm.modified_by
+,
+    v_hospital_stays_journal_multi_day_adm.soap_cat
+,
+    v_hospital_stays_journal_multi_day_adm.narrative
+,
+    v_hospital_stays_journal_multi_day_adm.pk_encounter
+,
+    v_hospital_stays_journal_multi_day_adm.pk_episode
+,
+    v_hospital_stays_journal_multi_day_adm.pk_health_issue
+,
+    v_hospital_stays_journal_multi_day_adm.src_pk
+,
+    v_hospital_stays_journal_multi_day_adm.src_table
+,
+    v_hospital_stays_journal_multi_day_adm.row_version
+,
+    v_hospital_stays_journal_multi_day_adm.health_issue
+,
+    v_hospital_stays_journal_multi_day_adm.issue_laterality
+,
+    v_hospital_stays_journal_multi_day_adm.issue_active
+,
+    v_hospital_stays_journal_multi_day_adm.issue_clinically_relevant
+,
+    v_hospital_stays_journal_multi_day_adm.issue_confidential
+,
+    v_hospital_stays_journal_multi_day_adm.episode
+,
+    v_hospital_stays_journal_multi_day_adm.episode_open
+,
+    v_hospital_stays_journal_multi_day_adm.encounter_started
+,
+    v_hospital_stays_journal_multi_day_adm.encounter_last_affirmed
+,
+    v_hospital_stays_journal_multi_day_adm.encounter_type
+,
+    v_hospital_stays_journal_multi_day_adm.encounter_l10n_type
+   
+FROM clin.v_hospital_stays_journal_multi_day_adm
+
+UNION ALL
+ 
+SELECT v_hospital_stays_journal_multi_day_dis.pk_patient
+,
+    v_hospital_stays_journal_multi_day_dis.modified_when
+,
+    v_hospital_stays_journal_multi_day_dis.clin_when
+,
+    v_hospital_stays_journal_multi_day_dis.modified_by
+,
+    v_hospital_stays_journal_multi_day_dis.soap_cat
+,
+    v_hospital_stays_journal_multi_day_dis.narrative
+,
+    v_hospital_stays_journal_multi_day_dis.pk_encounter
+,
+    v_hospital_stays_journal_multi_day_dis.pk_episode
+,
+    v_hospital_stays_journal_multi_day_dis.pk_health_issue
+,
+    v_hospital_stays_journal_multi_day_dis.src_pk
+,
+    v_hospital_stays_journal_multi_day_dis.src_table
+,
+    v_hospital_stays_journal_multi_day_dis.row_version
+,
+    v_hospital_stays_journal_multi_day_dis.health_issue
+,
+    v_hospital_stays_journal_multi_day_dis.issue_laterality
+,
+    v_hospital_stays_journal_multi_day_dis.issue_active
+,
+    v_hospital_stays_journal_multi_day_dis.issue_clinically_relevant
+,
+    v_hospital_stays_journal_multi_day_dis.issue_confidential
+,
+    v_hospital_stays_journal_multi_day_dis.episode
+,
+    v_hospital_stays_journal_multi_day_dis.episode_open
+,
+    v_hospital_stays_journal_multi_day_dis.encounter_started
+,
+    v_hospital_stays_journal_multi_day_dis.encounter_last_affirmed
+,
+    v_hospital_stays_journal_multi_day_dis.encounter_type
+,
+    v_hospital_stays_journal_multi_day_dis.encounter_l10n_type
+   
+FROM clin.v_hospital_stays_journal_multi_day_dis;</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-hospital-stays-journal-multi-day-adm">v_hospital_stays_journal_multi_day_adm</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.v_hospital_stays_journal_multi_day_adm Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>narrative</td>
-            	<td>text</td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>clinical comment, progress note
+				
 				</td>
 			 </tr>
             
@@ -62365,13 +76300,13 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
 				
-				DEFAULT 'o'::text
+				
 				</i>
 				
 				</td>
@@ -62380,18 +76315,11 @@ IT WILL BE WRONG.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -62403,24 +76331,16 @@ IT WILL BE WRONG.
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.test-type">clin.test_type.pk</a>
-                  
-                
                 </td>
-            	<td>fk_type</td>
-            	<td>integer</td>
+            	<td>modified_by</td>
+            	<td>text</td>
                 <td><i>
 				
-					
 
-					
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>the type of test this result is from
+				
 				</td>
 			 </tr>
             
@@ -62428,16 +76348,15 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>val_num</td>
-            	<td>numeric</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>numeric value if any,
-	 HL7: OBX.observation_results if OBX.value_type == NM
+				
 				</td>
 			 </tr>
             
@@ -62445,7 +76364,7 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>val_alpha</td>
+            	<td>narrative</td>
             	<td>text</td>
                 <td><i>
 				
@@ -62453,8 +76372,7 @@ IT WILL BE WRONG.
 				
 				
 				</i>
-				<br><br>alphanumeric value if any,
-	 HL7: OBX.observation_results if OBX.value_type == FT
+				
 				</td>
 			 </tr>
             
@@ -62462,16 +76380,15 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>val_unit</td>
-            	<td>text</td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>the unit this result came in
-	 HL7: OBX.units
+				
 				</td>
 			 </tr>
             
@@ -62479,16 +76396,15 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>val_normal_min</td>
-            	<td>numeric</td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>lower bound of normal range if numerical as
-	 defined by provider for this result
+				
 				</td>
 			 </tr>
             
@@ -62496,16 +76412,15 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>val_normal_max</td>
-            	<td>numeric</td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>upper bound of normal range if numerical as
-	 defined by provider for this result
+				
 				</td>
 			 </tr>
             
@@ -62513,18 +76428,15 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>val_normal_range</td>
-            	<td>text</td>
+            	<td>src_pk</td>
+            	<td>integer</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>range of normal values if alphanumerical
-	 as defined by provider for this result, eg.
-	 "less than 0.5 but detectable"
-	 HL7: OBX.reference_range
+				
 				</td>
 			 </tr>
             
@@ -62532,16 +76444,15 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>val_target_min</td>
-            	<td>numeric</td>
+            	<td>src_table</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>lower bound of target range if numerical as
-	 defined by clinician caring this patient
+				
 				</td>
 			 </tr>
             
@@ -62549,16 +76460,15 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>val_target_max</td>
-            	<td>numeric</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>upper bound of target range if numerical as
-	 defined by clinician caring for this patient
+				
 				</td>
 			 </tr>
             
@@ -62566,7 +76476,7 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>val_target_range</td>
+            	<td>health_issue</td>
             	<td>text</td>
                 <td><i>
 				
@@ -62574,8 +76484,7 @@ IT WILL BE WRONG.
 				
 				
 				</i>
-				<br><br>range of target values if alphanumerical
-	 as defined by clinician caring for this patient
+				
 				</td>
 			 </tr>
             
@@ -62583,17 +76492,15 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>abnormality_indicator</td>
-            	<td>text</td>
+            	<td>issue_laterality</td>
+            	<td>character varying(2)</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>how the test provider flagged this result as abnormal,
-	 *not* a clinical assessment but rather a technical one
-	 LDT: 8422
+				
 				</td>
 			 </tr>
             
@@ -62601,18 +76508,15 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>norm_ref_group</td>
-            	<td>text</td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>what sample of the population does this normal range
-	 applay to, eg what type of patient was assumed when
-	 interpreting this result,
-	 LDT: 8407
+				
 				</td>
 			 </tr>
             
@@ -62620,15 +76524,15 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>note_test_org</td>
-            	<td>text</td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>A comment on the test result provided by the tester or testing entity.
+				
 				</td>
 			 </tr>
             
@@ -62636,16 +76540,15 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>material</td>
-            	<td>text</td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>the submitted material, eg. smear, serum, urine, etc.,
-	 LDT: 8430
+				
 				</td>
 			 </tr>
             
@@ -62653,7 +76556,7 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>material_detail</td>
+            	<td>episode</td>
             	<td>text</td>
                 <td><i>
 				
@@ -62661,56 +76564,39 @@ IT WILL BE WRONG.
 				
 				
 				</i>
-				<br><br>details re the material, eg. site taken from, etc.
-	 LDT: 8431
+				
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.pk</a>
-                  
-                
                 </td>
-            	<td>fk_intended_reviewer</td>
-            	<td>integer</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
-					
 
-					
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>who is *supposed* to review this item
+				
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.lab-request">clin.lab_request.pk</a>
-                  
-                
                 </td>
-            	<td>fk_request</td>
-            	<td>integer</td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
-					
-
-					
-				
 
 				
 				
 				</i>
-				<br><br>The request this result was ordered under if any.
+				
 				</td>
 			 </tr>
             
@@ -62718,15 +76604,15 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>status</td>
-            	<td>text</td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>The result status (say, HL7 OBX 11 Observ result status (#00579, table 0085).
+				
 				</td>
 			 </tr>
             
@@ -62734,7 +76620,7 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>source_data</td>
+            	<td>encounter_type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -62742,7 +76628,7 @@ IT WILL BE WRONG.
 				
 				
 				</i>
-				<br><br>The source data for this observation (say, HL7 OBX).
+				
 				</td>
 			 </tr>
             
@@ -62750,7 +76636,7 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>val_grouping</td>
+            	<td>encounter_l10n_type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -62758,7 +76644,7 @@ IT WILL BE WRONG.
 				
 				
 				</i>
-				<br><br>A grouping for related values (say, HL7 OBX Obs Sub ID, think antibiogram).
+				
 				</td>
 			 </tr>
             
@@ -62766,86 +76652,203 @@ IT WILL BE WRONG.
 
         <!-- Inherits -->
 		
-        <p>Table clin.test_result Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#clin.table.clin-root-item">clin_root_item</a>, 
-        
-        </p>
-		
 
 		
-		
-		
 
         <!-- Constraint List -->
 		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>clin.test_result Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>clin_root_item_sane_soap_cat</td>
-                <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>clin_test_result_sane_source_data</td>
-                <td>CHECK (gm.is_null_or_non_empty_string(source_data))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>clin_test_result_sane_status</td>
-                <td>CHECK (gm.is_null_or_non_empty_string(status))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>clin_test_result_sane_val_grouping</td>
-                <td>CHECK (gm.is_null_or_non_empty_string(val_grouping))</td>
-            </tr>
-			
-            <tr class="tr0">
-				<td>numval_needs_unit</td>
-                <td>CHECK ((((val_num IS NOT NULL) AND (btrim(COALESCE(val_unit, ''::text)) <> ''::text)) OR (val_num IS NULL)))</td>
-            </tr>
-			
-            <tr class="tr1">
-				<td>test_result_check</td>
-                <td>CHECK ((((val_num IS NOT NULL) OR (val_alpha IS NOT NULL)) OR (((val_num IS NULL) AND (val_alpha <> ''::text)) AND (val_alpha IS NOT NULL))))</td>
-            </tr>
-			
-		</table>
-		
 
         <!-- Foreign Key Discovery -->
 		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.reviewed-test-results">clin.reviewed_test_results</a></li>
-			</ul>
-		
-		
 
     <!-- Indexes -->
     
-       idx_clin_test_result_fk_encounter fk_encounter
-    
-       idx_clin_test_result_fk_episode fk_episode
-    
-       idx_test_result_fk_type fk_type
-    
-       idx_test_result_status status
-    
-       idx_test_result_unit val_unit
-    
 
 	<!-- View Definition -->
 	
+	<pre>
+SELECT c_enc.fk_patient AS pk_patient
+,
+    c_hs.modified_when
+,
+    c_hs.clin_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_hs.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (c_hs.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    c_hs.soap_cat
+,
+    
+(
+     (
+           (
+                 (
+                       (
+                             (
+                                   (
+                                         (
+                                               (
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (
+                                                                             (
+                                                                                   (
+                                                                                         (
+                                                                                               (
+                                                                                                     (
+                                                                                                           (
+                                                                                                                 (_
+                                                                                                                       ('hospital stay'::text) || '
+'::text
+                                                                                                                 ) || ' '::text
+                                                                                                           ) || _
+                                                                                                           ('admitted'::text)
+                                                                                                     ) || ': '::text
+                                                                                               ) || to_char
+                                                                                               (c_hs.clin_when
+                                                                                                     ,'YYYY-MM-DD'::text
+                                                                                               )
+                                                                                         ) || '
+'::text
+                                                                                   ) || ' '::text
+                                                                             ) || _
+                                                                             ('discharged'::text)
+                                                                       ) || ': '::text
+                                                                 ) || to_char
+                                                                 (c_hs.discharge
+                                                                       ,'YYYY-MM-DD'::text
+                                                                 )
+                                                           ) || '
+'::text
+                                                     ) || ' '::text
+                                               ) || _
+                                               ('hospital'::text)
+                                         ) || ': "'::text
+                                   ) || d_ou.description
+                             ) || ' @ '::text
+                       ) || d_o.description
+                 ) || '"'::text
+           ) || '
+'::text
+     ) || COALESCE
+     (
+           ('
+ '::text || c_hs.narrative)
+           ,''::text
+     )
+) AS narrative
+,
+    c_hs.fk_encounter AS pk_encounter
+,
+    c_hs.fk_episode AS pk_episode
+,
+    
+(
+SELECT episode.fk_health_issue
+           
+  FROM clin.episode
+          
+ WHERE (episode.pk = c_hs.fk_episode)
+) AS pk_health_issue
+,
+    c_hs.pk AS src_pk
+,
+    'clin.hospital_stay'::text AS src_table
+,
+    c_hs.row_version
+,
+    c_hi.description AS health_issue
+,
+    c_hi.laterality AS issue_laterality
+,
+    c_hi.is_active AS issue_active
+,
+    c_hi.clinically_relevant AS issue_clinically_relevant
+,
+    c_hi.is_confidential AS issue_confidential
+,
+    c_epi.description AS episode
+,
+    c_epi.is_open AS episode_open
+,
+    c_enc.started AS encounter_started
+,
+    c_enc.last_affirmed AS encounter_last_affirmed
+,
+    c_ety.description AS encounter_type
+,
+    _
+(c_ety.description) AS encounter_l10n_type
+   
+FROM (
+     (
+           (
+                 (
+                       (
+                             (clin.hospital_stay c_hs
+     
+                                JOIN clin.encounter c_enc 
+                                  ON (
+                                         (c_hs.fk_encounter = c_enc.pk)
+                                   )
+                             )
+     
+                          JOIN clin.encounter_type c_ety 
+                            ON (
+                                   (c_enc.fk_type = c_ety.pk)
+                             )
+                       )
+     
+                    JOIN clin.episode c_epi 
+                      ON (
+                             (c_hs.fk_episode = c_epi.pk)
+                       )
+                 )
+     
+         LEFT JOIN clin.health_issue c_hi 
+                ON (
+                       (c_epi.fk_health_issue = c_hi.pk)
+                 )
+           )
+     
+   LEFT JOIN dem.org_unit d_ou 
+          ON (
+                 (d_ou.pk = c_hs.fk_org_unit)
+           )
+     )
+     
+LEFT JOIN dem.org d_o 
+    ON (
+           (d_o.pk = d_ou.fk_org)
+     )
+)
+  
+WHERE (
+     (c_hs.discharge IS NOT NULL)
+   AND (to_char
+           (c_hs.clin_when
+                 ,'YYYYMMDD'::text
+           ) <> to_char
+           (c_hs.discharge
+                 ,'YYYYMMDD'::text
+           )
+     )
+);</pre>
+	
 
 	<!-- List off permissions -->
 	
@@ -62856,17 +76859,15 @@ IT WILL BE WRONG.
     </p>
 	
         <hr>
-		<h2>Table:
+		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.table.test-type">test_type</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-hospital-stays-journal-multi-day-dis">v_hospital_stays_journal_multi_day_dis</a>
 		</h2>
         
-         <p>measurement type, like a "method" in a lab</p>
-        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.test_type Structure</caption>
+                <caption>clin.v_hospital_stays_journal_multi_day_dis Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -62878,35 +76879,19 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
+            	<td>pk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>row_version</td>
-            	<td>integer</td>
-                <td><i>
 				
-
-				NOT NULL
 				
 				</i>
 				
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -62915,24 +76900,8 @@ IT WILL BE WRONG.
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
-				</i>
 				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>modified_by</td>
-            	<td>name</td>
-                <td><i>
 				
-
-				NOT NULL
-				DEFAULT "current_user"()
 				</i>
 				
 				</td>
@@ -62941,18 +76910,11 @@ IT WILL BE WRONG.
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>pk</td>
-            	<td>serial</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -62964,82 +76926,16 @@ IT WILL BE WRONG.
             <tr class="tr1">
 				<td>
                 
-                  
-                
-                  
-                
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.test-org">clin.test_org.pk</a>
-                  
-                
-                </td>
-            	<td>fk_test_org</td>
-            	<td>integer</td>
-                <td><i>
-				
-					
-
-					
-                       UNIQUE#2
-                    
-				
-					
-
-					
-                       UNIQUE#1
-                    
-				
-					
-
-					
-				
-
-				NOT NULL
-				
-				</i>
-				<br><br>organisation carrying out this type of measurement, eg. a particular lab
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                  
-                
                 </td>
-            	<td>name</td>
+            	<td>modified_by</td>
             	<td>text</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>descriptive name of this measurement type,
-	 HL7: OBX.observation_identifier
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>comment</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
 				
-				</i>
-				<br><br>arbitrary comment on this type of measurement/test such
-	 as "outdated" or "only reliable when ..."
 				</td>
 			 </tr>
             
@@ -63047,7 +76943,7 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>reference_unit</td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -63055,7 +76951,7 @@ IT WILL BE WRONG.
 				
 				
 				</i>
-				<br><br>The chosen reference unit for this test type, preferably SI, used for comparing results delivered in differing units. This does not relate to what unit the test provider delivers results in but rather the unit we think those results need to be converted to in order to be comparable to OTHER results.
+				
 				</td>
 			 </tr>
             
@@ -63063,7 +76959,7 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>loinc</td>
+            	<td>narrative</td>
             	<td>text</td>
                 <td><i>
 				
@@ -63078,130 +76974,40 @@ IT WILL BE WRONG.
             <tr class="tr0">
 				<td>
                 
-                  
-                
-                </td>
-            	<td>abbrev</td>
-            	<td>text</td>
-                <td><i>
-				
-					
-
-					
-                       UNIQUE#2
-                    
-				
-
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                  
-                  <a href="gnumed-entire_schema.html#clin.table.meta-test-type">clin.meta_test_type.pk</a>
-                  
-                
                 </td>
-            	<td>fk_meta_test_type</td>
+            	<td>pk_encounter</td>
             	<td>integer</td>
-                <td><i>
-				
-					
-
-					
-				
-
-				
-				
-				</i>
-				<br><br>Link to the meta test type (if any) this test type is to be aggregated under.
-				</td>
-			 </tr>
-            
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table clin.test_type Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.lnk-tst2norm">clin.lnk_tst2norm</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.test-result">clin.test_result</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#de-de.table.lab-test-gnr">de_de.lab_test_gnr</a></li>
-			</ul>
-		
-		
-
-    <!-- Indexes -->
-    
-       idx_test_type_fk_meta_test_type fk_meta_test_type
-    
-       idx_test_type_fk_test_org fk_test_org
-    
-       idx_test_type_loinc loinc
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-brand-intakes">v_brand_intakes</a>
-		</h2>
-        
+                <td><i>
+				
 
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
 
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_brand_intakes Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_substance_intake</td>
+            	<td>pk_health_issue</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -63217,7 +77023,7 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
+            	<td>src_pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -63233,7 +77039,7 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
+            	<td>src_table</td>
             	<td>text</td>
                 <td><i>
 				
@@ -63249,8 +77055,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>brand</td>
-            	<td>text</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -63265,7 +77071,7 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>preparation</td>
+            	<td>health_issue</td>
             	<td>text</td>
                 <td><i>
 				
@@ -63281,8 +77087,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>substance</td>
-            	<td>text</td>
+            	<td>issue_laterality</td>
+            	<td>character varying(2)</td>
                 <td><i>
 				
 
@@ -63297,8 +77103,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>amount</td>
-            	<td>numeric</td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -63313,8 +77119,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>unit</td>
-            	<td>text</td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -63329,8 +77135,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>atc_substance</td>
-            	<td>text</td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -63345,7 +77151,7 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>atc_brand</td>
+            	<td>episode</td>
             	<td>text</td>
                 <td><i>
 				
@@ -63361,8 +77167,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>external_code_brand</td>
-            	<td>text</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -63377,8 +77183,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>external_code_type_brand</td>
-            	<td>text</td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -63393,7 +77199,7 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>started</td>
+            	<td>encounter_last_affirmed</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
@@ -63409,8 +77215,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>intake_is_approved_of</td>
-            	<td>boolean</td>
+            	<td>encounter_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -63425,7 +77231,7 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>schedule</td>
+            	<td>encounter_l10n_type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -63437,12 +77243,207 @@ IT WILL BE WRONG.
 				</td>
 			 </tr>
             
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT c_enc.fk_patient AS pk_patient
+,
+    c_hs.modified_when
+,
+    c_hs.discharge AS clin_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_hs.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (c_hs.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    c_hs.soap_cat
+,
+    
+(
+     (
+           (
+                 (
+                       (_
+                             ('discharged from'::text) || ' "'::text
+                       ) || d_ou.description
+                 ) || ' @ '::text
+           ) || d_o.description
+     ) || '"'::text
+) AS narrative
+,
+    c_hs.fk_encounter AS pk_encounter
+,
+    c_hs.fk_episode AS pk_episode
+,
+    
+(
+SELECT episode.fk_health_issue
+           
+  FROM clin.episode
+          
+ WHERE (episode.pk = c_hs.fk_episode)
+) AS pk_health_issue
+,
+    c_hs.pk AS src_pk
+,
+    'clin.hospital_stay'::text AS src_table
+,
+    c_hs.row_version
+,
+    c_hi.description AS health_issue
+,
+    c_hi.laterality AS issue_laterality
+,
+    c_hi.is_active AS issue_active
+,
+    c_hi.clinically_relevant AS issue_clinically_relevant
+,
+    c_hi.is_confidential AS issue_confidential
+,
+    c_epi.description AS episode
+,
+    c_epi.is_open AS episode_open
+,
+    c_enc.started AS encounter_started
+,
+    c_enc.last_affirmed AS encounter_last_affirmed
+,
+    c_ety.description AS encounter_type
+,
+    _
+(c_ety.description) AS encounter_l10n_type
+   
+FROM (
+     (
+           (
+                 (
+                       (
+                             (clin.hospital_stay c_hs
+     
+                                JOIN clin.encounter c_enc 
+                                  ON (
+                                         (c_hs.fk_encounter = c_enc.pk)
+                                   )
+                             )
+     
+                          JOIN clin.encounter_type c_ety 
+                            ON (
+                                   (c_enc.fk_type = c_ety.pk)
+                             )
+                       )
+     
+                    JOIN clin.episode c_epi 
+                      ON (
+                             (c_hs.fk_episode = c_epi.pk)
+                       )
+                 )
+     
+         LEFT JOIN clin.health_issue c_hi 
+                ON (
+                       (c_epi.fk_health_issue = c_hi.pk)
+                 )
+           )
+     
+   LEFT JOIN dem.org_unit d_ou 
+          ON (
+                 (d_ou.pk = c_hs.fk_org_unit)
+           )
+     )
+     
+LEFT JOIN dem.org d_o 
+    ON (
+           (d_o.pk = d_ou.fk_org)
+     )
+)
+  
+WHERE (
+     (c_hs.discharge IS NOT NULL)
+   AND (to_char
+           (c_hs.clin_when
+                 ,'YYYYMMDD'::text
+           ) <> to_char
+           (c_hs.discharge
+                 ,'YYYYMMDD'::text
+           )
+     )
+);</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-hospital-stays-journal-no-discharge">v_hospital_stays_journal_no_discharge</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.v_hospital_stays_journal_no_discharge Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
             <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>duration</td>
-            	<td>interval</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -63457,7 +77458,7 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>discontinued</td>
+            	<td>clin_when</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
@@ -63473,7 +77474,7 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>discontinue_reason</td>
+            	<td>modified_by</td>
             	<td>text</td>
                 <td><i>
 				
@@ -63489,8 +77490,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>is_long_term</td>
-            	<td>boolean</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -63505,7 +77506,7 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>aim</td>
+            	<td>narrative</td>
             	<td>text</td>
                 <td><i>
 				
@@ -63521,8 +77522,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>episode</td>
-            	<td>text</td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -63537,8 +77538,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>health_issue</td>
-            	<td>text</td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -63553,8 +77554,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>notes</td>
-            	<td>text</td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -63569,8 +77570,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>fake_brand</td>
-            	<td>boolean</td>
+            	<td>src_pk</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -63585,8 +77586,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>is_currently_active</td>
-            	<td>boolean</td>
+            	<td>src_table</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -63601,8 +77602,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>seems_inactive</td>
-            	<td>boolean</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -63617,8 +77618,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>pk_brand</td>
-            	<td>integer</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -63633,8 +77634,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>pk_data_source</td>
-            	<td>integer</td>
+            	<td>issue_laterality</td>
+            	<td>character varying(2)</td>
                 <td><i>
 				
 
@@ -63649,8 +77650,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>pk_substance</td>
-            	<td>integer</td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -63665,8 +77666,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>pk_drug_component</td>
-            	<td>integer</td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -63681,8 +77682,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -63697,8 +77698,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>episode</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -63713,8 +77714,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
-            	<td>integer</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -63729,7 +77730,7 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
+            	<td>encounter_started</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
@@ -63745,8 +77746,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -63761,8 +77762,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>encounter_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -63777,8 +77778,8 @@ IT WILL BE WRONG.
 				<td>
                 
                 </td>
-            	<td>xmin_substance_intake</td>
-            	<td>xid</td>
+            	<td>encounter_l10n_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -63808,99 +77809,159 @@ IT WILL BE WRONG.
 	<!-- View Definition -->
 	
 	<pre>
-SELECT c_si.pk AS pk_substance_intake
-, (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
- WHERE (encounter.pk = c_si.fk_encounter)
-) AS pk_patient
-, c_si.soap_cat
-, r_bd.description AS brand
-, r_bd.preparation
-, r_cs.description AS substance
-, r_cs.amount
-, r_cs.unit
-, r_cs.atc_code AS atc_substance
-, r_bd.atc_code AS atc_brand
-, r_bd.external_code AS external_code_brand
-, r_bd.external_code_type AS external_code_type_brand
-, c_si.clin_when AS started
-, c_si.intake_is_approved_of
-, c_si.schedule
-, c_si.duration
-, c_si.discontinued
-, c_si.discontinue_reason
-, c_si.is_long_term
-, c_si.aim
-, cep.description AS episode
-, c_hi.description AS health_issue
-, c_si.narrative AS notes
-, r_bd.is_fake AS fake_brand
-, CASE WHEN 
-(c_si.discontinued IS NULL) THEN true ELSE false END AS is_currently_active
-, CASE WHEN 
-(c_si.discontinued IS NOT NULL) THEN true WHEN 
-(c_si.clin_when IS NULL) THEN CASE WHEN 
-(c_si.is_long_term IS TRUE) THEN false ELSE NULL::boolean END WHEN 
-(
-     (c_si.clin_when > now
-           ()
-     ) IS TRUE
-) THEN true WHEN 
+SELECT c_enc.fk_patient AS pk_patient
+,
+    c_hs.modified_when
+,
+    c_hs.clin_when
+,
+    COALESCE
 (
      (
-           (c_si.clin_when + c_si.duration) < now
-           ()
-     ) IS TRUE
-) THEN true WHEN 
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_hs.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (c_hs.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    c_hs.soap_cat
+,
+    
 (
      (
-           (c_si.clin_when + c_si.duration) > now
-           ()
-     ) IS TRUE
-) THEN false ELSE NULL::boolean END AS seems_inactive
-, r_ls2b.fk_brand AS pk_brand
-, r_bd.fk_data_source AS pk_data_source
-, r_ls2b.fk_substance AS pk_substance
-, r_ls2b.pk AS pk_drug_component
-, c_si.fk_encounter AS pk_encounter
-, c_si.fk_episode AS pk_episode
-, cep.fk_health_issue AS pk_health_issue
-, c_si.modified_when
-, c_si.modified_by
-, c_si.row_version
-, c_si.xmin AS xmin_substance_intake 
+           (
+                 (
+                       (
+                             (
+                                   (
+                                         (
+                                               (
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (
+                                                                             (_
+                                                                                   ('hospital stay'::text) || '
+'::text
+                                                                             ) || ' '::text
+                                                                       ) || _
+                                                                       ('admitted'::text)
+                                                                 ) || ': '::text
+                                                           ) || to_char
+                                                           (c_hs.clin_when
+                                                                 ,'YYYY-MM-DD'::text
+                                                           )
+                                                     ) || '
+'::text
+                                               ) || ' '::text
+                                         ) || _
+                                         ('hospital'::text)
+                                   ) || ': "'::text
+                             ) || d_ou.description
+                       ) || ' @ '::text
+                 ) || d_o.description
+           ) || '"'::text
+     ) || COALESCE
+     (
+           ('
+ '::text || c_hs.narrative)
+           ,''::text
+     )
+) AS narrative
+,
+    c_hs.fk_encounter AS pk_encounter
+,
+    c_hs.fk_episode AS pk_episode
+,
+    
+(
+SELECT episode.fk_health_issue
+           
+  FROM clin.episode
+          
+ WHERE (episode.pk = c_hs.fk_episode)
+) AS pk_health_issue
+,
+    c_hs.pk AS src_pk
+,
+    'clin.hospital_stay'::text AS src_table
+,
+    c_hs.row_version
+,
+    c_hi.description AS health_issue
+,
+    c_hi.laterality AS issue_laterality
+,
+    c_hi.is_active AS issue_active
+,
+    c_hi.clinically_relevant AS issue_clinically_relevant
+,
+    c_hi.is_confidential AS issue_confidential
+,
+    c_epi.description AS episode
+,
+    c_epi.is_open AS episode_open
+,
+    c_enc.started AS encounter_started
+,
+    c_enc.last_affirmed AS encounter_last_affirmed
+,
+    c_ety.description AS encounter_type
+,
+    _
+(c_ety.description) AS encounter_l10n_type
+   
 FROM (
      (
            (
                  (
-                       (clin.substance_intake c_si 
-                          JOIN ref.lnk_substance2brand r_ls2b 
+                       (
+                             (clin.hospital_stay c_hs
+     
+                                JOIN clin.encounter c_enc 
+                                  ON (
+                                         (c_hs.fk_encounter = c_enc.pk)
+                                   )
+                             )
+     
+                          JOIN clin.encounter_type c_ety 
                             ON (
-                                   (c_si.fk_drug_component = r_ls2b.pk)
+                                   (c_enc.fk_type = c_ety.pk)
                              )
                        )
-                    JOIN ref.branded_drug r_bd 
+     
+                    JOIN clin.episode c_epi 
                       ON (
-                             (r_ls2b.fk_brand = r_bd.pk)
+                             (c_hs.fk_episode = c_epi.pk)
                        )
                  )
-              JOIN ref.consumable_substance r_cs 
+     
+         LEFT JOIN clin.health_issue c_hi 
                 ON (
-                       (r_ls2b.fk_substance = r_cs.pk)
+                       (c_epi.fk_health_issue = c_hi.pk)
                  )
            )
-   LEFT JOIN clin.episode cep 
+     
+   LEFT JOIN dem.org_unit d_ou 
           ON (
-                 (c_si.fk_episode = cep.pk)
+                 (d_ou.pk = c_hs.fk_org_unit)
            )
      )
-LEFT JOIN clin.health_issue c_hi 
+     
+LEFT JOIN dem.org d_o 
     ON (
-           (c_hi.pk = cep.fk_health_issue)
+           (d_o.pk = d_ou.fk_org)
      )
 )
-WHERE (c_si.fk_drug_component IS NOT NULL);</pre>
+  
+WHERE (c_hs.discharge IS NULL);</pre>
 	
 
 	<!-- List off permissions -->
@@ -63914,18 +77975,13 @@ WHERE (c_si.fk_drug_component IS NOT NULL);</pre>
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-emr-journal">v_emr_journal</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-hospital-stays-journal-one-day">v_hospital_stays_journal_one_day</a>
 		</h2>
         
-         <p>Clinical patient data formatted into one string per
-	 clinical entity even if it constains several user-
-	 visible fields. Mainly useful for display as a simple
-	 EMR journal.</p>
-        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_emr_journal Structure</caption>
+                <caption>clin.v_hospital_stays_journal_one_day Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -64113,371 +78169,8 @@ WHERE (c_si.fk_drug_component IS NOT NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-(
-     (
-           (
-                 (
-                       (
-                             (
-                                   (
-                                         (
-                                               (
-                                                     (
-                                                           (
-                                                                 (
-                                                                       (
-                                                                        SELECT v_pat_narrative_journal.pk_patient
-                                                                             , v_pat_narrative_journal.modified_when
-                                                                             , v_pat_narrative_journal.clin_when
-                                                                             , v_pat_narrative_journal.modified_by
-                                                                             , v_pat_narrative_journal.soap_cat
-                                                                             , v_pat_narrative_journal.narrative
-                                                                             , v_pat_narrative_journal.pk_encounter
-                                                                             , v_pat_narrative_journal.pk_episode
-                                                                             , v_pat_narrative_journal.pk_health_issue
-                                                                             , v_pat_narrative_journal.src_pk
-                                                                             , v_pat_narrative_journal.src_table
-                                                                             , v_pat_narrative_journal.row_version 
-                                                                          FROM clin.v_pat_narrative_journal 
-                                                                     UNION ALLSELECT v_health_issues_journal.pk_patient
-                                                                             , v_health_issues_journal.modified_when
-                                                                             , v_health_issues_journal.clin_when
-                                                                             , v_health_issues_journal.modified_by
-                                                                             , v_health_issues_journal.soap_cat
-                                                                             , v_health_issues_journal.narrative
-                                                                             , v_health_issues_journal.pk_encounter
-                                                                             , v_health_issues_journal.pk_episode
-                                                                             , v_health_issues_journal.pk_health_issue
-                                                                             , v_health_issues_journal.src_pk
-                                                                             , v_health_issues_journal.src_table
-                                                                             , v_health_issues_journal.row_version 
-                                                                          FROM clin.v_health_issues_journal
-                                                                       )
-                                                               UNION ALLSELECT v_pat_encounters_journal.pk_patient
-                                                                       , v_pat_encounters_journal.modified_when
-                                                                       , v_pat_encounters_journal.clin_when
-                                                                       , v_pat_encounters_journal.modified_by
-                                                                       , v_pat_encounters_journal.soap_cat
-                                                                       , v_pat_encounters_journal.narrative
-                                                                       , v_pat_encounters_journal.pk_encounter
-                                                                       , v_pat_encounters_journal.pk_episode
-                                                                       , v_pat_encounters_journal.pk_health_issue
-                                                                       , v_pat_encounters_journal.src_pk
-                                                                       , v_pat_encounters_journal.src_table
-                                                                       , v_pat_encounters_journal.row_version 
-                                                                    FROM clin.v_pat_encounters_journal
-                                                                 )
-                                                         UNION ALLSELECT v_pat_episodes_journal.pk_patient
-                                                                 , v_pat_episodes_journal.modified_when
-                                                                 , v_pat_episodes_journal.clin_when
-                                                                 , v_pat_episodes_journal.modified_by
-                                                                 , v_pat_episodes_journal.soap_cat
-                                                                 , v_pat_episodes_journal.narrative
-                                                                 , v_pat_episodes_journal.pk_encounter
-                                                                 , v_pat_episodes_journal.pk_episode
-                                                                 , v_pat_episodes_journal.pk_health_issue
-                                                                 , v_pat_episodes_journal.src_pk
-                                                                 , v_pat_episodes_journal.src_table
-                                                                 , v_pat_episodes_journal.row_version 
-                                                              FROM clin.v_pat_episodes_journal
-                                                           )
-                                                   UNION ALLSELECT v_family_history_journal.pk_patient
-                                                           , v_family_history_journal.modified_when
-                                                           , v_family_history_journal.clin_when
-                                                           , v_family_history_journal.modified_by
-                                                           , v_family_history_journal.soap_cat
-                                                           , v_family_history_journal.narrative
-                                                           , v_family_history_journal.pk_encounter
-                                                           , v_family_history_journal.pk_episode
-                                                           , v_family_history_journal.pk_health_issue
-                                                           , v_family_history_journal.src_pk
-                                                           , v_family_history_journal.src_table
-                                                           , v_family_history_journal.row_version 
-                                                        FROM clin.v_family_history_journal
-                                                     )
-                                             UNION ALLSELECT v_pat_allergies_journal.pk_patient
-                                                     , v_pat_allergies_journal.modified_when
-                                                     , v_pat_allergies_journal.clin_when
-                                                     , v_pat_allergies_journal.modified_by
-                                                     , v_pat_allergies_journal.soap_cat
-                                                     , v_pat_allergies_journal.narrative
-                                                     , v_pat_allergies_journal.pk_encounter
-                                                     , v_pat_allergies_journal.pk_episode
-                                                     , v_pat_allergies_journal.pk_health_issue
-                                                     , v_pat_allergies_journal.src_pk
-                                                     , v_pat_allergies_journal.src_table
-                                                     , 0 AS row_version 
-                                                  FROM clin.v_pat_allergies_journal
-                                               )
-                                       UNION ALLSELECT v_pat_allergy_state_journal.pk_patient
-                                               , v_pat_allergy_state_journal.modified_when
-                                               , v_pat_allergy_state_journal.clin_when
-                                               , v_pat_allergy_state_journal.modified_by
-                                               , v_pat_allergy_state_journal.soap_cat
-                                               , v_pat_allergy_state_journal.narrative
-                                               , v_pat_allergy_state_journal.pk_encounter
-                                               , v_pat_allergy_state_journal.pk_episode
-                                               , v_pat_allergy_state_journal.pk_health_issue
-                                               , v_pat_allergy_state_journal.src_pk
-                                               , v_pat_allergy_state_journal.src_table
-                                               , v_pat_allergy_state_journal.row_version 
-                                            FROM clin.v_pat_allergy_state_journal
-                                         )
-                                 UNION ALLSELECT v_test_results_journal.pk_patient
-                                         , v_test_results_journal.modified_when
-                                         , v_test_results_journal.clin_when
-                                         , v_test_results_journal.modified_by
-                                         , v_test_results_journal.soap_cat
-                                         , v_test_results_journal.narrative
-                                         , v_test_results_journal.pk_encounter
-                                         , v_test_results_journal.pk_episode
-                                         , v_test_results_journal.pk_health_issue
-                                         , v_test_results_journal.src_pk
-                                         , v_test_results_journal.src_table
-                                         , v_test_results_journal.row_version 
-                                      FROM clin.v_test_results_journal
-                                   )
-                           UNION ALLSELECT v_hospital_stays_journal.pk_patient
-                                   , v_hospital_stays_journal.modified_when
-                                   , v_hospital_stays_journal.clin_when
-                                   , v_hospital_stays_journal.modified_by
-                                   , v_hospital_stays_journal.soap_cat
-                                   , v_hospital_stays_journal.narrative
-                                   , v_hospital_stays_journal.pk_encounter
-                                   , v_hospital_stays_journal.pk_episode
-                                   , v_hospital_stays_journal.pk_health_issue
-                                   , v_hospital_stays_journal.src_pk
-                                   , v_hospital_stays_journal.src_table
-                                   , v_hospital_stays_journal.row_version 
-                                FROM clin.v_hospital_stays_journal
-                             )
-                     UNION ALLSELECT v_doc_med_journal.pk_patient
-                             , v_doc_med_journal.modified_when
-                             , v_doc_med_journal.clin_when
-                             , v_doc_med_journal.modified_by
-                             , v_doc_med_journal.soap_cat
-                             , v_doc_med_journal.narrative
-                             , v_doc_med_journal.pk_encounter
-                             , v_doc_med_journal.pk_episode
-                             , v_doc_med_journal.pk_health_issue
-                             , v_doc_med_journal.src_pk
-                             , v_doc_med_journal.src_table
-                             , 0 AS row_version 
-                          FROM blobs.v_doc_med_journal
-                       )
-               UNION ALLSELECT v_pat_substance_intake_journal.pk_patient
-                       , v_pat_substance_intake_journal.modified_when
-                       , v_pat_substance_intake_journal.clin_when
-                       , v_pat_substance_intake_journal.modified_by
-                       , v_pat_substance_intake_journal.soap_cat
-                       , v_pat_substance_intake_journal.narrative
-                       , v_pat_substance_intake_journal.pk_encounter
-                       , v_pat_substance_intake_journal.pk_episode
-                       , v_pat_substance_intake_journal.pk_health_issue
-                       , v_pat_substance_intake_journal.src_pk
-                       , v_pat_substance_intake_journal.src_table
-                       , v_pat_substance_intake_journal.row_version 
-                    FROM clin.v_pat_substance_intake_journal
-                 )
-         UNION ALLSELECT v_procedures_journal.pk_patient
-                 , v_procedures_journal.modified_when
-                 , v_procedures_journal.clin_when
-                 , v_procedures_journal.modified_by
-                 , v_procedures_journal.soap_cat
-                 , v_procedures_journal.narrative
-                 , v_procedures_journal.pk_encounter
-                 , v_procedures_journal.pk_episode
-                 , v_procedures_journal.pk_health_issue
-                 , v_procedures_journal.src_pk
-                 , v_procedures_journal.src_table
-                 , v_procedures_journal.row_version 
-              FROM clin.v_procedures_journal
-           )
-   UNION ALLSELECT v_pat_vaccinations_journal.pk_patient
-           , v_pat_vaccinations_journal.modified_when
-           , v_pat_vaccinations_journal.clin_when
-           , v_pat_vaccinations_journal.modified_by
-           , v_pat_vaccinations_journal.soap_cat
-           , v_pat_vaccinations_journal.narrative
-           , v_pat_vaccinations_journal.pk_encounter
-           , v_pat_vaccinations_journal.pk_episode
-           , v_pat_vaccinations_journal.pk_health_issue
-           , v_pat_vaccinations_journal.src_pk
-           , v_pat_vaccinations_journal.src_table
-           , v_pat_vaccinations_journal.row_version 
-        FROM clin.v_pat_vaccinations_journal
-     )
-UNION ALLSELECT v_suppressed_hints_journal.pk_identity AS pk_patient
-     , v_suppressed_hints_journal.modified_when
-     , v_suppressed_hints_journal.clin_when
-     , v_suppressed_hints_journal.modified_by
-     , v_suppressed_hints_journal.soap_cat
-     , v_suppressed_hints_journal.narrative
-     , v_suppressed_hints_journal.fk_encounter AS pk_encounter
-     , v_suppressed_hints_journal.pk_episode
-     , v_suppressed_hints_journal.pk_health_issue
-     , v_suppressed_hints_journal.src_pk
-     , v_suppressed_hints_journal.src_table
-     , v_suppressed_hints_journal.row_version 
-  FROM clin.v_suppressed_hints_journal
-)
-UNION ALLSELECT v_external_care_journal.pk_patient
-, v_external_care_journal.modified_when
-, v_external_care_journal.clin_when
-, v_external_care_journal.modified_by
-, v_external_care_journal.soap_cat
-, v_external_care_journal.narrative
-, v_external_care_journal.pk_encounter
-, v_external_care_journal.pk_episode
-, v_external_care_journal.pk_health_issue
-, v_external_care_journal.src_pk
-, v_external_care_journal.src_table
-, v_external_care_journal.row_version 
-FROM clin.v_external_care_journal;</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-export-items">v_export_items</a>
-		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_export_items Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_export_item</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>pk_identity</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>created_by</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>created_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>designation</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>description</td>
-            	<td>text</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -64492,8 +78185,8 @@ FROM clin.v_external_care_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_doc_obj</td>
-            	<td>integer</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -64508,8 +78201,8 @@ FROM clin.v_external_care_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>md5_sum</td>
-            	<td>text</td>
+            	<td>issue_laterality</td>
+            	<td>character varying(2)</td>
                 <td><i>
 				
 
@@ -64524,8 +78217,8 @@ FROM clin.v_external_care_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>size</td>
-            	<td>integer</td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -64540,8 +78233,8 @@ FROM clin.v_external_care_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>filename</td>
-            	<td>text</td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -64556,8 +78249,8 @@ FROM clin.v_external_care_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>xmin_export_item</td>
-            	<td>xid</td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -64572,7 +78265,7 @@ FROM clin.v_external_care_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>title</td>
+            	<td>episode</td>
             	<td>text</td>
                 <td><i>
 				
@@ -64588,8 +78281,8 @@ FROM clin.v_external_care_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>firstnames</td>
-            	<td>text</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -64604,8 +78297,8 @@ FROM clin.v_external_care_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>lastnames</td>
-            	<td>text</td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -64620,8 +78313,8 @@ FROM clin.v_external_care_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>preferred</td>
-            	<td>text</td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -64636,7 +78329,7 @@ FROM clin.v_external_care_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>gender</td>
+            	<td>encounter_type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -64652,8 +78345,8 @@ FROM clin.v_external_care_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>dob</td>
-            	<td>timestamp with time zone</td>
+            	<td>encounter_l10n_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -64683,93 +78376,170 @@ FROM clin.v_external_care_journal;</pre>
 	<!-- View Definition -->
 	
 	<pre>
-SELECT inner_export_items.pk_export_item
-, inner_export_items.pk_identity
-, inner_export_items.created_by
-, inner_export_items.created_when
-, inner_export_items.designation
-, inner_export_items.description
-, inner_export_items.pk_doc_obj
-, inner_export_items.md5_sum
-, inner_export_items.size
-, inner_export_items.filename
-, inner_export_items.xmin_export_item
-, d_vp.title
-, d_vp.firstnames
-, d_vp.lastnames
-, d_vp.preferred
-, d_vp.gender
-, d_vp.dob 
-FROM (
+SELECT c_enc.fk_patient AS pk_patient
+,
+    c_hs.modified_when
+,
+    c_hs.clin_when
+,
+    COALESCE
+(
      (
-      SELECT c_ei.pk AS pk_export_item
-           , COALESCE
-           (c_ei.fk_identity
-                 , (
-                  SELECT encounter.fk_patient 
-                    FROM clin.encounter 
-                   WHERE (encounter.pk = 
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_hs.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (c_hs.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    c_hs.soap_cat
+,
+    
+(
+     (
+           (
+                 (
+                       (
                              (
-                              SELECT doc_med.fk_encounter 
-                                FROM blobs.doc_med 
-                               WHERE (doc_med.pk = 
+                                   (
                                          (
-                                          SELECT doc_obj.fk_doc 
-                                            FROM blobs.doc_obj 
-                                           WHERE (doc_obj.pk = c_ei.fk_doc_obj)
-                                         )
-                                   )
-                             )
-                       )
-                 )
-           ) AS pk_identity
-           , COALESCE
+                                               (
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (
+                                                                             (
+                                                                                   (_
+                                                                                         ('hospital stay'::text) || '
+'::text
+                                                                                   ) || ' '::text
+                                                                             ) || _
+                                                                             ('admitted/discharged'::text)
+                                                                       ) || ': '::text
+                                                                 ) || to_char
+                                                                 (c_hs.clin_when
+                                                                       ,'YYYY-MM-DD'::text
+                                                                 )
+                                                           ) || '
+'::text
+                                                     ) || ' '::text
+                                               ) || _
+                                               ('hospital'::text)
+                                         ) || ': "'::text
+                                   ) || d_ou.description
+                             ) || ' @ '::text
+                       ) || d_o.description
+                 ) || '"'::text
+           ) || '
+'::text
+     ) || COALESCE
+     (
+           ('
+ '::text || c_hs.narrative)
+           ,''::text
+     )
+) AS narrative
+,
+    c_hs.fk_encounter AS pk_encounter
+,
+    c_hs.fk_episode AS pk_episode
+,
+    
+(
+SELECT episode.fk_health_issue
+           
+  FROM clin.episode
+          
+ WHERE (episode.pk = c_hs.fk_episode)
+) AS pk_health_issue
+,
+    c_hs.pk AS src_pk
+,
+    'clin.hospital_stay'::text AS src_table
+,
+    c_hs.row_version
+,
+    c_hi.description AS health_issue
+,
+    c_hi.laterality AS issue_laterality
+,
+    c_hi.is_active AS issue_active
+,
+    c_hi.clinically_relevant AS issue_clinically_relevant
+,
+    c_hi.is_confidential AS issue_confidential
+,
+    c_epi.description AS episode
+,
+    c_epi.is_open AS episode_open
+,
+    c_enc.started AS encounter_started
+,
+    c_enc.last_affirmed AS encounter_last_affirmed
+,
+    c_ety.description AS encounter_type
+,
+    _
+(c_ety.description) AS encounter_l10n_type
+   
+FROM (
+     (
            (
                  (
-                  SELECT staff.short_alias 
-                    FROM dem.staff 
-                   WHERE (staff.db_user = c_ei.created_by)
-                 )
-                 , (c_ei.created_by)::text
-           ) AS created_by
-           , c_ei.created_when
-           , c_ei.designation
-           , c_ei.description
-           , c_ei.fk_doc_obj AS pk_doc_obj
-           , md5
-           (COALESCE
-                 (c_ei.data
-                       , COALESCE
                        (
-                             (
-                              SELECT b_do.data 
-                                FROM blobs.doc_obj b_do 
-                               WHERE (b_do.pk = c_ei.fk_doc_obj)
+                             (clin.hospital_stay c_hs
+     
+                                JOIN clin.encounter c_enc 
+                                  ON (
+                                         (c_hs.fk_encounter = c_enc.pk)
+                                   )
+                             )
+     
+                          JOIN clin.encounter_type c_ety 
+                            ON (
+                                   (c_enc.fk_type = c_ety.pk)
                              )
-                             ,'\x'::bytea
+                       )
+     
+                    JOIN clin.episode c_epi 
+                      ON (
+                             (c_hs.fk_episode = c_epi.pk)
                        )
                  )
-           ) AS md5_sum
-           , octet_length
-           (COALESCE
-                 (c_ei.data
-                       ,'\x'::bytea
-                 )
-           ) AS size
-           , COALESCE
-           (c_ei.filename
-                 , (
-                  SELECT b_do.filename 
-                    FROM blobs.doc_obj b_do 
-                   WHERE (b_do.pk = c_ei.fk_doc_obj)
+     
+         LEFT JOIN clin.health_issue c_hi 
+                ON (
+                       (c_epi.fk_health_issue = c_hi.pk)
                  )
-           ) AS filename
-           , c_ei.xmin AS xmin_export_item 
-        FROM clin.export_item c_ei
-     ) inner_export_items 
-  JOIN dem.v_persons d_vp 
+           )
+     
+   LEFT JOIN dem.org_unit d_ou 
+          ON (
+                 (d_ou.pk = c_hs.fk_org_unit)
+           )
+     )
+     
+LEFT JOIN dem.org d_o 
     ON (
-           (d_vp.pk_identity = inner_export_items.pk_identity)
+           (d_o.pk = d_ou.fk_org)
+     )
+)
+  
+WHERE (
+     (c_hs.discharge IS NOT NULL)
+   AND (to_char
+           (c_hs.clin_when
+                 ,'YYYYMMDD'::text
+           ) = to_char
+           (c_hs.discharge
+                 ,'YYYYMMDD'::text
+           )
      )
 );</pre>
 	
@@ -64785,13 +78555,15 @@ FROM (
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-external-care">v_external_care</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-incoming-data-unmatched">v_incoming_data_unmatched</a>
 		</h2>
         
+         <p>Shows incoming data but w/o the data field.</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_external_care Structure</caption>
+                <caption>clin.v_incoming_data_unmatched Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -64803,7 +78575,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_external_care</td>
+            	<td>pk_incoming_data_unmatched</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -64819,8 +78591,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_identity</td>
-            	<td>integer</td>
+            	<td>pk_patient_candidates</td>
+            	<td>integer[]</td>
                 <td><i>
 				
 
@@ -64835,7 +78607,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>issue</td>
+            	<td>firstnames</td>
             	<td>text</td>
                 <td><i>
 				
@@ -64851,7 +78623,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>provider</td>
+            	<td>lastnames</td>
             	<td>text</td>
                 <td><i>
 				
@@ -64867,8 +78639,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>unit</td>
-            	<td>text</td>
+            	<td>dob</td>
+            	<td>date</td>
                 <td><i>
 				
 
@@ -64883,7 +78655,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>organization</td>
+            	<td>gender</td>
             	<td>text</td>
                 <td><i>
 				
@@ -64899,7 +78671,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>comment</td>
+            	<td>postcode</td>
             	<td>text</td>
                 <td><i>
 				
@@ -64915,8 +78687,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
-            	<td>integer</td>
+            	<td>other_info</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -64931,8 +78703,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_org_unit</td>
-            	<td>integer</td>
+            	<td>request_id</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -64947,8 +78719,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>requestor</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -64963,8 +78735,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>xmin_external_care</td>
-            	<td>xid</td>
+            	<td>external_data_id</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -64979,8 +78751,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -64995,8 +78767,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>pk_identity_disambiguated</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -65011,7 +78783,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>row_version</td>
+            	<td>pk_provider_disambiguated</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -65023,97 +78795,12 @@ FROM (
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT c_ec.pk AS pk_external_care
-, (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
- WHERE (encounter.pk = c_ec.fk_encounter)
-) AS pk_identity
-, COALESCE
-(c_ec.issue
-     , c_hi.description
-) AS issue
-, c_ec.provider
-, d_ou.description AS unit
-, d_o.description AS organization
-, c_ec.comment
-, c_ec.fk_health_issue AS pk_health_issue
-, c_ec.fk_org_unit AS pk_org_unit
-, c_ec.fk_encounter AS pk_encounter
-, c_ec.xmin AS xmin_external_care
-, c_ec.modified_when
-, c_ec.modified_by
-, c_ec.row_version 
-FROM (
-     (
-           (clin.external_care c_ec 
-         LEFT JOIN clin.health_issue c_hi 
-                ON (
-                       (c_hi.pk = c_ec.fk_health_issue)
-                 )
-           )
-   LEFT JOIN dem.org_unit d_ou 
-          ON (
-                 (c_ec.fk_org_unit = d_ou.pk)
-           )
-     )
-LEFT JOIN dem.org d_o 
-    ON (
-           (d_ou.fk_org = d_o.pk)
-     )
-);</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-external-care-journal">v_external_care_journal</a>
-		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_external_care_journal Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>data_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -65128,8 +78815,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>md5_sum</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -65144,8 +78831,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>data_size</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -65160,8 +78847,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>xmin_incoming_data_unmatched</td>
+            	<td>xid</td>
                 <td><i>
 				
 
@@ -65172,75 +78859,98 @@ LEFT JOIN dem.org d_o
 				</td>
 			 </tr>
             
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
-                <td><i>
-				
+        </table>
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>narrative</td>
-            	<td>text</td>
-                <td><i>
-				
+        <!-- Inherits -->
+		
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
-                <td><i>
-				
+		
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
-                <td><i>
-				
+        <!-- Constraint List -->
+		
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT c_idu.pk AS pk_incoming_data_unmatched
+,
+    c_idu.fk_patient_candidates AS pk_patient_candidates
+,
+    c_idu.firstnames
+,
+    c_idu.lastnames
+,
+    c_idu.dob
+,
+    c_idu.gender
+,
+    c_idu.postcode
+,
+    c_idu.other_info
+,
+    c_idu.request_id
+,
+    c_idu.requestor
+,
+    c_idu.external_data_id
+,
+    c_idu.comment
+,
+    c_idu.fk_identity_disambiguated AS pk_identity_disambiguated
+,
+    c_idu.fk_provider_disambiguated AS pk_provider_disambiguated
+,
+    c_idu.type AS data_type
+,
+    md5
+(c_idu.data) AS md5_sum
+,
+    octet_length
+(c_idu.data) AS data_size
+,
+    c_idu.xmin AS xmin_incoming_data_unmatched
+   
+FROM clin.incoming_data_unmatched c_idu;</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-indications4vaccine">v_indications4vaccine</a>
+		</h2>
+        
+         <p>Denormalizes indications per vaccine.</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.v_indications4vaccine Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
+            	<td>pk_vaccine</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -65256,8 +78966,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>src_pk</td>
-            	<td>integer</td>
+            	<td>vaccine</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -65272,7 +78982,7 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>src_table</td>
+            	<td>preparation</td>
             	<td>text</td>
                 <td><i>
 				
@@ -65288,8 +78998,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>atc_code</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -65300,121 +79010,12 @@ LEFT JOIN dem.org d_o
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT c_vec.pk_identity AS pk_patient
-, c_vec.modified_when
-, c_vec.modified_when AS clin_when
-, c_vec.modified_by
-,'s'::text AS soap_cat
-, (
-     (
-           (
-                 (
-                       (
-                             (
-                                   (
-                                         (
-                                               (
-                                                     (
-                                                           (
-                                                                 (
-                                                                       (_
-                                                                             ('External care'::text) || COALESCE
-                                                                             (
-                                                                                   (
-                                                                                         (
-                                                                                               (' '::text || _
-                                                                                                     ('by'::text)
-                                                                                               ) || ' '::text
-                                                                                         ) || c_vec.provider
-                                                                                   )
-                                                                                   ,''::text
-                                                                             )
-                                                                       ) || ' @ '::text
-                                                                 ) || c_vec.unit
-                                                           ) || ' '::text
-                                                     ) || _
-                                                     ('of'::text)
-                                               ) || ' '::text
-                                         ) || c_vec.organization
-                                   ) || '
-'::text
-                             ) || _
-                             ('Issue:'::text)
-                       ) || ' '::text
-                 ) || c_vec.issue
-           ) || '
-'::text
-     ) || COALESCE
-     (
-           (
-                 (_
-                       ('Comment:'::text) || ' '::text
-                 ) || c_vec.comment
-           )
-           ,''::text
-     )
-) AS narrative
-, c_vec.pk_encounter
-, NULL::integer AS pk_episode
-, c_vec.pk_health_issue
-, c_vec.pk_external_care AS src_pk
-,'clin.v_external_care'::text AS src_table
-, c_vec.row_version 
-FROM clin.v_external_care c_vec;</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-family-history">v_family_history</a>
-		</h2>
-        
-         <p>family history denormalized</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_family_history Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_family_history</td>
-            	<td>integer</td>
+            	<td>is_fake_vaccine</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -65429,8 +79030,8 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>route_abbreviation</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -65445,7 +79046,7 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
+            	<td>route_description</td>
             	<td>text</td>
                 <td><i>
 				
@@ -65461,8 +79062,8 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>relation</td>
-            	<td>text</td>
+            	<td>is_live</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -65477,8 +79078,8 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>l10n_relation</td>
-            	<td>text</td>
+            	<td>min_age</td>
+            	<td>interval</td>
                 <td><i>
 				
 
@@ -65493,8 +79094,8 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>condition</td>
-            	<td>text</td>
+            	<td>max_age</td>
+            	<td>interval</td>
                 <td><i>
 				
 
@@ -65509,7 +79110,7 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>age_noted</td>
+            	<td>comment</td>
             	<td>text</td>
                 <td><i>
 				
@@ -65525,8 +79126,8 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>age_of_death</td>
-            	<td>interval</td>
+            	<td>indication</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -65541,8 +79142,8 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>contributed_to_death</td>
-            	<td>boolean</td>
+            	<td>l10n_indication</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -65557,8 +79158,8 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>atcs_single_indication</td>
+            	<td>text[]</td>
                 <td><i>
 				
 
@@ -65573,8 +79174,8 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>episode</td>
-            	<td>text</td>
+            	<td>atcs_combi_indication</td>
+            	<td>text[]</td>
                 <td><i>
 				
 
@@ -65589,8 +79190,8 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>when_known_to_patient</td>
-            	<td>timestamp with time zone</td>
+            	<td>external_code</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -65605,7 +79206,7 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>name_relative</td>
+            	<td>external_code_type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -65621,8 +79222,8 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>dob_relative</td>
-            	<td>timestamp with time zone</td>
+            	<td>indications</td>
+            	<td>text[]</td>
                 <td><i>
 				
 
@@ -65637,8 +79238,8 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>is_genetic_relative</td>
-            	<td>boolean</td>
+            	<td>l10n_indications</td>
+            	<td>text[]</td>
                 <td><i>
 				
 
@@ -65653,8 +79254,8 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>pk_indications</td>
+            	<td>integer[]</td>
                 <td><i>
 				
 
@@ -65669,7 +79270,7 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
+            	<td>pk_route</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -65685,7 +79286,7 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
+            	<td>pk_brand</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -65701,7 +79302,7 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_fhx_relation_type</td>
+            	<td>pk_data_source</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -65717,8 +79318,8 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_indication</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -65733,23 +79334,7 @@ FROM clin.v_external_care c_vec;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_generic_codes</td>
-            	<td>integer[]</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>xmin_family_history</td>
+            	<td>xmin_vaccine</td>
             	<td>xid</td>
                 <td><i>
 				
@@ -65780,54 +79365,127 @@ FROM clin.v_external_care c_vec;</pre>
 	<!-- View Definition -->
 	
 	<pre>
-SELECT c_fh.pk AS pk_family_history
-, cenc.fk_patient AS pk_patient
-, c_fh.soap_cat
-, c_fhrt.description AS relation
-, _
-(c_fhrt.description) AS l10n_relation
-, c_fh.narrative AS condition
-, c_fh.age_noted
-, c_fh.age_of_death
-, c_fh.contributed_to_death
-, c_fh.comment
-, cep.description AS episode
-, c_fh.clin_when AS when_known_to_patient
-, c_fh.name_relative
-, c_fh.dob_relative
-, c_fhrt.is_genetic AS is_genetic_relative
-, c_fh.fk_encounter AS pk_encounter
-, c_fh.fk_episode AS pk_episode
-, cep.fk_health_issue AS pk_health_issue
-, c_fhrt.pk AS pk_fhx_relation_type
-, c_fh.modified_when
-, COALESCE
+SELECT cv.pk AS pk_vaccine
+,
+    rbd.description AS vaccine
+,
+    rbd.preparation
+,
+    rbd.atc_code
+,
+    rbd.is_fake AS is_fake_vaccine
+,
+    cvr.abbreviation AS route_abbreviation
+,
+    cvr.description AS route_description
+,
+    cv.is_live
+,
+    cv.min_age
+,
+    cv.max_age
+,
+    cv.comment
+,
+    cvi.description AS indication
+,
+    _
+(cvi.description) AS l10n_indication
+,
+    cvi.atcs_single_indication
+,
+    cvi.atcs_combi_indication
+,
+    rbd.external_code
+,
+    rbd.external_code_type
+,
+    
 (
-     (
-      SELECT array_agg
-           (c_lc2fhx.fk_generic_code) AS array_agg 
-        FROM clin.lnk_code2fhx c_lc2fhx 
-       WHERE (c_lc2fhx.fk_item = c_fh.pk)
+SELECT array_agg
+     (cvi2.description) AS array_agg
+           
+  FROM (clin.lnk_vaccine2inds clv2i_2
+             
+        JOIN clin.vacc_indication cvi2 
+          ON (
+                 (clv2i_2.fk_indication = cvi2.id)
+           )
      )
-     , ARRAY[]::integer[]
-) AS pk_generic_codes
-, c_fh.xmin AS xmin_family_history 
+          
+ WHERE (clv2i_2.fk_vaccine = cv.pk)
+) AS indications
+,
+    
+(
+SELECT array_agg
+     (_
+           (cvi2.description)
+     ) AS array_agg
+           
+  FROM (clin.lnk_vaccine2inds clv2i_2
+             
+        JOIN clin.vacc_indication cvi2 
+          ON (
+                 (clv2i_2.fk_indication = cvi2.id)
+           )
+     )
+          
+ WHERE (clv2i_2.fk_vaccine = cv.pk)
+) AS l10n_indications
+,
+    
+(
+SELECT array_agg
+     (clv2i_2.fk_indication) AS array_agg
+           
+  FROM (clin.lnk_vaccine2inds clv2i_2
+             
+        JOIN clin.vacc_indication cvi2 
+          ON (
+                 (clv2i_2.fk_indication = cvi2.id)
+           )
+     )
+          
+ WHERE (clv2i_2.fk_vaccine = cv.pk)
+) AS pk_indications
+,
+    cv.id_route AS pk_route
+,
+    cv.fk_brand AS pk_brand
+,
+    rbd.fk_data_source AS pk_data_source
+,
+    cvi.id AS pk_indication
+,
+    cv.xmin AS xmin_vaccine
+   
 FROM (
      (
-           (clin.family_history c_fh 
-              JOIN clin.encounter cenc 
+           (
+                 (clin.vaccine cv
+     
+               LEFT JOIN clin.vacc_route cvr 
+                      ON (
+                             (cvr.id = cv.id_route)
+                       )
+                 )
+     
+              JOIN ref.branded_drug rbd 
                 ON (
-                       (c_fh.fk_encounter = cenc.pk)
+                       (rbd.pk = cv.fk_brand)
                  )
            )
-        JOIN clin.episode cep 
+     
+        JOIN clin.lnk_vaccine2inds clv2i 
           ON (
-                 (c_fh.fk_episode = cep.pk)
+                 (clv2i.fk_vaccine = cv.pk)
            )
      )
-LEFT JOIN clin.fhx_relation_type c_fhrt 
+     
+  JOIN clin.vacc_indication cvi 
     ON (
-           (c_fh.fk_relation_type = c_fhrt.pk)
+           (cvi.id = clv2i.fk_indication)
      )
 );</pre>
 	
@@ -65843,13 +79501,15 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-family-history-journal">v_family_history_journal</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-linked-codes">v_linked_codes</a>
 		</h2>
         
+         <p>Denormalized codes linked to EMR structures.</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_family_history_journal Structure</caption>
+                <caption>clin.v_linked_codes Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -65861,7 +79521,7 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
+            	<td>pk_item</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -65877,8 +79537,8 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>item_table</td>
+            	<td>regclass</td>
                 <td><i>
 				
 
@@ -65893,8 +79553,8 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>code</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -65909,7 +79569,7 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
+            	<td>base_code</td>
             	<td>text</td>
                 <td><i>
 				
@@ -65925,7 +79585,7 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
+            	<td>code_modifier</td>
             	<td>text</td>
                 <td><i>
 				
@@ -65941,7 +79601,7 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>narrative</td>
+            	<td>term</td>
             	<td>text</td>
                 <td><i>
 				
@@ -65957,8 +79617,8 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>name_long</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -65973,8 +79633,8 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>name_short</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -65989,8 +79649,8 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
-            	<td>integer</td>
+            	<td>version</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -66005,7 +79665,39 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>src_pk</td>
+            	<td>lang</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>code_table</td>
+            	<td>regclass</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_generic_code</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -66021,8 +79713,8 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>src_table</td>
-            	<td>text</td>
+            	<td>pk_data_source</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -66037,7 +79729,7 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>row_version</td>
+            	<td>pk_lnk_code2item</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -66068,154 +79760,53 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 	<!-- View Definition -->
 	
 	<pre>
-SELECT cenc.fk_patient AS pk_patient
-, c_fh.modified_when
-, c_fh.clin_when
-, COALESCE
-(
-     (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.db_user = c_fh.modified_by)
-     )
-     , (
-           ('<'::text || 
-                 (c_fh.modified_by)::text
-           ) || '>'::text
-     )
-) AS modified_by
-, c_fh.soap_cat
-, (
-     (
-           (
-                 (
-                       (
-                             (
-                                   (
-                                         (
-                                               (
-                                                     (
-                                                           (
-                                                                 (_
-                                                                       (c_fhrt.description) || COALESCE
-                                                                       (
-                                                                             (' @ '::text || c_fh.age_noted)
-                                                                             ,''::text
-                                                                       )
-                                                                 ) || ': '::text
-                                                           ) || c_fh.narrative
-                                                     ) || '
-'::text
-                                               ) || ' '::text
-                                         ) || CASE WHEN 
-                                         (c_fh.contributed_to_death IS TRUE) THEN 
-                                         (_
-                                               ('contributed to death'::text) || ' '::text
-                                         ) ELSE ''::text END
-                                   ) || COALESCE
-                                   (
-                                         ('@ '::text || 
-                                               (justify_interval
-                                                     (c_fh.age_of_death)
-                                               )::text
-                                         )
-                                         ,''::text
-                                   )
-                             ) || '
-'::text
-                       ) || COALESCE
-                       (
-                             (
-                                   (' '::text || c_fh.name_relative) || 
-                                 ','::text
-                             )
-                             ,''::text
-                       )
-                 ) || COALESCE
-                 (
-                       (' '::text || to_char
-                             (c_fh.dob_relative
-                                   ,'YYYY-MM-DD'::text
-                             )
-                       )
-                       ,''::text
-                 )
-           ) || COALESCE
-           (
-                 ('
- '::text || c_fh.comment)
-                 ,''::text
-           )
-     ) || COALESCE
-     (
-           (
-                 (';
-'::text || array_to_string
-                       (
-                             (
-                              SELECT array_agg
-                                   (
-                                         (
-                                               (
-                                                     (
-                                                           (
-                                                                 (
-                                                                       (
-                                                                             (
-                                                                                   (r_csr.code || 
-                                                                                      ' ('::text) || r_ds.name_short
-                                                                                   ) || ' - '::text
-                                                                             ) || r_ds.version
-                                                                       ) || ' - '::text
-                                                                 ) || r_ds.lang
-                                                           ) || 
-                                                 '): '::text
-                                               ) || r_csr.term
-                                         )
-                                   ) AS array_agg 
-                                FROM (
-                                         (clin.lnk_code2fhx c_lc2fhx 
-                                            JOIN ref.coding_system_root r_csr 
-                                              ON (
-                                                     (c_lc2fhx.fk_generic_code = r_csr.pk_coding_system)
-                                               )
-                                         )
-                                      JOIN ref.data_source r_ds 
-                                        ON (
-                                               (r_ds.pk = r_csr.fk_data_source)
-                                         )
-                                   )
-                               WHERE (c_lc2fhx.fk_item = c_fh.pk)
-                             )
-                             ,'; '::text
-                       )
-                 ) || ';'::text
-           )
+SELECT c_lc2ir.fk_item AS pk_item
+,
+    
+(c_lc2ir.tableoid)::regclass AS item_table
+,
+    
+(r_csr.code || COALESCE
+     (c_lc2ir.code_modifier
            ,''::text
      )
-) AS narrative
-, c_fh.fk_encounter AS pk_encounter
-, c_fh.fk_episode AS pk_episode
-, cep.fk_health_issue AS pk_health_issue
-, c_fh.pk AS src_pk
-,'clin.family_history'::text AS src_table
-, c_fh.row_version 
+) AS code
+,
+    r_csr.code AS base_code
+,
+    c_lc2ir.code_modifier
+,
+    r_csr.term
+,
+    r_ds.name_long
+,
+    r_ds.name_short
+,
+    r_ds.version
+,
+    r_ds.lang
+,
+    
+(r_csr.tableoid)::regclass AS code_table
+,
+    r_csr.pk_coding_system AS pk_generic_code
+,
+    r_csr.fk_data_source AS pk_data_source
+,
+    c_lc2ir.pk_lnk_code2item
+   
 FROM (
-     (
-           (clin.family_history c_fh 
-              JOIN clin.encounter cenc 
-                ON (
-                       (c_fh.fk_encounter = cenc.pk)
-                 )
-           )
-        JOIN clin.episode cep 
+     (clin.lnk_code2item_root c_lc2ir
+     
+        JOIN ref.coding_system_root r_csr 
           ON (
-                 (c_fh.fk_episode = cep.pk)
+                 (r_csr.pk_coding_system = c_lc2ir.fk_generic_code)
            )
      )
-LEFT JOIN clin.fhx_relation_type c_fhrt 
+     
+  JOIN ref.data_source r_ds 
     ON (
-           (c_fh.fk_relation_type = c_fhrt.pk)
+           (r_ds.pk = r_csr.fk_data_source)
      )
 );</pre>
 	
@@ -66231,13 +79822,15 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-health-issues">v_health_issues</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-lnk-vaccine2inds">v_lnk_vaccine2inds</a>
 		</h2>
         
+         <p>Denormalizes indications per vaccine.</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_health_issues Structure</caption>
+                <caption>clin.v_lnk_vaccine2inds Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -66249,7 +79842,7 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
+            	<td>pk_vaccine</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -66265,8 +79858,8 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
-            	<td>integer</td>
+            	<td>vaccine</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -66281,7 +79874,7 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>description</td>
+            	<td>preparation</td>
             	<td>text</td>
                 <td><i>
 				
@@ -66297,7 +79890,7 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>summary</td>
+            	<td>atc_code</td>
             	<td>text</td>
                 <td><i>
 				
@@ -66313,8 +79906,8 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>laterality</td>
-            	<td>character varying(2)</td>
+            	<td>is_fake_vaccine</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -66329,8 +79922,8 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>age_noted</td>
-            	<td>interval</td>
+            	<td>route_abbreviation</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -66345,8 +79938,8 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>is_active</td>
-            	<td>boolean</td>
+            	<td>route_description</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -66361,7 +79954,7 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>clinically_relevant</td>
+            	<td>is_live</td>
             	<td>boolean</td>
                 <td><i>
 				
@@ -66377,8 +79970,8 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>is_confidential</td>
-            	<td>boolean</td>
+            	<td>min_age</td>
+            	<td>interval</td>
                 <td><i>
 				
 
@@ -66393,8 +79986,8 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>is_cause_of_death</td>
-            	<td>boolean</td>
+            	<td>max_age</td>
+            	<td>interval</td>
                 <td><i>
 				
 
@@ -66409,8 +80002,8 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -66425,8 +80018,8 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>indication</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -66441,8 +80034,8 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>l10n_indication</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -66457,8 +80050,8 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>atcs_single_indication</td>
+            	<td>text[]</td>
                 <td><i>
 				
 
@@ -66473,8 +80066,8 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>grouping</td>
-            	<td>text</td>
+            	<td>atcs_combi_indication</td>
+            	<td>text[]</td>
                 <td><i>
 				
 
@@ -66489,7 +80082,7 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>diagnostic_certainty_classification</td>
+            	<td>external_code</td>
             	<td>text</td>
                 <td><i>
 				
@@ -66505,8 +80098,8 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>has_open_episode</td>
-            	<td>boolean</td>
+            	<td>external_code_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -66521,8 +80114,8 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>pk_generic_codes</td>
-            	<td>integer[]</td>
+            	<td>pk_route</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -66537,7 +80130,55 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 				<td>
                 
                 </td>
-            	<td>xmin_health_issue</td>
+            	<td>pk_brand</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_data_source</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_indication</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>xmin_vaccine</td>
             	<td>xid</td>
                 <td><i>
 				
@@ -66568,48 +80209,79 @@ LEFT JOIN clin.fhx_relation_type c_fhrt
 	<!-- View Definition -->
 	
 	<pre>
-SELECT (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
- WHERE (encounter.pk = c_hi.fk_encounter)
-) AS pk_patient
-, c_hi.pk AS pk_health_issue
-, c_hi.description
-, c_hi.summary
-, c_hi.laterality
-, c_hi.age_noted
-, c_hi.is_active
-, c_hi.clinically_relevant
-, c_hi.is_confidential
-, c_hi.is_cause_of_death
-, c_hi.fk_encounter AS pk_encounter
-, c_hi.modified_when
-, c_hi.modified_by
-, c_hi.row_version
-, c_hi.grouping
-, c_hi.diagnostic_certainty_classification
-, (EXISTS 
+SELECT cv.pk AS pk_vaccine
+,
+    rbd.description AS vaccine
+,
+    rbd.preparation
+,
+    rbd.atc_code
+,
+    rbd.is_fake AS is_fake_vaccine
+,
+    cvr.abbreviation AS route_abbreviation
+,
+    cvr.description AS route_description
+,
+    cv.is_live
+,
+    cv.min_age
+,
+    cv.max_age
+,
+    cv.comment
+,
+    cvi.description AS indication
+,
+    _
+(cvi.description) AS l10n_indication
+,
+    cvi.atcs_single_indication
+,
+    cvi.atcs_combi_indication
+,
+    rbd.external_code
+,
+    rbd.external_code_type
+,
+    cv.id_route AS pk_route
+,
+    cv.fk_brand AS pk_brand
+,
+    rbd.fk_data_source AS pk_data_source
+,
+    cvi.id AS pk_indication
+,
+    cv.xmin AS xmin_vaccine
+   
+FROM (
      (
-      SELECT 1 
-        FROM clin.episode c_ep 
-       WHERE (
-                 (c_ep.fk_health_issue = c_hi.pk)
-               AND (c_ep.is_open IS TRUE)
-           ) LIMIT 1
+           (
+                 (clin.vaccine cv
+     
+               LEFT JOIN clin.vacc_route cvr 
+                      ON (
+                             (cvr.id = cv.id_route)
+                       )
+                 )
+     
+              JOIN ref.branded_drug rbd 
+                ON (
+                       (rbd.pk = cv.fk_brand)
+                 )
+           )
+     
+        JOIN clin.lnk_vaccine2inds clv2i 
+          ON (
+                 (clv2i.fk_vaccine = cv.pk)
+           )
      )
-) AS has_open_episode
-, COALESCE
-(
-     (
-      SELECT array_agg
-           (c_lc2h.fk_generic_code) AS array_agg 
-        FROM clin.lnk_code2h_issue c_lc2h 
-       WHERE (c_lc2h.fk_item = c_hi.pk)
+     
+  JOIN clin.vacc_indication cvi 
+    ON (
+           (cvi.id = clv2i.fk_indication)
      )
-     , ARRAY[]::integer[]
-) AS pk_generic_codes
-, c_hi.xmin AS xmin_health_issue 
-FROM clin.health_issue c_hi;</pre>
+);</pre>
 	
 
 	<!-- List off permissions -->
@@ -66623,58 +80295,32 @@ FROM clin.health_issue c_hi;</pre>
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-health-issues-journal">v_health_issues_journal</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-most-recent-encounters">v_most_recent_encounters</a>
 		</h2>
         
+         <p>Lists the most recent encounters per patient. Logic of "most recent" 
+	is: for a patient: 
+	 1) select encounters with latest "last_affirmed",
+	 2) from those select encounters with latest "started"
+	 3) limit those to 1 if there are duplicates (same start and end of encounter!)</p>
+        
 
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_health_issues_journal Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.v_most_recent_encounters Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -66689,8 +80335,8 @@ FROM clin.health_issue c_hi;</pre>
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>text</td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -66705,7 +80351,7 @@ FROM clin.health_issue c_hi;</pre>
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
+            	<td>reason_for_encounter</td>
             	<td>text</td>
                 <td><i>
 				
@@ -66721,7 +80367,7 @@ FROM clin.health_issue c_hi;</pre>
 				<td>
                 
                 </td>
-            	<td>narrative</td>
+            	<td>assessment_of_encounter</td>
             	<td>text</td>
                 <td><i>
 				
@@ -66737,8 +80383,8 @@ FROM clin.health_issue c_hi;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -66753,8 +80399,8 @@ FROM clin.health_issue c_hi;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>l10n_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -66769,8 +80415,8 @@ FROM clin.health_issue c_hi;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
-            	<td>integer</td>
+            	<td>started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -66785,8 +80431,8 @@ FROM clin.health_issue c_hi;</pre>
 				<td>
                 
                 </td>
-            	<td>src_pk</td>
-            	<td>integer</td>
+            	<td>last_affirmed</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -66801,8 +80447,8 @@ FROM clin.health_issue c_hi;</pre>
 				<td>
                 
                 </td>
-            	<td>src_table</td>
-            	<td>text</td>
+            	<td>pk_type</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -66817,7 +80463,7 @@ FROM clin.health_issue c_hi;</pre>
 				<td>
                 
                 </td>
-            	<td>row_version</td>
+            	<td>pk_location</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -66848,175 +80494,52 @@ FROM clin.health_issue c_hi;</pre>
 	<!-- View Definition -->
 	
 	<pre>
-SELECT cenc.fk_patient AS pk_patient
-, chi.modified_when
-, COALESCE
-(
-     (
-      SELECT (identity.dob + chi.age_noted)
-        FROM dem.identity 
-       WHERE (identity.pk = 
-                 (
-                  SELECT encounter.fk_patient 
-                    FROM clin.encounter 
-                   WHERE (encounter.pk = chi.fk_encounter)
-                 )
-           )
-     )
-     , cenc.started
-) AS clin_when
-, COALESCE
-(
-     (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.db_user = chi.modified_by)
-     )
-     , (
-           ('<'::text || 
-                 (chi.modified_by)::text
-           ) || '>'::text
-     )
-) AS modified_by
-,'a'::text AS soap_cat
-, (
-     (
-           (
-                 (
-                       (
-                             (
-                                   (
-                                         (
-                                               (
-                                                     (
-                                                           (
-                                                                 (
-                                                                       (_
-                                                                             ('Health Issue'::text) || 
-                                                                          ' ('::text) || CASE WHEN chi.is_active THEN _
-                                                                             ('active'::text) ELSE _
-                                                                             ('inactive'::text) END
-                                                                       ) || 
-                                                                    ', '::text
-                                                                 ) || CASE WHEN chi.clinically_relevant THEN _
-                                                                 ('clinically relevant'::text) ELSE _
-                                                                 ('clinically not relevant'::text) END
-                                                           ) || COALESCE
-                                                           (
-                                                                 (
-                                                                    ', '::text || chi.diagnostic_certainty_classification
-                                                                 )
-                                                                 ,''::text
-                                                           )
-                                                     ) || 
-                                           '): '::text
-                                         ) || chi.description
-                                   ) || COALESCE
-                                   (
-                                         (
-                                               (
-                                                     (
-                                                           (';
-'::text || _
-                                                                 ('noted at age'::text)
-                                                           ) || ': '::text
-                                                     ) || 
-                                                     (chi.age_noted)::text
-                                               ) || ';
-'::text
-                                         )
-                                         ,';
-'::text
-                                   )
-                             ) || COALESCE
-                             (
-                                   (
-                                         (
-                                               (_
-                                                     ('Laterality'::text) || ': '::text
-                                               ) || 
-                                               (chi.laterality)::text
-                                         ) || ' / '::text
-                                   )
-                                   ,''::text
-                             )
-                       ) || CASE WHEN chi.is_confidential THEN 
-                       (_
-                             ('confidential'::text) || ' / '::text
-                       ) ELSE ''::text END
-                 ) || CASE WHEN chi.is_cause_of_death THEN _
-                 ('cause of death'::text) ELSE ''::text END
-           ) || COALESCE
-           (
-                 (
-                       (
-                             (';
-'::text || _
-                                   ('Summary'::text)
-                             ) || ':
-'::text
-                       ) || chi.summary
-                 )
-                 ,''::text
-           )
-     ) || COALESCE
-     (
+SELECT ce1.pk AS pk_encounter
+,
+    ce1.fk_patient AS pk_patient
+,
+    ce1.reason_for_encounter
+,
+    ce1.assessment_of_encounter
+,
+    et.description AS type
+,
+    _
+(et.description) AS l10n_type
+,
+    ce1.started
+,
+    ce1.last_affirmed
+,
+    ce1.fk_type AS pk_type
+,
+    ce1.fk_location AS pk_location
+   
+FROM clin.encounter ce1
+,
+    clin.encounter_type et
+  
+WHERE (
+     (ce1.fk_type = et.pk)
+   AND (ce1.started = 
            (
-                 (';
-'::text || array_to_string
+            SELECT max
+                 (ce2.started) AS max
+           
+              FROM clin.encounter ce2
+          
+             WHERE (ce2.last_affirmed = 
                        (
-                             (
-                              SELECT array_agg
-                                   (
-                                         (
-                                               (
-                                                     (
-                                                           (
-                                                                 (
-                                                                       (
-                                                                             (
-                                                                                   (r_csr.code || 
-                                                                                      ' ('::text) || r_ds.name_short
-                                                                                   ) || ' - '::text
-                                                                             ) || r_ds.version
-                                                                       ) || ' - '::text
-                                                                 ) || r_ds.lang
-                                                           ) || 
-                                                 '): '::text
-                                               ) || r_csr.term
-                                         )
-                                   ) AS array_agg 
-                                FROM (
-                                         (clin.lnk_code2h_issue c_lc2h 
-                                            JOIN ref.coding_system_root r_csr 
-                                              ON (
-                                                     (c_lc2h.fk_generic_code = r_csr.pk_coding_system)
-                                               )
-                                         )
-                                      JOIN ref.data_source r_ds 
-                                        ON (
-                                               (r_ds.pk = r_csr.fk_data_source)
-                                         )
-                                   )
-                               WHERE (c_lc2h.fk_item = chi.pk)
-                             )
-                             ,'; '::text
+                        SELECT max
+                             (ce3.last_affirmed) AS max
+                   
+                          FROM clin.encounter ce3
+                  
+                         WHERE (ce3.fk_patient = ce1.fk_patient)
                        )
-                 ) || ';'::text
+                 )
+         LIMIT 1
            )
-           ,''::text
-     )
-) AS narrative
-, chi.fk_encounter AS pk_encounter
-, (-1) AS pk_episode
-, chi.pk AS pk_health_issue
-, chi.pk AS src_pk
-,'clin.health_issue'::text AS src_table
-, chi.row_version 
-FROM (clin.health_issue chi 
-  JOIN clin.encounter cenc 
-    ON (
-           (chi.fk_encounter = cenc.pk)
      )
 );</pre>
 	
@@ -67032,13 +80555,15 @@ FROM (clin.health_issue chi
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-hospital-stays">v_hospital_stays</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-narrative">v_narrative</a>
 		</h2>
         
+         <p>patient narrative with denormalized context added</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_hospital_stays Structure</caption>
+                <caption>clin.v_narrative Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -67050,7 +80575,7 @@ FROM (clin.health_issue chi
 				<td>
                 
                 </td>
-            	<td>pk_hospital_stay</td>
+            	<td>pk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -67066,8 +80591,8 @@ FROM (clin.health_issue chi
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>date</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -67082,7 +80607,7 @@ FROM (clin.health_issue chi
 				<td>
                 
                 </td>
-            	<td>hospital</td>
+            	<td>modified_by</td>
             	<td>text</td>
                 <td><i>
 				
@@ -67098,7 +80623,7 @@ FROM (clin.health_issue chi
 				<td>
                 
                 </td>
-            	<td>ward</td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -67114,7 +80639,7 @@ FROM (clin.health_issue chi
 				<td>
                 
                 </td>
-            	<td>comment</td>
+            	<td>narrative</td>
             	<td>text</td>
                 <td><i>
 				
@@ -67130,8 +80655,8 @@ FROM (clin.health_issue chi
 				<td>
                 
                 </td>
-            	<td>admission</td>
-            	<td>timestamp with time zone</td>
+            	<td>episode</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -67146,8 +80671,8 @@ FROM (clin.health_issue chi
 				<td>
                 
                 </td>
-            	<td>discharge</td>
-            	<td>timestamp with time zone</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -67162,8 +80687,8 @@ FROM (clin.health_issue chi
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>pk_item</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -67178,8 +80703,8 @@ FROM (clin.health_issue chi
 				<td>
                 
                 </td>
-            	<td>episode</td>
-            	<td>text</td>
+            	<td>pk_narrative</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -67194,8 +80719,8 @@ FROM (clin.health_issue chi
 				<td>
                 
                 </td>
-            	<td>health_issue</td>
-            	<td>text</td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -67210,7 +80735,7 @@ FROM (clin.health_issue chi
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
+            	<td>pk_episode</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -67226,7 +80751,7 @@ FROM (clin.health_issue chi
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
+            	<td>pk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -67242,8 +80767,8 @@ FROM (clin.health_issue chi
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
-            	<td>integer</td>
+            	<td>xmin_clin_narrative</td>
+            	<td>xid</td>
                 <td><i>
 				
 
@@ -67258,8 +80783,8 @@ FROM (clin.health_issue chi
 				<td>
                 
                 </td>
-            	<td>pk_org_unit</td>
-            	<td>integer</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -67274,7 +80799,7 @@ FROM (clin.health_issue chi
 				<td>
                 
                 </td>
-            	<td>pk_org</td>
+            	<td>row_version</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -67290,8 +80815,8 @@ FROM (clin.health_issue chi
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -67306,8 +80831,8 @@ FROM (clin.health_issue chi
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>text</td>
+            	<td>modified_by_raw</td>
+            	<td>name</td>
                 <td><i>
 				
 
@@ -67322,24 +80847,8 @@ FROM (clin.health_issue chi
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>xmin_hospital_stay</td>
-            	<td>xid</td>
+            	<td>pk_generic_codes</td>
+            	<td>integer[]</td>
                 <td><i>
 				
 
@@ -67369,63 +80878,86 @@ FROM (clin.health_issue chi
 	<!-- View Definition -->
 	
 	<pre>
-SELECT c_hs.pk AS pk_hospital_stay
-, (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
- WHERE (encounter.pk = c_hs.fk_encounter)
-) AS pk_patient
-, d_o.description AS hospital
-, d_ou.description AS ward
-, c_hs.narrative AS comment
-, c_hs.clin_when AS admission
-, c_hs.discharge
-, c_hs.soap_cat
-, c_e.description AS episode
-, c_hi.description AS health_issue
-, c_hs.fk_encounter AS pk_encounter
-, c_hs.fk_episode AS pk_episode
-, c_hi.pk AS pk_health_issue
-, c_hs.fk_org_unit AS pk_org_unit
-, d_o.pk AS pk_org
-, c_hs.modified_when
-, COALESCE
+SELECT c_enc.fk_patient AS pk_patient
+,
+    c_n.clin_when AS date
+,
+    COALESCE
 (
      (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.db_user = c_hs.modified_by)
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_n.modified_by)
      )
      , (
            ('<'::text || 
-                 (c_hs.modified_by)::text
+                 (c_n.modified_by)::text
            ) || '>'::text
      )
 ) AS modified_by
-, c_hs.row_version
-, c_hs.xmin AS xmin_hospital_stay 
+,
+    c_n.soap_cat
+,
+    c_n.narrative
+,
+    c_epi.description AS episode
+,
+    c_hi.description AS health_issue
+,
+    c_n.pk_item
+,
+    c_n.pk AS pk_narrative
+,
+    c_epi.fk_health_issue AS pk_health_issue
+,
+    c_n.fk_episode AS pk_episode
+,
+    c_n.fk_encounter AS pk_encounter
+,
+    c_n.xmin AS xmin_clin_narrative
+,
+    c_n.modified_when
+,
+    c_n.row_version
+,
+    c_n.pk_audit
+,
+    c_n.modified_by AS modified_by_raw
+,
+    COALESCE
+(
+     (
+      SELECT array_agg
+           (c_lc2n.fk_generic_code) AS array_agg
+           
+        FROM clin.lnk_code2narrative c_lc2n
+          
+       WHERE (c_lc2n.fk_item = c_n.pk)
+     )
+     , ARRAY[]::integer[]
+) AS pk_generic_codes
+   
 FROM (
      (
-           (
-                 (clin.hospital_stay c_hs 
-               LEFT JOIN clin.episode c_e 
-                      ON (
-                             (c_e.pk = c_hs.fk_episode)
-                       )
-                 )
-         LEFT JOIN clin.health_issue c_hi 
+           (clin.clin_narrative c_n
+     
+         LEFT JOIN clin.encounter c_enc 
                 ON (
-                       (c_hi.pk = c_e.fk_health_issue)
+                       (c_n.fk_encounter = c_enc.pk)
                  )
            )
-   LEFT JOIN dem.org_unit d_ou 
+     
+   LEFT JOIN clin.episode c_epi 
           ON (
-                 (d_ou.pk = c_hs.fk_org_unit)
+                 (c_n.fk_episode = c_epi.pk)
            )
      )
-LEFT JOIN dem.org d_o 
+     
+LEFT JOIN clin.health_issue c_hi 
     ON (
-           (d_o.pk = d_ou.fk_org)
+           (c_epi.fk_health_issue = c_hi.pk)
      )
 );</pre>
 	
@@ -67441,13 +80973,17 @@ LEFT JOIN dem.org d_o
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-hospital-stays-journal">v_hospital_stays_journal</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-narrative4search">v_narrative4search</a>
 		</h2>
         
+         <p>unformatted *complete* narrative for patients
+	 including health issue/episode/encounter descriptions,
+	 mainly for searching the narrative in context</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_hospital_stays_journal Structure</caption>
+                <caption>clin.v_narrative4search Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -67475,54 +81011,6 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>modified_by</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
             	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
@@ -67535,7 +81023,7 @@ LEFT JOIN dem.org d_o
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -67551,7 +81039,7 @@ LEFT JOIN dem.org d_o
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -67567,7 +81055,7 @@ LEFT JOIN dem.org d_o
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -67583,7 +81071,7 @@ LEFT JOIN dem.org d_o
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -67599,7 +81087,7 @@ LEFT JOIN dem.org d_o
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -67615,7 +81103,7 @@ LEFT JOIN dem.org d_o
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -67631,117 +81119,729 @@ LEFT JOIN dem.org d_o
 				</td>
 			 </tr>
             
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>row_version</td>
-            	<td>integer</td>
-                <td><i>
-				
+        </table>
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT union_table.pk_patient
+,
+    union_table.soap_cat
+,
+    union_table.narrative
+,
+    union_table.pk_encounter
+,
+    union_table.pk_episode
+,
+    union_table.pk_health_issue
+,
+    union_table.src_pk
+,
+    union_table.src_table
+   
+FROM (
+SELECT vpi.pk_patient
+     ,
+            vpi.soap_cat
+     ,
+            vpi.narrative
+     ,
+            vpi.pk_encounter
+     ,
+            vpi.pk_episode
+     ,
+            vpi.pk_health_issue
+     ,
+            vpi.pk_item AS src_pk
+     ,
+            vpi.src_table
+           
+  FROM clin.v_pat_items vpi
+          
+ WHERE (vpi.src_table <> ALL 
+           (ARRAY['clin.allergy'::text
+                 ,'clin.test_result'::text
+                 ,'clin.procedure'::text
+                 ,'clin.substance_intake'::text
+                 ,'clin.family_history'::text]
+           )
+     )
+        
+UNION ALL
+         
+SELECT v_subst_intake4narr_search.pk_patient
+     ,
+            v_subst_intake4narr_search.soap_cat
+     ,
+            v_subst_intake4narr_search.narrative
+     ,
+            v_subst_intake4narr_search.pk_encounter
+     ,
+            v_subst_intake4narr_search.pk_episode
+     ,
+            v_subst_intake4narr_search.pk_health_issue
+     ,
+            v_subst_intake4narr_search.src_pk
+     ,
+            v_subst_intake4narr_search.src_table
+           
+  FROM clin.v_subst_intake4narr_search
+          
+ WHERE (gm.is_null_or_blank_string
+           (v_subst_intake4narr_search.narrative) IS FALSE
+     )
+        
+UNION ALL
+         
+SELECT (
+      SELECT encounter.fk_patient
+                   
+        FROM clin.encounter
+                  
+       WHERE (encounter.pk = cpr.fk_encounter)
+     ) AS pk_patient
+     ,
+            cpr.soap_cat
+     ,
+            cpr.narrative
+     ,
+            cpr.fk_encounter AS pk_encounter
+     ,
+            cpr.fk_episode AS pk_episode
+     ,
+            
+     (
+      SELECT episode.fk_health_issue
+                   
+        FROM clin.episode
+                  
+       WHERE (episode.pk = cpr.fk_episode)
+     ) AS pk_health_issue
+     ,
+            cpr.pk AS src_pk
+     ,
+            'clin.procedure'::text AS src_table
+           
+  FROM clin.procedure cpr
+          
+ WHERE (cpr.narrative IS NOT NULL)
+        
+UNION ALL
+         
+SELECT (
+      SELECT encounter.fk_patient
+                   
+        FROM clin.encounter
+                  
+       WHERE (encounter.pk = ctr.fk_encounter)
+     ) AS pk_patient
+     ,
+            ctr.soap_cat
+     ,
+            
+     (
+           (
+                 (
+                       (
+                             (
+                                   (
+                                         (
+                                               (COALESCE
+                                                     (ctr.narrative
+                                                           ,''::text
+                                                     ) || COALESCE
+                                                     (
+                                                           (' '::text || ctr.val_alpha)
+                                                           ,''::text
+                                                     )
+                                               ) || COALESCE
+                                               (
+                                                     (' '::text || ctr.val_unit)
+                                                     ,''::text
+                                               )
+                                         ) || COALESCE
+                                         (
+                                               (' '::text || ctr.val_normal_range)
+                                               ,''::text
+                                         )
+                                   ) || COALESCE
+                                   (
+                                         (' '::text || ctr.val_target_range)
+                                         ,''::text
+                                   )
+                             ) || COALESCE
+                             (
+                                   (' '::text || ctr.norm_ref_group)
+                                   ,''::text
+                             )
+                       ) || COALESCE
+                       (
+                             (' '::text || ctr.note_test_org)
+                             ,''::text
+                       )
+                 ) || COALESCE
+                 (
+                       (' '::text || ctr.material)
+                       ,''::text
+                 )
+           ) || COALESCE
+           (
+                 (' '::text || ctr.material_detail)
+                 ,''::text
+           )
+     ) AS narrative
+     ,
+            ctr.fk_encounter AS pk_encounter
+     ,
+            ctr.fk_episode AS pk_episode
+     ,
+            
+     (
+      SELECT episode.fk_health_issue
+                   
+        FROM clin.episode
+                  
+       WHERE (episode.pk = ctr.fk_episode)
+     ) AS pk_health_issue
+     ,
+            ctr.pk AS src_pk
+     ,
+            'clin.test_result'::text AS src_table
+           
+  FROM clin.test_result ctr
+        
+UNION ALL
+         
+SELECT (
+      SELECT encounter.fk_patient
+                   
+        FROM clin.encounter
+                  
+       WHERE (encounter.pk = 
+                 (
+                  SELECT test_result.fk_encounter
+                           
+                    FROM clin.test_result
+                          
+                   WHERE (test_result.pk = crtr.fk_reviewed_row)
+                 )
+           )
+     ) AS pk_patient
+     ,
+            'o'::text AS soap_cat
+     ,
+            crtr.comment AS narrative
+     ,
+            
+     (
+      SELECT test_result.fk_encounter
+                   
+        FROM clin.test_result
+                  
+       WHERE (test_result.pk = crtr.fk_reviewed_row)
+     ) AS pk_encounter
+     ,
+            
+     (
+      SELECT test_result.fk_episode
+                   
+        FROM clin.test_result
+                  
+       WHERE (test_result.pk = crtr.fk_reviewed_row)
+     ) AS pk_episode
+     ,
+            
+     (
+      SELECT episode.fk_health_issue
+                   
+        FROM clin.episode
+                  
+       WHERE (episode.pk = 
+                 (
+                  SELECT test_result.fk_episode
+                           
+                    FROM clin.test_result
+                          
+                   WHERE (test_result.pk = crtr.fk_reviewed_row)
+                 )
+           )
+     ) AS pk_health_issue
+     ,
+            crtr.pk AS src_pk
+     ,
+            'clin.reviewed_test_results'::text AS src_table
+           
+  FROM clin.reviewed_test_results crtr
+        
+UNION ALL
+         
+SELECT (
+      SELECT encounter.fk_patient
+                   
+        FROM clin.encounter
+                  
+       WHERE (encounter.pk = cas.fk_encounter)
+     ) AS pk_patient
+     ,
+            'o'::text AS soap_cat
+     ,
+            cas.comment AS narrative
+     ,
+            cas.fk_encounter AS pk_encounter
+     ,
+            NULL::integer AS pk_episode
+     ,
+            NULL::integer AS pk_health_issue
+     ,
+            cas.pk AS src_pk
+     ,
+            'clin.allergy_state'::text AS src_table
+           
+  FROM clin.allergy_state cas
+          
+ WHERE (cas.comment IS NOT NULL)
+        
+UNION ALL
+         
+SELECT (
+      SELECT encounter.fk_patient
+                   
+        FROM clin.encounter
+                  
+       WHERE (encounter.pk = ca.fk_encounter)
+     ) AS pk_patient
+     ,
+            ca.soap_cat
+     ,
+            
+     (
+           (
+                 (
+                       (
+                             (COALESCE
+                                   (ca.narrative
+                                         ,''::text
+                                   ) || COALESCE
+                                   (
+                                         (' '::text || ca.substance)
+                                         ,''::text
+                                   )
+                             ) || COALESCE
+                             (
+                                   (' '::text || ca.substance_code)
+                                   ,''::text
+                             )
+                       ) || COALESCE
+                       (
+                             (' '::text || ca.generics)
+                             ,''::text
+                       )
+                 ) || COALESCE
+                 (
+                       (' '::text || ca.allergene)
+                       ,''::text
+                 )
+           ) || COALESCE
+           (
+                 (' '::text || ca.atc_code)
+                 ,''::text
+           )
+     ) AS narrative
+     ,
+            ca.fk_encounter AS pk_encounter
+     ,
+            ca.fk_episode AS pk_episode
+     ,
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
- WHERE (encounter.pk = c_hs.fk_encounter)
-) AS pk_patient
-, c_hs.modified_when
-, c_hs.clin_when
-, COALESCE
-(
      (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.db_user = c_hs.modified_by)
-     )
-     , (
-           ('<'::text || 
-                 (c_hs.modified_by)::text
-           ) || '>'::text
-     )
-) AS modified_by
-, c_hs.soap_cat
-, (
+      SELECT episode.fk_health_issue
+                   
+        FROM clin.episode
+                  
+       WHERE (episode.pk = ca.fk_episode)
+     ) AS pk_health_issue
+     ,
+            ca.pk AS src_pk
+     ,
+            'clin.allergy'::text AS src_table
+           
+  FROM clin.allergy ca
+        
+UNION ALL
+         
+SELECT (
+      SELECT encounter.fk_patient
+                   
+        FROM clin.encounter
+                  
+       WHERE (encounter.pk = chi.fk_encounter)
+     ) AS pk_patient
+     ,
+            'a'::text AS soap_cat
+     ,
+            
+     (chi.description || COALESCE
+           (
+                 (' '::text || chi.summary)
+                 ,''::text
+           )
+     ) AS narrative
+     ,
+            chi.fk_encounter AS pk_encounter
+     ,
+            NULL::integer AS pk_episode
+     ,
+            chi.pk AS pk_health_issue
+     ,
+            chi.pk AS src_pk
+     ,
+            'clin.health_issue'::text AS src_table
+           
+  FROM clin.health_issue chi
+        
+UNION ALL
+         
+SELECT cenc.fk_patient AS pk_patient
+     ,
+            's'::text AS soap_cat
+     ,
+            
+     (COALESCE
+           (cenc.reason_for_encounter
+                 ,''::text
+           ) || COALESCE
+           (
+                 (' '::text || cenc.assessment_of_encounter)
+                 ,''::text
+           )
+     ) AS narrative
+     ,
+            cenc.pk AS pk_encounter
+     ,
+            NULL::integer AS pk_episode
+     ,
+            NULL::integer AS pk_health_issue
+     ,
+            cenc.pk AS src_pk
+     ,
+            'clin.encounter'::text AS src_table
+           
+  FROM clin.encounter cenc
+        
+UNION ALL
+         
+SELECT (
+      SELECT encounter.fk_patient
+                   
+        FROM clin.encounter
+                  
+       WHERE (encounter.pk = cep.fk_encounter)
+     ) AS pk_patient
+     ,
+            's'::text AS soap_cat
+     ,
+            
+     (cep.description || COALESCE
+           (
+                 (' '::text || cep.summary)
+                 ,''::text
+           )
+     ) AS narrative
+     ,
+            cep.fk_encounter AS pk_encounter
+     ,
+            cep.pk AS pk_episode
+     ,
+            cep.fk_health_issue AS pk_health_issue
+     ,
+            cep.pk AS src_pk
+     ,
+            'clin.episode'::text AS src_table
+           
+  FROM clin.episode cep
+        
+UNION ALL
+         
+SELECT c_vfhx.pk_patient
+     ,
+            c_vfhx.soap_cat
+     ,
+            
      (
            (
                  (
                        (
                              (
-                                   (
-                                         (
-                                               (
-                                                     (_
-                                                           ('hospital stay'::text) || ': '::text
-                                                     ) || to_char
-                                                     (c_hs.clin_when
-                                                           ,'YYYY-MM-DD'::text
-                                                     )
-                                               ) || ' - '::text
-                                         ) || COALESCE
-                                         (to_char
-                                               (c_hs.discharge
-                                                     ,'YYYY-MM-DD'::text
-                                               )
-                                               ,'?'::text
-                                         )
-                                   ) || ' "'::text
-                             ) || d_ou.description
-                       ) || ' @ '::text
-                 ) || d_o.description
-           ) || '"'::text
-     ) || COALESCE
+                                   (c_vfhx.relation || ' / '::text) || c_vfhx.l10n_relation
+                             ) || ' '::text
+                       ) || c_vfhx.name_relative
+                 ) || ': '::text
+           ) || c_vfhx.condition
+     ) AS narrative
+     ,
+            c_vfhx.pk_encounter
+     ,
+            c_vfhx.pk_episode
+     ,
+            c_vfhx.pk_health_issue
+     ,
+            c_vfhx.pk_family_history AS src_pk
+     ,
+            'clin.family_history'::text AS src_table
+           
+  FROM clin.v_family_history c_vfhx
+        
+UNION ALL
+         
+SELECT vdm.pk_patient
+     ,
+            'o'::text AS soap_cat
+     ,
+            
      (
-           (' '::text || c_hs.narrative)
-           ,''::text
+           (
+                 (
+                       (vdm.l10n_type || ' '::text) || COALESCE
+                       (vdm.ext_ref
+                             ,''::text
+                       )
+                 ) || ' '::text
+           ) || COALESCE
+           (vdm.comment
+                 ,''::text
+           )
+     ) AS narrative
+     ,
+            vdm.pk_encounter
+     ,
+            vdm.pk_episode
+     ,
+            vdm.pk_health_issue
+     ,
+            vdm.pk_doc AS src_pk
+     ,
+            'blobs.doc_med'::text AS src_table
+           
+  FROM blobs.v_doc_med vdm
+        
+UNION ALL
+         
+SELECT vo4d.pk_patient
+     ,
+            'o'::text AS soap_cat
+     ,
+            vo4d.obj_comment AS narrative
+     ,
+            vo4d.pk_encounter
+     ,
+            vo4d.pk_episode
+     ,
+            vo4d.pk_health_issue
+     ,
+            vo4d.pk_obj AS src_pk
+     ,
+            'blobs.doc_obj'::text AS src_table
+           
+  FROM blobs.v_obj4doc_no_data vo4d
+        
+UNION ALL
+         
+SELECT vdd.pk_patient
+     ,
+            'o'::text AS soap_cat
+     ,
+            vdd.description AS narrative
+     ,
+            vdd.pk_encounter
+     ,
+            vdd.pk_episode
+     ,
+            vdd.pk_health_issue
+     ,
+            vdd.pk_doc_desc AS src_pk
+     ,
+            'blobs.doc_desc'::text AS src_table
+           
+  FROM blobs.v_doc_desc vdd
+        
+UNION ALL
+         
+SELECT vrdo.pk_patient
+     ,
+            's'::text AS soap_cat
+     ,
+            vrdo.comment AS narrative
+     ,
+            NULL::integer AS pk_encounter
+     ,
+            vrdo.pk_episode
+     ,
+            vrdo.pk_health_issue
+     ,
+            vrdo.pk_review_root AS src_pk
+     ,
+            'blobs.v_reviewed_doc_objects'::text AS src_table
+           
+  FROM blobs.v_reviewed_doc_objects vrdo
+        
+UNION ALL
+         
+SELECT d_vit.pk_identity AS pk_patient
+     ,
+            's'::text AS soap_cat
+     ,
+            
+     (d_vit.l10n_description || COALESCE
+           (
+                 (' '::text || d_vit.comment)
+                 ,''::text
+           )
+     ) AS narrative
+     ,
+            NULL::integer AS pk_encounter
+     ,
+            NULL::integer AS pk_episode
+     ,
+            NULL::integer AS pk_health_issue
+     ,
+            d_vit.pk_identity_tag AS src_pk
+     ,
+            'dem.v_identity_tags'::text AS src_table
+           
+  FROM dem.v_identity_tags d_vit
+        
+UNION ALL
+         
+SELECT c_vec.pk_identity AS pk_patient
+     ,
+            's'::text AS soap_cat
+     ,
+                CASE
+                    WHEN 
+     (c_vec.pk_health_issue IS NULL) THEN 
+     (
+           (COALESCE
+                 (c_vec.issue
+                       ,''::text
+                 ) || COALESCE
+                 (
+                       (' / '::text || c_vec.provider)
+                       ,''::text
+                 )
+           ) || COALESCE
+           (
+                 (' / '::text || c_vec.comment)
+                 ,''::text
+           )
      )
-) AS narrative
-, c_hs.fk_encounter AS pk_encounter
-, c_hs.fk_episode AS pk_episode
-, (
-SELECT episode.fk_health_issue 
-  FROM clin.episode 
- WHERE (episode.pk = c_hs.fk_episode)
-) AS pk_health_issue
-, c_hs.pk AS src_pk
-,'clin.hospital_stay'::text AS src_table
-, c_hs.row_version 
-FROM (
-     (clin.hospital_stay c_hs 
-   LEFT JOIN dem.org_unit d_ou 
-          ON (
-                 (d_ou.pk = c_hs.fk_org_unit)
+                    ELSE 
+     (COALESCE
+           (c_vec.provider
+                 ,''::text
+           ) || COALESCE
+           (
+                 (' / '::text || c_vec.comment)
+                 ,''::text
            )
      )
-LEFT JOIN dem.org d_o 
-    ON (
-           (d_o.pk = d_ou.fk_org)
+                END AS narrative
+     ,
+            c_vec.pk_encounter
+     ,
+            NULL::integer AS pk_episode
+     ,
+            c_vec.pk_health_issue
+     ,
+            c_vec.pk_external_care AS src_pk
+     ,
+            'clin.v_external_care'::text AS src_table
+           
+  FROM clin.v_external_care c_vec
+        
+UNION ALL
+         
+SELECT c_vei.pk_identity AS pk_patient
+     ,
+            's'::text AS soap_cat
+     ,
+                CASE
+                    WHEN 
+     (c_vei.pk_doc_obj IS NULL) THEN 
+     (COALESCE
+           (c_vei.description
+                 ,''::text
+           ) || COALESCE
+           (
+                 (' / '::text || c_vei.filename)
+                 ,''::text
+           )
+     )
+                    ELSE COALESCE
+     (c_vei.description
+           ,''::text
      )
+                END AS narrative
+     ,
+            NULL::integer AS pk_encounter
+     ,
+            NULL::integer AS pk_episode
+     ,
+            NULL::integer AS pk_health_issue
+     ,
+            c_vei.pk_export_item AS src_pk
+     ,
+            'clin.v_export_items'::text AS src_table
+           
+  FROM clin.v_export_items c_vei
+        
+UNION ALL
+         
+SELECT (
+      SELECT encounter.fk_patient
+                   
+        FROM clin.encounter
+                  
+       WHERE (encounter.pk = c_sh.fk_encounter)
+     ) AS pk_patient
+     ,
+            'p'::text AS soap_cat
+     ,
+            c_sh.rationale AS narrative
+     ,
+            c_sh.fk_encounter AS pk_encounter
+     ,
+            NULL::integer AS pk_episode
+     ,
+            NULL::integer AS pk_health_issue
+     ,
+            c_sh.pk AS src_pk
+     ,
+            'clin.suppressed_hint'::text AS src_table
+           
+  FROM clin.suppressed_hint c_sh
+) union_table
+  
+WHERE (btrim
+     (COALESCE
+           (union_table.narrative
+                 ,''::text
+           )
+     ) <> ''::text
 );</pre>
 	
 
@@ -67756,15 +81856,13 @@ LEFT JOIN dem.org d_o
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-incoming-data-unmatched">v_incoming_data_unmatched</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-nonbrand-intakes">v_nonbrand_intakes</a>
 		</h2>
         
-         <p>Shows incoming data but w/o the data field.</p>
-        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_incoming_data_unmatched Structure</caption>
+                <caption>clin.v_nonbrand_intakes Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -67776,7 +81874,7 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>pk_incoming_data_unmatched</td>
+            	<td>pk_substance_intake</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -67792,8 +81890,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>pk_patient_candidates</td>
-            	<td>integer[]</td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -67808,7 +81906,7 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>firstnames</td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -67824,8 +81922,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>lastnames</td>
-            	<td>text</td>
+            	<td>brand</td>
+            	<td>unknown</td>
                 <td><i>
 				
 
@@ -67840,8 +81938,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>dob</td>
-            	<td>date</td>
+            	<td>preparation</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -67856,7 +81954,7 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>gender</td>
+            	<td>substance</td>
             	<td>text</td>
                 <td><i>
 				
@@ -67872,8 +81970,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>postcode</td>
-            	<td>text</td>
+            	<td>amount</td>
+            	<td>numeric</td>
                 <td><i>
 				
 
@@ -67888,7 +81986,7 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>other_info</td>
+            	<td>unit</td>
             	<td>text</td>
                 <td><i>
 				
@@ -67904,7 +82002,7 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>request_id</td>
+            	<td>atc_substance</td>
             	<td>text</td>
                 <td><i>
 				
@@ -67920,8 +82018,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>requestor</td>
-            	<td>text</td>
+            	<td>atc_brand</td>
+            	<td>unknown</td>
                 <td><i>
 				
 
@@ -67936,8 +82034,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>external_data_id</td>
-            	<td>text</td>
+            	<td>external_code_brand</td>
+            	<td>unknown</td>
                 <td><i>
 				
 
@@ -67952,8 +82050,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>external_code_type_brand</td>
+            	<td>unknown</td>
                 <td><i>
 				
 
@@ -67968,8 +82066,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>pk_identity_disambiguated</td>
-            	<td>integer</td>
+            	<td>started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -67984,8 +82082,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>pk_provider_disambiguated</td>
-            	<td>integer</td>
+            	<td>comment_on_start</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -68000,8 +82098,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>data_type</td>
-            	<td>text</td>
+            	<td>start_is_unknown</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -68016,8 +82114,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>md5_sum</td>
-            	<td>text</td>
+            	<td>start_is_approximate</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -68032,8 +82130,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>data_size</td>
-            	<td>integer</td>
+            	<td>intake_is_approved_of</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -68048,8 +82146,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>xmin_incoming_data_unmatched</td>
-            	<td>xid</td>
+            	<td>harmful_use_type</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -68060,81 +82158,12 @@ LEFT JOIN dem.org d_o
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT c_idu.pk AS pk_incoming_data_unmatched
-, c_idu.fk_patient_candidates AS pk_patient_candidates
-, c_idu.firstnames
-, c_idu.lastnames
-, c_idu.dob
-, c_idu.gender
-, c_idu.postcode
-, c_idu.other_info
-, c_idu.request_id
-, c_idu.requestor
-, c_idu.external_data_id
-, c_idu.comment
-, c_idu.fk_identity_disambiguated AS pk_identity_disambiguated
-, c_idu.fk_provider_disambiguated AS pk_provider_disambiguated
-, c_idu.type AS data_type
-, md5
-(c_idu.data) AS md5_sum
-, octet_length
-(c_idu.data) AS data_size
-, c_idu.xmin AS xmin_incoming_data_unmatched 
-FROM clin.incoming_data_unmatched c_idu;</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-indications4vaccine">v_indications4vaccine</a>
-		</h2>
-        
-         <p>Denormalizes indications per vaccine.</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_indications4vaccine Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_vaccine</td>
-            	<td>integer</td>
+            	<td>last_checked_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -68149,7 +82178,7 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>vaccine</td>
+            	<td>schedule</td>
             	<td>text</td>
                 <td><i>
 				
@@ -68165,8 +82194,8 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>preparation</td>
-            	<td>text</td>
+            	<td>duration</td>
+            	<td>interval</td>
                 <td><i>
 				
 
@@ -68181,8 +82210,8 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>atc_code</td>
-            	<td>text</td>
+            	<td>discontinued</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -68197,8 +82226,8 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>is_fake_vaccine</td>
-            	<td>boolean</td>
+            	<td>discontinue_reason</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -68213,8 +82242,8 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>route_abbreviation</td>
-            	<td>text</td>
+            	<td>is_long_term</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -68229,7 +82258,7 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>route_description</td>
+            	<td>aim</td>
             	<td>text</td>
                 <td><i>
 				
@@ -68245,8 +82274,8 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>is_live</td>
-            	<td>boolean</td>
+            	<td>episode</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -68261,8 +82290,8 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>min_age</td>
-            	<td>interval</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -68277,8 +82306,8 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>max_age</td>
-            	<td>interval</td>
+            	<td>notes</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -68293,8 +82322,8 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>fake_brand</td>
+            	<td>unknown</td>
                 <td><i>
 				
 
@@ -68309,8 +82338,8 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>indication</td>
-            	<td>text</td>
+            	<td>is_currently_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -68325,8 +82354,8 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>l10n_indication</td>
-            	<td>text</td>
+            	<td>seems_inactive</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -68341,8 +82370,8 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>atcs_single_indication</td>
-            	<td>text[]</td>
+            	<td>pk_brand</td>
+            	<td>unknown</td>
                 <td><i>
 				
 
@@ -68357,8 +82386,8 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>atcs_combi_indication</td>
-            	<td>text[]</td>
+            	<td>pk_data_source</td>
+            	<td>unknown</td>
                 <td><i>
 				
 
@@ -68373,8 +82402,8 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>external_code</td>
-            	<td>text</td>
+            	<td>pk_substance</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -68389,8 +82418,8 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>external_code_type</td>
-            	<td>text</td>
+            	<td>pk_drug_component</td>
+            	<td>unknown</td>
                 <td><i>
 				
 
@@ -68405,8 +82434,8 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>indications</td>
-            	<td>text[]</td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -68421,8 +82450,8 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>l10n_indications</td>
-            	<td>text[]</td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -68437,8 +82466,8 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_indications</td>
-            	<td>integer[]</td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -68453,8 +82482,8 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_route</td>
-            	<td>integer</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -68469,8 +82498,8 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_brand</td>
-            	<td>integer</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
@@ -68485,7 +82514,7 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_data_source</td>
+            	<td>row_version</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -68501,23 +82530,7 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_indication</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>xmin_vaccine</td>
+            	<td>xmin_substance_intake</td>
             	<td>xid</td>
                 <td><i>
 				
@@ -68548,88 +82561,178 @@ FROM clin.incoming_data_unmatched c_idu;</pre>
 	<!-- View Definition -->
 	
 	<pre>
-SELECT cv.pk AS pk_vaccine
-, rbd.description AS vaccine
-, rbd.preparation
-, rbd.atc_code
-, rbd.is_fake AS is_fake_vaccine
-, cvr.abbreviation AS route_abbreviation
-, cvr.description AS route_description
-, cv.is_live
-, cv.min_age
-, cv.max_age
-, cv.comment
-, cvi.description AS indication
-, _
-(cvi.description) AS l10n_indication
-, cvi.atcs_single_indication
-, cvi.atcs_combi_indication
-, rbd.external_code
-, rbd.external_code_type
-, (
-SELECT array_agg
-     (cvi2.description) AS array_agg 
-  FROM (clin.lnk_vaccine2inds clv2i_2 
-        JOIN clin.vacc_indication cvi2 
-          ON (
-                 (clv2i_2.fk_indication = cvi2.id)
-           )
-     )
- WHERE (clv2i_2.fk_vaccine = cv.pk)
-) AS indications
-, (
-SELECT array_agg
-     (_
-           (cvi2.description)
-     ) AS array_agg 
-  FROM (clin.lnk_vaccine2inds clv2i_2 
-        JOIN clin.vacc_indication cvi2 
-          ON (
-                 (clv2i_2.fk_indication = cvi2.id)
-           )
-     )
- WHERE (clv2i_2.fk_vaccine = cv.pk)
-) AS l10n_indications
-, (
-SELECT array_agg
-     (clv2i_2.fk_indication) AS array_agg 
-  FROM (clin.lnk_vaccine2inds clv2i_2 
-        JOIN clin.vacc_indication cvi2 
-          ON (
-                 (clv2i_2.fk_indication = cvi2.id)
-           )
-     )
- WHERE (clv2i_2.fk_vaccine = cv.pk)
-) AS pk_indications
-, cv.id_route AS pk_route
-, cv.fk_brand AS pk_brand
-, rbd.fk_data_source AS pk_data_source
-, cvi.id AS pk_indication
-, cv.xmin AS xmin_vaccine 
+SELECT c_si.pk AS pk_substance_intake
+,
+    
+(
+SELECT encounter.fk_patient
+           
+  FROM clin.encounter
+          
+ WHERE (encounter.pk = c_si.fk_encounter)
+) AS pk_patient
+,
+    c_si.soap_cat
+,
+    NULL::unknown AS brand
+,
+    c_si.preparation
+,
+    r_cs.description AS substance
+,
+    r_cs.amount
+,
+    r_cs.unit
+,
+    r_cs.atc_code AS atc_substance
+,
+    NULL::unknown AS atc_brand
+,
+    NULL::unknown AS external_code_brand
+,
+    NULL::unknown AS external_code_type_brand
+,
+        CASE
+            WHEN 
+(c_si.comment_on_start = '?'::text) THEN NULL::timestamp with time zone
+            ELSE c_si.clin_when
+        END AS started
+,
+    c_si.comment_on_start
+,
+        CASE
+            WHEN 
+(c_si.comment_on_start = '?'::text) THEN true
+            ELSE false
+        END AS start_is_unknown
+,
+        CASE
+            WHEN 
+(c_si.comment_on_start IS NULL) THEN false
+            ELSE true
+        END AS start_is_approximate
+,
+    c_si.intake_is_approved_of
+,
+    c_si.harmful_use_type
+,
+        CASE
+            WHEN 
+(c_si.harmful_use_type IS NULL) THEN NULL::timestamp with time zone
+            ELSE c_enc.started
+        END AS last_checked_when
+,
+    c_si.schedule
+,
+    c_si.duration
+,
+    c_si.discontinued
+,
+    c_si.discontinue_reason
+,
+    c_si.is_long_term
+,
+    c_si.aim
+,
+    cep.description AS episode
+,
+    c_hi.description AS health_issue
+,
+    c_si.narrative AS notes
+,
+    NULL::unknown AS fake_brand
+,
+        CASE
+            WHEN 
+(c_si.discontinued IS NULL) THEN true
+            ELSE false
+        END AS is_currently_active
+,
+        CASE
+            WHEN 
+(c_si.discontinued IS NOT NULL) THEN true
+            WHEN 
+(c_si.clin_when IS NULL) THEN
+            CASE
+                WHEN 
+(c_si.is_long_term IS TRUE) THEN false
+                ELSE NULL::boolean
+            END
+            WHEN 
+(
+     (c_si.clin_when > now
+           ()
+     ) IS TRUE
+) THEN true
+            WHEN 
+(
+     (
+           (c_si.clin_when + c_si.duration) < now
+           ()
+     ) IS TRUE
+) THEN true
+            WHEN 
+(
+     (
+           (c_si.clin_when + c_si.duration) > now
+           ()
+     ) IS TRUE
+) THEN false
+            ELSE NULL::boolean
+        END AS seems_inactive
+,
+    NULL::unknown AS pk_brand
+,
+    NULL::unknown AS pk_data_source
+,
+    r_cs.pk AS pk_substance
+,
+    NULL::unknown AS pk_drug_component
+,
+    c_si.fk_encounter AS pk_encounter
+,
+    c_si.fk_episode AS pk_episode
+,
+    cep.fk_health_issue AS pk_health_issue
+,
+    c_si.modified_when
+,
+    c_si.modified_by
+,
+    c_si.row_version
+,
+    c_si.xmin AS xmin_substance_intake
+   
 FROM (
      (
            (
-                 (clin.vaccine cv 
-               LEFT JOIN clin.vacc_route cvr 
+                 (clin.substance_intake c_si
+     
+                    JOIN ref.consumable_substance r_cs 
                       ON (
-                             (cvr.id = cv.id_route)
+                             (c_si.fk_substance = r_cs.pk)
                        )
                  )
-              JOIN ref.branded_drug rbd 
+     
+         LEFT JOIN clin.episode cep 
                 ON (
-                       (rbd.pk = cv.fk_brand)
+                       (c_si.fk_episode = cep.pk)
                  )
            )
-        JOIN clin.lnk_vaccine2inds clv2i 
+     
+   LEFT JOIN clin.health_issue c_hi 
           ON (
-                 (clv2i.fk_vaccine = cv.pk)
+                 (c_hi.pk = cep.fk_health_issue)
            )
      )
-  JOIN clin.vacc_indication cvi 
+     
+LEFT JOIN clin.encounter c_enc 
     ON (
-           (cvi.id = clv2i.fk_indication)
+           (c_si.fk_encounter = c_enc.pk)
      )
-);</pre>
+)
+  
+WHERE (c_si.fk_drug_component IS NULL);</pre>
 	
 
 	<!-- List off permissions -->
@@ -68643,15 +82746,15 @@ FROM (
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-linked-codes">v_linked_codes</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-allergies">v_pat_allergies</a>
 		</h2>
         
-         <p>Denormalized codes linked to EMR structures.</p>
+         <p>denormalizes clin.allergy</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_linked_codes Structure</caption>
+                <caption>clin.v_pat_allergies Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -68663,8 +82766,104 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
-            	<td>integer</td>
+            	<td>pk_allergy</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>soap_cat</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>descriptor</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>allergene</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>substance</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>substance_code</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -68679,8 +82878,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>item_table</td>
-            	<td>regclass</td>
+            	<td>generics</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -68695,8 +82894,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>code</td>
-            	<td>text</td>
+            	<td>generic_specific</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -68711,7 +82910,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>base_code</td>
+            	<td>atc_code</td>
             	<td>text</td>
                 <td><i>
 				
@@ -68727,7 +82926,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>code_modifier</td>
+            	<td>type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -68743,7 +82942,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>term</td>
+            	<td>l10n_type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -68759,8 +82958,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>name_long</td>
-            	<td>text</td>
+            	<td>definite</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -68775,7 +82974,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>name_short</td>
+            	<td>reaction</td>
             	<td>text</td>
                 <td><i>
 				
@@ -68791,8 +82990,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>version</td>
-            	<td>text</td>
+            	<td>pk_type</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -68807,8 +83006,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>lang</td>
-            	<td>text</td>
+            	<td>pk_item</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -68823,8 +83022,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>code_table</td>
-            	<td>regclass</td>
+            	<td>date</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -68839,7 +83038,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_generic_code</td>
+            	<td>pk_health_issue</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -68855,7 +83054,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_data_source</td>
+            	<td>pk_episode</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -68871,7 +83070,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_lnk_code2item</td>
+            	<td>pk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -68883,6 +83082,54 @@ FROM (
 				</td>
 			 </tr>
             
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>xmin_allergy</td>
+            	<td>xid</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
         </table>
 
         <!-- Inherits -->
@@ -68902,36 +83149,81 @@ FROM (
 	<!-- View Definition -->
 	
 	<pre>
-SELECT c_lc2ir.fk_item AS pk_item
-, (c_lc2ir.tableoid)::regclass AS item_table
-, (r_csr.code || COALESCE
-     (c_lc2ir.code_modifier
+SELECT a.pk AS pk_allergy
+,
+    
+(
+SELECT encounter.fk_patient
+           
+  FROM clin.encounter
+          
+ WHERE (encounter.pk = a.fk_encounter)
+) AS pk_patient
+,
+    a.soap_cat
+,
+        CASE
+            WHEN 
+(COALESCE
+     (btrim
+           (a.allergene)
            ,''::text
-     )
-) AS code
-, r_csr.code AS base_code
-, c_lc2ir.code_modifier
-, r_csr.term
-, r_ds.name_long
-, r_ds.name_short
-, r_ds.version
-, r_ds.lang
-, (r_csr.tableoid)::regclass AS code_table
-, r_csr.pk_coding_system AS pk_generic_code
-, r_csr.fk_data_source AS pk_data_source
-, c_lc2ir.pk_lnk_code2item 
-FROM (
-     (clin.lnk_code2item_root c_lc2ir 
-        JOIN ref.coding_system_root r_csr 
-          ON (
-                 (r_csr.pk_coding_system = c_lc2ir.fk_generic_code)
-           )
-     )
-  JOIN ref.data_source r_ds 
-    ON (
-           (r_ds.pk = r_csr.fk_data_source)
-     )
-);</pre>
+     ) = ''::text
+) THEN a.substance
+            ELSE a.allergene
+        END AS descriptor
+,
+    a.allergene
+,
+    a.substance
+,
+    a.substance_code
+,
+    a.generics
+,
+    a.generic_specific
+,
+    a.atc_code
+,
+    at.value AS type
+,
+    _
+(at.value) AS l10n_type
+,
+    a.definite
+,
+    a.narrative AS reaction
+,
+    a.fk_type AS pk_type
+,
+    a.pk_item
+,
+    a.clin_when AS date
+,
+    
+(
+SELECT episode.fk_health_issue
+           
+  FROM clin.episode
+          
+ WHERE (episode.pk = a.fk_episode)
+) AS pk_health_issue
+,
+    a.fk_episode AS pk_episode
+,
+    a.fk_encounter AS pk_encounter
+,
+    a.modified_when
+,
+    a.modified_by
+,
+    a.xmin AS xmin_allergy
+   
+FROM clin.allergy a
+,
+    clin._enum_allergy_type at
+  
+WHERE (at.pk = a.fk_type);</pre>
 	
 
 	<!-- List off permissions -->
@@ -68945,19 +83237,13 @@ FROM (
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-most-recent-encounters">v_most_recent_encounters</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-allergies-journal">v_pat_allergies_journal</a>
 		</h2>
         
-         <p>Lists the most recent encounters per patient. Logic of "most recent" 
-	is: for a patient: 
-	 1) select encounters with latest "last_affirmed",
-	 2) from those select encounters with latest "started"
-	 3) limit those to 1 if there are duplicates (same start and end of encounter!)</p>
-        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_most_recent_encounters Structure</caption>
+                <caption>clin.v_pat_allergies_journal Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -68969,7 +83255,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
+            	<td>pk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -68985,8 +83271,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -69001,8 +83287,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>reason_for_encounter</td>
-            	<td>text</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -69017,7 +83303,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>assessment_of_encounter</td>
+            	<td>modified_by</td>
             	<td>text</td>
                 <td><i>
 				
@@ -69033,7 +83319,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>type</td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -69049,7 +83335,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>l10n_type</td>
+            	<td>narrative</td>
             	<td>text</td>
                 <td><i>
 				
@@ -69065,8 +83351,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>started</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -69081,8 +83367,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>last_affirmed</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -69097,7 +83383,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_type</td>
+            	<td>pk_health_issue</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -69113,7 +83399,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_location</td>
+            	<td>src_pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -69125,91 +83411,44 @@ FROM (
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT ce1.pk AS pk_encounter
-, ce1.fk_patient AS pk_patient
-, ce1.reason_for_encounter
-, ce1.assessment_of_encounter
-, et.description AS type
-, _
-(et.description) AS l10n_type
-, ce1.started
-, ce1.last_affirmed
-, ce1.fk_type AS pk_type
-, ce1.fk_location AS pk_location 
-FROM clin.encounter ce1
-, clin.encounter_type et 
-WHERE (
-     (ce1.fk_type = et.pk)
-   AND (ce1.started = 
-           (
-            SELECT max
-                 (ce2.started) AS max 
-              FROM clin.encounter ce2 
-             WHERE (ce2.last_affirmed = 
-                       (
-                        SELECT max
-                             (ce3.last_affirmed) AS max 
-                          FROM clin.encounter ce3 
-                         WHERE (ce3.fk_patient = ce1.fk_patient)
-                       )
-                 ) LIMIT 1
-           )
-     )
-);</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-narrative">v_narrative</a>
-		</h2>
-        
-         <p>patient narrative with denormalized context added</p>
-        
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>src_table</td>
+            	<td>text</td>
+                <td><i>
+				
 
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
 
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_narrative Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -69224,8 +83463,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>date</td>
-            	<td>timestamp with time zone</td>
+            	<td>issue_laterality</td>
+            	<td>character varying(2)</td>
                 <td><i>
 				
 
@@ -69240,8 +83479,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>text</td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -69256,8 +83495,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -69272,8 +83511,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>narrative</td>
-            	<td>text</td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -69304,8 +83543,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>health_issue</td>
-            	<td>text</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -69320,8 +83559,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
-            	<td>integer</td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -69336,8 +83575,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_narrative</td>
-            	<td>integer</td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -69352,8 +83591,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
-            	<td>integer</td>
+            	<td>encounter_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -69368,7 +83607,227 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
+            	<td>encounter_l10n_type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT c_enc.fk_patient AS pk_patient
+,
+    c_all.modified_when
+,
+    c_all.clin_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_all.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (c_all.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    c_all.soap_cat
+,
+    
+(
+     (
+           (
+                 (
+                       (
+                             (
+                                   (
+                                         (
+                                               (
+                                                     (
+                                                           (
+                                                                 (_
+                                                                       ('Allergy'::text) || 
+                                                                    ' ('::text) || _
+                                                                       (c_at.value)
+                                                                 ) || 
+                                                       '): '::text
+                                                     ) || COALESCE
+                                                     (c_all.narrative
+                                                           ,''::text
+                                                     )
+                                               ) || '
+'::text
+                                         ) || _
+                                         ('substance'::text)
+                                   ) || ': '::text
+                             ) || c_all.substance
+                       ) || '; '::text
+                 ) || COALESCE
+                 (
+                       (
+                             (
+                                   (_
+                                         ('allergene'::text) || ': '::text
+                                   ) || c_all.allergene
+                             ) || '; '::text
+                       )
+                       ,''::text
+                 )
+           ) || COALESCE
+           (
+                 (
+                       (
+                             (_
+                                   ('generic'::text) || ': '::text
+                             ) || c_all.generics
+                       ) || '; '::text
+                 )
+                 ,''::text
+           )
+     ) || COALESCE
+     (
+           (
+                 (
+                       (_
+                             ('ATC code'::text) || ': '::text
+                       ) || c_all.atc_code
+                 ) || '; '::text
+           )
+           ,''::text
+     )
+) AS narrative
+,
+    c_all.fk_encounter AS pk_encounter
+,
+    c_all.fk_episode AS pk_episode
+,
+    c_epi.fk_health_issue AS pk_health_issue
+,
+    c_all.pk AS src_pk
+,
+    'clin.allergy'::text AS src_table
+,
+    c_all.row_version
+,
+    c_hi.description AS health_issue
+,
+    c_hi.laterality AS issue_laterality
+,
+    c_hi.is_active AS issue_active
+,
+    c_hi.clinically_relevant AS issue_clinically_relevant
+,
+    c_hi.is_confidential AS issue_confidential
+,
+    c_epi.description AS episode
+,
+    c_epi.is_open AS episode_open
+,
+    c_enc.started AS encounter_started
+,
+    c_enc.last_affirmed AS encounter_last_affirmed
+,
+    c_ety.description AS encounter_type
+,
+    _
+(c_ety.description) AS encounter_l10n_type
+   
+FROM (
+     (
+           (
+                 (
+                       (clin.allergy c_all
+     
+                          JOIN clin._enum_allergy_type c_at 
+                            ON (
+                                   (c_all.fk_type = c_at.pk)
+                             )
+                       )
+     
+                    JOIN clin.encounter c_enc 
+                      ON (
+                             (c_all.fk_encounter = c_enc.pk)
+                       )
+                 )
+     
+              JOIN clin.encounter_type c_ety 
+                ON (
+                       (c_enc.fk_type = c_ety.pk)
+                 )
+           )
+     
+        JOIN clin.episode c_epi 
+          ON (
+                 (c_all.fk_episode = c_epi.pk)
+           )
+     )
+     
+LEFT JOIN clin.health_issue c_hi 
+    ON (
+           (c_epi.fk_health_issue = c_hi.pk)
+     )
+);</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-allergy-state">v_pat_allergy_state</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.v_pat_allergy_state Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -69384,8 +83843,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -69400,8 +83859,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>xmin_clin_narrative</td>
-            	<td>xid</td>
+            	<td>modified_by</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -69416,7 +83875,7 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
+            	<td>last_confirmed</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
@@ -69432,7 +83891,7 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>row_version</td>
+            	<td>has_allergy</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -69448,8 +83907,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -69464,8 +83923,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>modified_by_raw</td>
-            	<td>name</td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -69480,8 +83939,24 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_generic_codes</td>
-            	<td>integer[]</td>
+            	<td>pk_allergy_state</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>xmin_allergy_state</td>
+            	<td>xid</td>
                 <td><i>
 				
 
@@ -69511,63 +83986,45 @@ WHERE (
 	<!-- View Definition -->
 	
 	<pre>
-SELECT c_enc.fk_patient AS pk_patient
-, c_n.clin_when AS date
-, COALESCE
-(
-     (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.db_user = c_n.modified_by)
-     )
-     , (
-           ('<'::text || 
-                 (c_n.modified_by)::text
-           ) || '>'::text
-     )
-) AS modified_by
-, c_n.soap_cat
-, c_n.narrative
-, c_epi.description AS episode
-, c_hi.description AS health_issue
-, c_n.pk_item
-, c_n.pk AS pk_narrative
-, c_epi.fk_health_issue AS pk_health_issue
-, c_n.fk_episode AS pk_episode
-, c_n.fk_encounter AS pk_encounter
-, c_n.xmin AS xmin_clin_narrative
-, c_n.modified_when
-, c_n.row_version
-, c_n.pk_audit
-, c_n.modified_by AS modified_by_raw
-, COALESCE
-(
-     (
-      SELECT array_agg
-           (c_lc2n.fk_generic_code) AS array_agg 
-        FROM clin.lnk_code2narrative c_lc2n 
-       WHERE (c_lc2n.fk_item = c_n.pk)
-     )
-     , ARRAY[]::integer[]
-) AS pk_generic_codes 
-FROM (
-     (
-           (clin.clin_narrative c_n 
-         LEFT JOIN clin.encounter c_enc 
-                ON (
-                       (c_n.fk_encounter = c_enc.pk)
-                 )
-           )
-   LEFT JOIN clin.episode c_epi 
-          ON (
-                 (c_n.fk_episode = c_epi.pk)
-           )
+SELECT (
+SELECT encounter.fk_patient
+           
+  FROM clin.encounter
+          
+ WHERE (encounter.pk = a.fk_encounter)
+) AS pk_patient
+,
+    a.modified_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = a.modified_by)
      )
-LEFT JOIN clin.health_issue c_hi 
-    ON (
-           (c_epi.fk_health_issue = c_hi.pk)
+     , (
+           ('<'::text || 
+                 (a.modified_by)::text
+           ) || '>'::text
      )
-);</pre>
+) AS modified_by
+,
+    a.last_confirmed
+,
+    a.has_allergy
+,
+    a.comment
+,
+    a.fk_encounter AS pk_encounter
+,
+    a.pk AS pk_allergy_state
+,
+    a.xmin AS xmin_allergy_state
+   
+FROM clin.allergy_state a;</pre>
 	
 
 	<!-- List off permissions -->
@@ -69581,17 +84038,13 @@ LEFT JOIN clin.health_issue c_hi
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-narrative4search">v_narrative4search</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-allergy-state-journal">v_pat_allergy_state_journal</a>
 		</h2>
         
-         <p>unformatted *complete* narrative for patients
-	 including health issue/episode/encounter descriptions,
-	 mainly for searching the narrative in context</p>
-        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_narrative4search Structure</caption>
+                <caption>clin.v_pat_allergy_state_journal Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -69619,7 +84072,39 @@ LEFT JOIN clin.health_issue c_hi
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_by</td>
             	<td>text</td>
                 <td><i>
 				
@@ -69635,7 +84120,7 @@ LEFT JOIN clin.health_issue c_hi
 				<td>
                 
                 </td>
-            	<td>narrative</td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -69651,6 +84136,22 @@ LEFT JOIN clin.health_issue c_hi
 				<td>
                 
                 </td>
+            	<td>narrative</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
             	<td>pk_encounter</td>
             	<td>integer</td>
                 <td><i>
@@ -69663,7 +84164,7 @@ LEFT JOIN clin.health_issue c_hi
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -69679,7 +84180,7 @@ LEFT JOIN clin.health_issue c_hi
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -69695,7 +84196,7 @@ LEFT JOIN clin.health_issue c_hi
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -69711,7 +84212,7 @@ LEFT JOIN clin.health_issue c_hi
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -69727,551 +84228,28 @@ LEFT JOIN clin.health_issue c_hi
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT union_table.pk_patient
-, union_table.soap_cat
-, union_table.narrative
-, union_table.pk_encounter
-, union_table.pk_episode
-, union_table.pk_health_issue
-, union_table.src_pk
-, union_table.src_table 
-FROM (
-     (
-           (
-                 (
-                       (
-                             (
-                                   (
-                                         (
-                                               (
-                                                     (
-                                                           (
-                                                                 (
-                                                                       (
-                                                                             (
-                                                                                   (
-                                                                                         (
-                                                                                               (
-                                                                                                     (
-                                                                                                      SELECT vpi.pk_patient
-                                                                                                           , vpi.soap_cat
-                                                                                                           , vpi.narrative
-                                                                                                           , vpi.pk_encounter
-                                                                                                           , vpi.pk_episode
-                                                                                                           , vpi.pk_health_issue
-                                                                                                           , vpi.pk_item AS src_pk
-                                                                                                           , vpi.src_table 
-                                                                                                        FROM clin.v_pat_items vpi 
-                                                                                                       WHERE (vpi.src_table <> ALL 
-                                                                                                                 (ARRAY['clin.allergy'::text
-                                                                                                                       ,'clin.test_result'::text
-                                                                                                                       ,'clin.procedure'::text
-                                                                                                                       ,'clin.substance_intake'::text
-                                                                                                                       ,'clin.family_history'::text]
-                                                                                                                 )
-                                                                                                           )
-                                                                                                   UNION ALLSELECT (
-                                                                                                            SELECT encounter.fk_patient 
-                                                                                                              FROM clin.encounter 
-                                                                                                             WHERE (encounter.pk = csi.fk_encounter)
-                                                                                                           ) AS pk_patient
-                                                                                                           , csi.soap_cat
-                                                                                                           , (
-                                                                                                                 (
-                                                                                                                       (COALESCE
-                                                                                                                             (csi.narrative
-                                                                                                                                   ,''::text
-                                                                                                                             ) || COALESCE
-                                                                                                                             (
-                                                                                                                                   (' '::text || csi.schedule)
-                                                                                                                                   ,''::text
-                                                                                                                             )
-                                                                                                                       ) || COALESCE
-                                                                                                                       (
-                                                                                                                             (' '::text || csi.aim)
-                                                                                                                             ,''::text
-                                                                                                                       )
-                                                                                                                 ) || COALESCE
-                                                                                                                 (
-                                                                                                                       (' '::text || csi.discontinue_reason)
-                                                                                                                       ,''::text
-                                                                                                                 )
-                                                                                                           ) AS narrative
-                                                                                                           , csi.fk_encounter AS pk_encounter
-                                                                                                           , csi.fk_episode AS pk_episode
-                                                                                                           , (
-                                                                                                            SELECT episode.fk_health_issue 
-                                                                                                              FROM clin.episode 
-                                                                                                             WHERE (episode.pk = csi.fk_episode)
-                                                                                                           ) AS pk_health_issue
-                                                                                                           , csi.pk AS src_pk
-                                                                                                           ,'clin.substance_intake'::text AS src_table 
-                                                                                                        FROM clin.substance_intake csi
-                                                                                                     )
-                                                                                             UNION ALLSELECT (
-                                                                                                      SELECT encounter.fk_patient 
-                                                                                                        FROM clin.encounter 
-                                                                                                       WHERE (encounter.pk = cpr.fk_encounter)
-                                                                                                     ) AS pk_patient
-                                                                                                     , cpr.soap_cat
-                                                                                                     , cpr.narrative
-                                                                                                     , cpr.fk_encounter AS pk_encounter
-                                                                                                     , cpr.fk_episode AS pk_episode
-                                                                                                     , (
-                                                                                                      SELECT episode.fk_health_issue 
-                                                                                                        FROM clin.episode 
-                                                                                                       WHERE (episode.pk = cpr.fk_episode)
-                                                                                                     ) AS pk_health_issue
-                                                                                                     , cpr.pk AS src_pk
-                                                                                                     ,'clin.procedure'::text AS src_table 
-                                                                                                  FROM clin.procedure cpr 
-                                                                                                 WHERE (cpr.narrative IS NOT NULL)
-                                                                                               )
-                                                                                       UNION ALLSELECT (
-                                                                                                SELECT encounter.fk_patient 
-                                                                                                  FROM clin.encounter 
-                                                                                                 WHERE (encounter.pk = ctr.fk_encounter)
-                                                                                               ) AS pk_patient
-                                                                                               , ctr.soap_cat
-                                                                                               , (
-                                                                                                     (
-                                                                                                           (
-                                                                                                                 (
-                                                                                                                       (
-                                                                                                                             (
-                                                                                                                                   (
-                                                                                                                                         (COALESCE
-                                                                                                                                               (ctr.narrative
-                                                                                                                                                     ,''::text
-                                                                                                                                               ) || COALESCE
-                                                                                                                                               (
-                                                                                                                                                     (' '::text || ctr.val_alpha)
-                                                                                                                                                     ,''::text
-                                                                                                                                               )
-                                                                                                                                         ) || COALESCE
-                                                                                                                                         (
-                                                                                                                                               (' '::text || ctr.val_unit)
-                                                                                                                                               ,''::text
-                                                                                                                                         )
-                                                                                                                                   ) || COALESCE
-                                                                                                                                   (
-                                                                                                                                         (' '::text || ctr.val_normal_range)
-                                                                                                                                         ,''::text
-                                                                                                                                   )
-                                                                                                                             ) || COALESCE
-                                                                                                                             (
-                                                                                                                                   (' '::text || ctr.val_target_range)
-                                                                                                                                   ,''::text
-                                                                                                                             )
-                                                                                                                       ) || COALESCE
-                                                                                                                       (
-                                                                                                                             (' '::text || ctr.norm_ref_group)
-                                                                                                                             ,''::text
-                                                                                                                       )
-                                                                                                                 ) || COALESCE
-                                                                                                                 (
-                                                                                                                       (' '::text || ctr.note_test_org)
-                                                                                                                       ,''::text
-                                                                                                                 )
-                                                                                                           ) || COALESCE
-                                                                                                           (
-                                                                                                                 (' '::text || ctr.material)
-                                                                                                                 ,''::text
-                                                                                                           )
-                                                                                                     ) || COALESCE
-                                                                                                     (
-                                                                                                           (' '::text || ctr.material_detail)
-                                                                                                           ,''::text
-                                                                                                     )
-                                                                                               ) AS narrative
-                                                                                               , ctr.fk_encounter AS pk_encounter
-                                                                                               , ctr.fk_episode AS pk_episode
-                                                                                               , (
-                                                                                                SELECT episode.fk_health_issue 
-                                                                                                  FROM clin.episode 
-                                                                                                 WHERE (episode.pk = ctr.fk_episode)
-                                                                                               ) AS pk_health_issue
-                                                                                               , ctr.pk AS src_pk
-                                                                                               ,'clin.test_result'::text AS src_table 
-                                                                                            FROM clin.test_result ctr
-                                                                                         )
-                                                                                 UNION ALLSELECT (
-                                                                                          SELECT encounter.fk_patient 
-                                                                                            FROM clin.encounter 
-                                                                                           WHERE (encounter.pk = 
-                                                                                                     (
-                                                                                                      SELECT test_result.fk_encounter 
-                                                                                                        FROM clin.test_result 
-                                                                                                       WHERE (test_result.pk = crtr.fk_reviewed_row)
-                                                                                                     )
-                                                                                               )
-                                                                                         ) AS pk_patient
-                                                                                         ,'o'::text AS soap_cat
-                                                                                         , crtr.comment AS narrative
-                                                                                         , (
-                                                                                          SELECT test_result.fk_encounter 
-                                                                                            FROM clin.test_result 
-                                                                                           WHERE (test_result.pk = crtr.fk_reviewed_row)
-                                                                                         ) AS pk_encounter
-                                                                                         , (
-                                                                                          SELECT test_result.fk_episode 
-                                                                                            FROM clin.test_result 
-                                                                                           WHERE (test_result.pk = crtr.fk_reviewed_row)
-                                                                                         ) AS pk_episode
-                                                                                         , (
-                                                                                          SELECT episode.fk_health_issue 
-                                                                                            FROM clin.episode 
-                                                                                           WHERE (episode.pk = 
-                                                                                                     (
-                                                                                                      SELECT test_result.fk_episode 
-                                                                                                        FROM clin.test_result 
-                                                                                                       WHERE (test_result.pk = crtr.fk_reviewed_row)
-                                                                                                     )
-                                                                                               )
-                                                                                         ) AS pk_health_issue
-                                                                                         , crtr.pk AS src_pk
-                                                                                         ,'clin.reviewed_test_results'::text AS src_table 
-                                                                                      FROM clin.reviewed_test_results crtr
-                                                                                   )
-                                                                           UNION ALLSELECT (
-                                                                                    SELECT encounter.fk_patient 
-                                                                                      FROM clin.encounter 
-                                                                                     WHERE (encounter.pk = cas.fk_encounter)
-                                                                                   ) AS pk_patient
-                                                                                   ,'o'::text AS soap_cat
-                                                                                   , cas.comment AS narrative
-                                                                                   , cas.fk_encounter AS pk_encounter
-                                                                                   , NULL::integer AS pk_episode
-                                                                                   , NULL::integer AS pk_health_issue
-                                                                                   , cas.pk AS src_pk
-                                                                                   ,'clin.allergy_state'::text AS src_table 
-                                                                                FROM clin.allergy_state cas 
-                                                                               WHERE (cas.comment IS NOT NULL)
-                                                                             )
-                                                                     UNION ALLSELECT (
-                                                                              SELECT encounter.fk_patient 
-                                                                                FROM clin.encounter 
-                                                                               WHERE (encounter.pk = ca.fk_encounter)
-                                                                             ) AS pk_patient
-                                                                             , ca.soap_cat
-                                                                             , (
-                                                                                   (
-                                                                                         (
-                                                                                               (
-                                                                                                     (COALESCE
-                                                                                                           (ca.narrative
-                                                                                                                 ,''::text
-                                                                                                           ) || COALESCE
-                                                                                                           (
-                                                                                                                 (' '::text || ca.substance)
-                                                                                                                 ,''::text
-                                                                                                           )
-                                                                                                     ) || COALESCE
-                                                                                                     (
-                                                                                                           (' '::text || ca.substance_code)
-                                                                                                           ,''::text
-                                                                                                     )
-                                                                                               ) || COALESCE
-                                                                                               (
-                                                                                                     (' '::text || ca.generics)
-                                                                                                     ,''::text
-                                                                                               )
-                                                                                         ) || COALESCE
-                                                                                         (
-                                                                                               (' '::text || ca.allergene)
-                                                                                               ,''::text
-                                                                                         )
-                                                                                   ) || COALESCE
-                                                                                   (
-                                                                                         (' '::text || ca.atc_code)
-                                                                                         ,''::text
-                                                                                   )
-                                                                             ) AS narrative
-                                                                             , ca.fk_encounter AS pk_encounter
-                                                                             , ca.fk_episode AS pk_episode
-                                                                             , (
-                                                                              SELECT episode.fk_health_issue 
-                                                                                FROM clin.episode 
-                                                                               WHERE (episode.pk = ca.fk_episode)
-                                                                             ) AS pk_health_issue
-                                                                             , ca.pk AS src_pk
-                                                                             ,'clin.allergy'::text AS src_table 
-                                                                          FROM clin.allergy ca
-                                                                       )
-                                                               UNION ALLSELECT (
-                                                                        SELECT encounter.fk_patient 
-                                                                          FROM clin.encounter 
-                                                                         WHERE (encounter.pk = chi.fk_encounter)
-                                                                       ) AS pk_patient
-                                                                       ,'a'::text AS soap_cat
-                                                                       , (chi.description || COALESCE
-                                                                             (
-                                                                                   (' '::text || chi.summary)
-                                                                                   ,''::text
-                                                                             )
-                                                                       ) AS narrative
-                                                                       , chi.fk_encounter AS pk_encounter
-                                                                       , NULL::integer AS pk_episode
-                                                                       , chi.pk AS pk_health_issue
-                                                                       , chi.pk AS src_pk
-                                                                       ,'clin.health_issue'::text AS src_table 
-                                                                    FROM clin.health_issue chi
-                                                                 )
-                                                         UNION ALLSELECT cenc.fk_patient AS pk_patient
-                                                                 ,'s'::text AS soap_cat
-                                                                 , (COALESCE
-                                                                       (cenc.reason_for_encounter
-                                                                             ,''::text
-                                                                       ) || COALESCE
-                                                                       (
-                                                                             (' '::text || cenc.assessment_of_encounter)
-                                                                             ,''::text
-                                                                       )
-                                                                 ) AS narrative
-                                                                 , cenc.pk AS pk_encounter
-                                                                 , NULL::integer AS pk_episode
-                                                                 , NULL::integer AS pk_health_issue
-                                                                 , cenc.pk AS src_pk
-                                                                 ,'clin.encounter'::text AS src_table 
-                                                              FROM clin.encounter cenc
-                                                           )
-                                                   UNION ALLSELECT (
-                                                            SELECT encounter.fk_patient 
-                                                              FROM clin.encounter 
-                                                             WHERE (encounter.pk = cep.fk_encounter)
-                                                           ) AS pk_patient
-                                                           ,'s'::text AS soap_cat
-                                                           , (cep.description || COALESCE
-                                                                 (
-                                                                       (' '::text || cep.summary)
-                                                                       ,''::text
-                                                                 )
-                                                           ) AS narrative
-                                                           , cep.fk_encounter AS pk_encounter
-                                                           , cep.pk AS pk_episode
-                                                           , cep.fk_health_issue AS pk_health_issue
-                                                           , cep.pk AS src_pk
-                                                           ,'clin.episode'::text AS src_table 
-                                                        FROM clin.episode cep
-                                                     )
-                                             UNION ALLSELECT c_vfhx.pk_patient
-                                                     , c_vfhx.soap_cat
-                                                     , (
-                                                           (
-                                                                 (
-                                                                       (
-                                                                             (
-                                                                                   (c_vfhx.relation || ' / '::text) || c_vfhx.l10n_relation
-                                                                             ) || ' '::text
-                                                                       ) || c_vfhx.name_relative
-                                                                 ) || ': '::text
-                                                           ) || c_vfhx.condition
-                                                     ) AS narrative
-                                                     , c_vfhx.pk_encounter
-                                                     , c_vfhx.pk_episode
-                                                     , c_vfhx.pk_health_issue
-                                                     , c_vfhx.pk_family_history AS src_pk
-                                                     ,'clin.family_history'::text AS src_table 
-                                                  FROM clin.v_family_history c_vfhx
-                                               )
-                                       UNION ALLSELECT vdm.pk_patient
-                                               ,'o'::text AS soap_cat
-                                               , (
-                                                     (
-                                                           (
-                                                                 (vdm.l10n_type || ' '::text) || COALESCE
-                                                                 (vdm.ext_ref
-                                                                       ,''::text
-                                                                 )
-                                                           ) || ' '::text
-                                                     ) || COALESCE
-                                                     (vdm.comment
-                                                           ,''::text
-                                                     )
-                                               ) AS narrative
-                                               , vdm.pk_encounter
-                                               , vdm.pk_episode
-                                               , vdm.pk_health_issue
-                                               , vdm.pk_doc AS src_pk
-                                               ,'blobs.doc_med'::text AS src_table 
-                                            FROM blobs.v_doc_med vdm
-                                         )
-                                 UNION ALLSELECT vo4d.pk_patient
-                                         ,'o'::text AS soap_cat
-                                         , vo4d.obj_comment AS narrative
-                                         , vo4d.pk_encounter
-                                         , vo4d.pk_episode
-                                         , vo4d.pk_health_issue
-                                         , vo4d.pk_obj AS src_pk
-                                         ,'blobs.doc_obj'::text AS src_table 
-                                      FROM blobs.v_obj4doc_no_data vo4d
-                                   )
-                           UNION ALLSELECT vdd.pk_patient
-                                   ,'o'::text AS soap_cat
-                                   , vdd.description AS narrative
-                                   , vdd.pk_encounter
-                                   , vdd.pk_episode
-                                   , vdd.pk_health_issue
-                                   , vdd.pk_doc_desc AS src_pk
-                                   ,'blobs.doc_desc'::text AS src_table 
-                                FROM blobs.v_doc_desc vdd
-                             )
-                     UNION ALLSELECT vrdo.pk_patient
-                             ,'s'::text AS soap_cat
-                             , vrdo.comment AS narrative
-                             , NULL::integer AS pk_encounter
-                             , vrdo.pk_episode
-                             , vrdo.pk_health_issue
-                             , vrdo.pk_review_root AS src_pk
-                             ,'blobs.v_reviewed_doc_objects'::text AS src_table 
-                          FROM blobs.v_reviewed_doc_objects vrdo
-                       )
-               UNION ALLSELECT d_vit.pk_identity AS pk_patient
-                       ,'s'::text AS soap_cat
-                       , (d_vit.l10n_description || COALESCE
-                             (
-                                   (' '::text || d_vit.comment)
-                                   ,''::text
-                             )
-                       ) AS narrative
-                       , NULL::integer AS pk_encounter
-                       , NULL::integer AS pk_episode
-                       , NULL::integer AS pk_health_issue
-                       , d_vit.pk_identity_tag AS src_pk
-                       ,'dem.v_identity_tags'::text AS src_table 
-                    FROM dem.v_identity_tags d_vit
-                 )
-         UNION ALLSELECT c_vec.pk_identity AS pk_patient
-                 ,'s'::text AS soap_cat
-                 , CASE WHEN 
-                 (c_vec.pk_health_issue IS NULL) THEN 
-                 (
-                       (COALESCE
-                             (c_vec.issue
-                                   ,''::text
-                             ) || COALESCE
-                             (
-                                   (' / '::text || c_vec.provider)
-                                   ,''::text
-                             )
-                       ) || COALESCE
-                       (
-                             (' / '::text || c_vec.comment)
-                             ,''::text
-                       )
-                 ) ELSE 
-                 (COALESCE
-                       (c_vec.provider
-                             ,''::text
-                       ) || COALESCE
-                       (
-                             (' / '::text || c_vec.comment)
-                             ,''::text
-                       )
-                 ) END AS narrative
-                 , c_vec.pk_encounter
-                 , NULL::integer AS pk_episode
-                 , c_vec.pk_health_issue
-                 , c_vec.pk_external_care AS src_pk
-                 ,'clin.v_external_care'::text AS src_table 
-              FROM clin.v_external_care c_vec
-           )
-   UNION ALLSELECT c_vei.pk_identity AS pk_patient
-           ,'s'::text AS soap_cat
-           , CASE WHEN 
-           (c_vei.pk_doc_obj IS NULL) THEN 
-           (COALESCE
-                 (c_vei.description
-                       ,''::text
-                 ) || COALESCE
-                 (
-                       (' / '::text || c_vei.filename)
-                       ,''::text
-                 )
-           ) ELSE COALESCE
-           (c_vei.description
-                 ,''::text
-           ) END AS narrative
-           , NULL::integer AS pk_encounter
-           , NULL::integer AS pk_episode
-           , NULL::integer AS pk_health_issue
-           , c_vei.pk_export_item AS src_pk
-           ,'clin.v_export_items'::text AS src_table 
-        FROM clin.v_export_items c_vei
-     )
-UNION ALLSELECT (
-      SELECT encounter.fk_patient 
-        FROM clin.encounter 
-       WHERE (encounter.pk = c_sh.fk_encounter)
-     ) AS pk_patient
-     ,'p'::text AS soap_cat
-     , c_sh.rationale AS narrative
-     , c_sh.fk_encounter AS pk_encounter
-     , NULL::integer AS pk_episode
-     , NULL::integer AS pk_health_issue
-     , c_sh.pk AS src_pk
-     ,'clin.suppressed_hint'::text AS src_table 
-  FROM clin.suppressed_hint c_sh
-) union_table 
-WHERE (btrim
-     (COALESCE
-           (union_table.narrative
-                 ,''::text
-           )
-     ) <> ''::text
-);</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-nonbrand-intakes">v_nonbrand_intakes</a>
-		</h2>
-        
-
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
 
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_nonbrand_intakes Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_substance_intake</td>
-            	<td>integer</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -70286,8 +84264,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>issue_laterality</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -70302,8 +84280,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -70318,8 +84296,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>brand</td>
-            	<td>unknown</td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -70334,8 +84312,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>preparation</td>
-            	<td>text</td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -70350,7 +84328,7 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>substance</td>
+            	<td>episode</td>
             	<td>text</td>
                 <td><i>
 				
@@ -70366,8 +84344,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>amount</td>
-            	<td>numeric</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -70382,8 +84360,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>unit</td>
-            	<td>text</td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -70398,8 +84376,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>atc_substance</td>
-            	<td>text</td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -70414,8 +84392,24 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>atc_brand</td>
-            	<td>unknown</td>
+            	<td>encounter_type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>encounter_l10n_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -70426,12 +84420,350 @@ WHERE (btrim
 				</td>
 			 </tr>
             
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT c_enc.fk_patient AS pk_patient
+,
+    c_ast.modified_when
+,
+    COALESCE
+(c_ast.last_confirmed
+     , c_ast.modified_when
+) AS clin_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_ast.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (c_ast.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    'o'::text AS soap_cat
+,
+    
+(
+     (
+           (
+                 (_
+                       ('Allergy state'::text) || ': '::text
+                 ) ||
+        CASE
+            WHEN 
+                 (c_ast.has_allergy IS NULL) THEN _
+                 (
+      'unknown, unasked'::text
+                 )
+            WHEN 
+                 (c_ast.has_allergy = 0) THEN _
+                 ('no known allergies'::text)
+            WHEN 
+                 (c_ast.has_allergy = 1) THEN _
+                 ('does have allergies'::text)
+            ELSE NULL::text
+        END
+           ) || COALESCE
+           (
+                 (
+                       (
+                             (
+                                ' ('::text || _
+                                         ('last confirmed'::text)
+                                   ) || to_char
+                                   (c_ast.last_confirmed
+                                         ,' YYYY-MM-DD HH24:MI'::text
+                                   )
+                             ) || 
+                     ')'::text
+                 )
+                 ,''::text
+           )
+     ) || COALESCE
+     (
+           ('
+ '::text || c_ast.comment)
+           ,''::text
+     )
+) AS narrative
+,
+    c_ast.fk_encounter AS pk_encounter
+,
+    NULL::integer AS pk_episode
+,
+    NULL::integer AS pk_health_issue
+,
+    c_ast.pk AS src_pk
+,
+    'clin.allergy_state'::text AS src_table
+,
+    c_ast.row_version
+,
+    NULL::text AS health_issue
+,
+    NULL::text AS issue_laterality
+,
+    NULL::boolean AS issue_active
+,
+    NULL::boolean AS issue_clinically_relevant
+,
+    NULL::boolean AS issue_confidential
+,
+    NULL::text AS episode
+,
+    NULL::boolean AS episode_open
+,
+    c_enc.started AS encounter_started
+,
+    c_enc.last_affirmed AS encounter_last_affirmed
+,
+    c_ety.description AS encounter_type
+,
+    _
+(c_ety.description) AS encounter_l10n_type
+   
+FROM (
+     (clin.allergy_state c_ast
+     
+        JOIN clin.encounter c_enc 
+          ON (
+                 (c_ast.fk_encounter = c_enc.pk)
+           )
+     )
+     
+  JOIN clin.encounter_type c_ety 
+    ON (
+           (c_enc.fk_type = c_ety.pk)
+     )
+)
+UNION ALL
+ 
+SELECT c_enc.fk_patient AS pk_patient
+,
+    now
+() AS modified_when
+,
+    now
+() AS clin_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_ast.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (c_ast.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    'o'::text AS soap_cat
+,
+    
+(
+     (
+           (
+                 (
+                       (
+                             (
+                                   (
+                                         (
+                                               (_
+                                                     ('Allergy state'::text) || 
+                                                  ' ('::text) || _
+                                                     ('copy'::text)
+                                               ) || 
+                                     '): '::text
+                                   ) ||
+        CASE
+            WHEN 
+                                   (c_ast.has_allergy IS NULL) THEN _
+                                   (
+                        'unknown, unasked'::text
+                                   )
+            WHEN 
+                                   (c_ast.has_allergy = 0) THEN _
+                                   ('no known allergies'::text)
+            WHEN 
+                                   (c_ast.has_allergy = 1) THEN _
+                                   ('does have allergies'::text)
+            ELSE NULL::text
+        END
+                             ) || COALESCE
+                             (
+                                   ('
+ '::text || c_ast.comment)
+                                   ,''::text
+                             )
+                       ) || COALESCE
+                       (
+                             (
+                                   ('
+ '::text || _
+                                         ('last confirmed'::text)
+                                   ) || to_char
+                                   (c_ast.last_confirmed
+                                         ,' YYYY-MM-DD HH24:MI'::text
+                                   )
+                             )
+                             ,''::text
+                       )
+                 ) || COALESCE
+                 (
+                       (
+                             ('
+ '::text || _
+                                   ('entry last modified'::text)
+                             ) || to_char
+                             (c_ast.modified_when
+                                   ,' YYYY-MM-DD HH24:MI'::text
+                             )
+                       )
+                       ,''::text
+                 )
+           ) || COALESCE
+           (
+                 (
+                       ('
+ '::text || _
+                             ('encounter started'::text)
+                       ) || to_char
+                       (c_enc.started
+                             ,' YYYY-MM-DD HH24:MI'::text
+                       )
+                 )
+                 ,''::text
+           )
+     ) || COALESCE
+     (
+           (
+                 ('
+ '::text || _
+                       ('encounter last affirmed'::text)
+                 ) || to_char
+                 (c_enc.last_affirmed
+                       ,' YYYY-MM-DD HH24:MI'::text
+                 )
+           )
+           ,''::text
+     )
+) AS narrative
+,
+    c_ast.fk_encounter AS pk_encounter
+,
+    NULL::integer AS pk_episode
+,
+    NULL::integer AS pk_health_issue
+,
+    c_ast.pk AS src_pk
+,
+    'clin.allergy_state'::text AS src_table
+,
+    c_ast.row_version
+,
+    NULL::text AS health_issue
+,
+    NULL::text AS issue_laterality
+,
+    NULL::boolean AS issue_active
+,
+    NULL::boolean AS issue_clinically_relevant
+,
+    NULL::boolean AS issue_confidential
+,
+    NULL::text AS episode
+,
+    NULL::boolean AS episode_open
+,
+    now
+() AS encounter_started
+,
+    now
+() AS encounter_last_affirmed
+,
+    c_ety.description AS encounter_type
+,
+    _
+(c_ety.description) AS encounter_l10n_type
+   
+FROM (
+     (clin.allergy_state c_ast
+     
+        JOIN clin.encounter c_enc 
+          ON (
+                 (c_ast.fk_encounter = c_enc.pk)
+           )
+     )
+     
+  JOIN clin.encounter_type c_ety 
+    ON (
+           (c_enc.fk_type = c_ety.pk)
+     )
+);</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-encounters">v_pat_encounters</a>
+		</h2>
+        
+         <p>Details on encounters.</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.v_pat_encounters Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>external_code_brand</td>
-            	<td>unknown</td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -70446,8 +84778,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>external_code_type_brand</td>
-            	<td>unknown</td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -70478,8 +84810,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>intake_is_approved_of</td>
-            	<td>boolean</td>
+            	<td>type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -70494,7 +84826,7 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>schedule</td>
+            	<td>l10n_type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -70510,8 +84842,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>duration</td>
-            	<td>interval</td>
+            	<td>reason_for_encounter</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -70526,8 +84858,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>discontinued</td>
-            	<td>timestamp with time zone</td>
+            	<td>assessment_of_encounter</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -70542,8 +84874,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>discontinue_reason</td>
-            	<td>text</td>
+            	<td>last_affirmed</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -70558,8 +84890,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>is_long_term</td>
-            	<td>boolean</td>
+            	<td>source_time_zone</td>
+            	<td>interval</td>
                 <td><i>
 				
 
@@ -70574,8 +84906,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>aim</td>
-            	<td>text</td>
+            	<td>started_original_tz</td>
+            	<td>timestamp without time zone</td>
                 <td><i>
 				
 
@@ -70590,8 +84922,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>episode</td>
-            	<td>text</td>
+            	<td>last_affirmed_original_tz</td>
+            	<td>timestamp without time zone</td>
                 <td><i>
 				
 
@@ -70606,7 +84938,7 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>health_issue</td>
+            	<td>praxis_branch</td>
             	<td>text</td>
                 <td><i>
 				
@@ -70622,7 +84954,7 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>notes</td>
+            	<td>praxis</td>
             	<td>text</td>
                 <td><i>
 				
@@ -70638,8 +84970,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>fake_brand</td>
-            	<td>unknown</td>
+            	<td>pk_org_unit</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -70654,8 +84986,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>is_currently_active</td>
-            	<td>boolean</td>
+            	<td>pk_org</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -70670,8 +85002,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>seems_inactive</td>
-            	<td>boolean</td>
+            	<td>pk_unit_type</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -70686,8 +85018,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>pk_brand</td>
-            	<td>unknown</td>
+            	<td>pk_org_type</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -70702,8 +85034,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>pk_data_source</td>
-            	<td>unknown</td>
+            	<td>pk_type</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -70718,8 +85050,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>pk_substance</td>
-            	<td>integer</td>
+            	<td>pk_generic_codes_rfe</td>
+            	<td>integer[]</td>
                 <td><i>
 				
 
@@ -70734,8 +85066,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>pk_drug_component</td>
-            	<td>unknown</td>
+            	<td>pk_generic_codes_aoe</td>
+            	<td>integer[]</td>
                 <td><i>
 				
 
@@ -70750,8 +85082,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>xmin_encounter</td>
+            	<td>xid</td>
                 <td><i>
 				
 
@@ -70766,7 +85098,7 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
+            	<td>row_version</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -70782,7 +85114,7 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
+            	<td>pk_audit</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -70814,7 +85146,7 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
+            	<td>modified_by_raw</td>
             	<td>name</td>
                 <td><i>
 				
@@ -70830,24 +85162,8 @@ WHERE (btrim
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>xmin_substance_intake</td>
-            	<td>xid</td>
+            	<td>modified_by</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -70877,87 +85193,148 @@ WHERE (btrim
 	<!-- View Definition -->
 	
 	<pre>
-SELECT c_si.pk AS pk_substance_intake
-, (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
- WHERE (encounter.pk = c_si.fk_encounter)
-) AS pk_patient
-, c_si.soap_cat
-, NULL::unknown AS brand
-, c_si.preparation
-, r_cs.description AS substance
-, r_cs.amount
-, r_cs.unit
-, r_cs.atc_code AS atc_substance
-, NULL::unknown AS atc_brand
-, NULL::unknown AS external_code_brand
-, NULL::unknown AS external_code_type_brand
-, c_si.clin_when AS started
-, c_si.intake_is_approved_of
-, c_si.schedule
-, c_si.duration
-, c_si.discontinued
-, c_si.discontinue_reason
-, c_si.is_long_term
-, c_si.aim
-, cep.description AS episode
-, c_hi.description AS health_issue
-, c_si.narrative AS notes
-, NULL::unknown AS fake_brand
-, CASE WHEN 
-(c_si.discontinued IS NULL) THEN true ELSE false END AS is_currently_active
-, CASE WHEN 
-(c_si.discontinued IS NOT NULL) THEN true WHEN 
-(c_si.clin_when IS NULL) THEN CASE WHEN 
-(c_si.is_long_term IS TRUE) THEN false ELSE NULL::boolean END WHEN 
+SELECT c_enc.pk AS pk_encounter
+,
+    c_enc.fk_patient AS pk_patient
+,
+    c_enc.started
+,
+    c_et.description AS type
+,
+    _
+(c_et.description) AS l10n_type
+,
+    c_enc.reason_for_encounter
+,
+    c_enc.assessment_of_encounter
+,
+    c_enc.last_affirmed
+,
+    c_enc.source_time_zone
+,
+    
 (
-     (c_si.clin_when > now
-           ()
-     ) IS TRUE
-) THEN true WHEN 
+SELECT timezone
+     (
+           (
+            SELECT c_enc1.source_time_zone
+                   
+              FROM clin.encounter c_enc1
+                  
+             WHERE (c_enc1.pk = c_enc.pk)
+           )
+           , c_enc.started
+     ) AS timezone
+) AS started_original_tz
+,
+    
 (
+SELECT timezone
      (
-           (c_si.clin_when + c_si.duration) < now
-           ()
-     ) IS TRUE
-) THEN true WHEN 
+           (
+            SELECT c_enc1.source_time_zone
+                   
+              FROM clin.encounter c_enc1
+                  
+             WHERE (c_enc1.pk = c_enc.pk)
+           )
+           , c_enc.last_affirmed
+     ) AS timezone
+) AS last_affirmed_original_tz
+,
+    COALESCE
+(d_ou.description
+     ,'?'::text
+) AS praxis_branch
+,
+    COALESCE
+(d_o.description
+     ,'?'::text
+) AS praxis
+,
+    c_enc.fk_location AS pk_org_unit
+,
+    d_ou.fk_org AS pk_org
+,
+    d_ou.fk_category AS pk_unit_type
+,
+    d_o.fk_category AS pk_org_type
+,
+    c_enc.fk_type AS pk_type
+,
+    COALESCE
 (
      (
-           (c_si.clin_when + c_si.duration) > now
-           ()
-     ) IS TRUE
-) THEN false ELSE NULL::boolean END AS seems_inactive
-, NULL::unknown AS pk_brand
-, NULL::unknown AS pk_data_source
-, r_cs.pk AS pk_substance
-, NULL::unknown AS pk_drug_component
-, c_si.fk_encounter AS pk_encounter
-, c_si.fk_episode AS pk_episode
-, cep.fk_health_issue AS pk_health_issue
-, c_si.modified_when
-, c_si.modified_by
-, c_si.row_version
-, c_si.xmin AS xmin_substance_intake 
+      SELECT array_agg
+           (c_lc2r.fk_generic_code) AS array_agg
+           
+        FROM clin.lnk_code2rfe c_lc2r
+          
+       WHERE (c_lc2r.fk_item = c_enc.pk)
+     )
+     , ARRAY[]::integer[]
+) AS pk_generic_codes_rfe
+,
+    COALESCE
+(
+     (
+      SELECT array_agg
+           (c_lc2a.fk_generic_code) AS array_agg
+           
+        FROM clin.lnk_code2aoe c_lc2a
+          
+       WHERE (c_lc2a.fk_item = c_enc.pk)
+     )
+     , ARRAY[]::integer[]
+) AS pk_generic_codes_aoe
+,
+    c_enc.xmin AS xmin_encounter
+,
+    c_enc.row_version
+,
+    c_enc.pk_audit
+,
+    c_enc.modified_when
+,
+    c_enc.modified_by AS modified_by_raw
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_enc.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (c_enc.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+   
 FROM (
      (
-           (clin.substance_intake c_si 
-              JOIN ref.consumable_substance r_cs 
+           (clin.encounter c_enc
+     
+         LEFT JOIN clin.encounter_type c_et 
                 ON (
-                       (c_si.fk_substance = r_cs.pk)
+                       (c_enc.fk_type = c_et.pk)
                  )
            )
-   LEFT JOIN clin.episode cep 
+     
+   LEFT JOIN dem.org_unit d_ou 
           ON (
-                 (c_si.fk_episode = cep.pk)
+                 (c_enc.fk_location = d_ou.pk)
            )
      )
-LEFT JOIN clin.health_issue c_hi 
+     
+LEFT JOIN dem.org d_o 
     ON (
-           (c_hi.pk = cep.fk_health_issue)
+           (d_ou.fk_org = d_o.pk)
      )
-)
-WHERE (c_si.fk_drug_component IS NULL);</pre>
+);</pre>
 	
 
 	<!-- List off permissions -->
@@ -70971,15 +85348,13 @@ WHERE (c_si.fk_drug_component IS NULL);</pre>
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-allergies">v_pat_allergies</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-encounters-journal">v_pat_encounters_journal</a>
 		</h2>
         
-         <p>denormalizes clin.allergy</p>
-        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_pat_allergies Structure</caption>
+                <caption>clin.v_pat_encounters_journal Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -70991,22 +85366,6 @@ WHERE (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_allergy</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
             	<td>pk_patient</td>
             	<td>integer</td>
                 <td><i>
@@ -71019,92 +85378,12 @@ WHERE (c_si.fk_drug_component IS NULL);</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>descriptor</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>allergene</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>substance</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>substance_code</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
             <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>generics</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -71119,8 +85398,8 @@ WHERE (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>generic_specific</td>
-            	<td>boolean</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -71135,7 +85414,7 @@ WHERE (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>atc_code</td>
+            	<td>modified_by</td>
             	<td>text</td>
                 <td><i>
 				
@@ -71151,23 +85430,7 @@ WHERE (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>type</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>l10n_type</td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -71179,27 +85442,11 @@ WHERE (c_si.fk_drug_component IS NULL);</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>definite</td>
-            	<td>boolean</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
             <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>reaction</td>
+            	<td>narrative</td>
             	<td>text</td>
                 <td><i>
 				
@@ -71215,7 +85462,7 @@ WHERE (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_type</td>
+            	<td>pk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -71231,7 +85478,7 @@ WHERE (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
+            	<td>pk_episode</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -71247,22 +85494,6 @@ WHERE (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>date</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
             	<td>pk_health_issue</td>
             	<td>integer</td>
                 <td><i>
@@ -71275,27 +85506,11 @@ WHERE (c_si.fk_drug_component IS NULL);</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
             <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
+            	<td>src_pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -71311,8 +85526,8 @@ WHERE (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>src_table</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -71327,24 +85542,8 @@ WHERE (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>xmin_allergy</td>
-            	<td>xid</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -71355,99 +85554,12 @@ WHERE (c_si.fk_drug_component IS NULL);</pre>
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT a.pk AS pk_allergy
-, (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
- WHERE (encounter.pk = a.fk_encounter)
-) AS pk_patient
-, a.soap_cat
-, CASE WHEN 
-(COALESCE
-     (btrim
-           (a.allergene)
-           ,''::text
-     ) = ''::text
-) THEN a.substance ELSE a.allergene END AS descriptor
-, a.allergene
-, a.substance
-, a.substance_code
-, a.generics
-, a.generic_specific
-, a.atc_code
-, at.value AS type
-, _
-(at.value) AS l10n_type
-, a.definite
-, a.narrative AS reaction
-, a.fk_type AS pk_type
-, a.pk_item
-, a.clin_when AS date
-, (
-SELECT episode.fk_health_issue 
-  FROM clin.episode 
- WHERE (episode.pk = a.fk_episode)
-) AS pk_health_issue
-, a.fk_episode AS pk_episode
-, a.fk_encounter AS pk_encounter
-, a.modified_when
-, a.modified_by
-, a.xmin AS xmin_allergy 
-FROM clin.allergy a
-, clin._enum_allergy_type at 
-WHERE (at.pk = a.fk_type);</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-allergies-journal">v_pat_allergies_journal</a>
-		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_pat_allergies_journal Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -71462,8 +85574,8 @@ WHERE (at.pk = a.fk_type);</pre>
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>issue_laterality</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -71478,8 +85590,8 @@ WHERE (at.pk = a.fk_type);</pre>
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -71494,8 +85606,8 @@ WHERE (at.pk = a.fk_type);</pre>
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>text</td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -71510,8 +85622,8 @@ WHERE (at.pk = a.fk_type);</pre>
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -71526,7 +85638,7 @@ WHERE (at.pk = a.fk_type);</pre>
 				<td>
                 
                 </td>
-            	<td>narrative</td>
+            	<td>episode</td>
             	<td>text</td>
                 <td><i>
 				
@@ -71542,8 +85654,8 @@ WHERE (at.pk = a.fk_type);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -71558,8 +85670,8 @@ WHERE (at.pk = a.fk_type);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -71574,8 +85686,8 @@ WHERE (at.pk = a.fk_type);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
-            	<td>integer</td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -71590,8 +85702,8 @@ WHERE (at.pk = a.fk_type);</pre>
 				<td>
                 
                 </td>
-            	<td>src_pk</td>
-            	<td>integer</td>
+            	<td>encounter_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -71606,7 +85718,7 @@ WHERE (at.pk = a.fk_type);</pre>
 				<td>
                 
                 </td>
-            	<td>src_table</td>
+            	<td>encounter_l10n_type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -71637,28 +85749,32 @@ WHERE (at.pk = a.fk_type);</pre>
 	<!-- View Definition -->
 	
 	<pre>
-SELECT (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
- WHERE (encounter.pk = a.fk_encounter)
-) AS pk_patient
-, a.modified_when
-, a.clin_when
-, COALESCE
+SELECT c_enc.fk_patient AS pk_patient
+,
+    c_enc.modified_when
+,
+    c_enc.started AS clin_when
+,
+    COALESCE
 (
      (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.db_user = a.modified_by)
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_enc.modified_by)
      )
      , (
            ('<'::text || 
-                 (a.modified_by)::text
+                 (c_enc.modified_by)::text
            ) || '>'::text
      )
 ) AS modified_by
-, a.soap_cat
-, (
+,
+    NULL::text AS soap_cat
+,
+    
+(
      (
            (
                  (
@@ -71666,34 +85782,108 @@ SELECT encounter.fk_patient
                              (
                                    (
                                          (
+                                               (_
+                                                     ('Encounter'::text) || ': '::text
+                                               ) || 
+                                               (
+                                                SELECT _
+                                                     (encounter_type.description) AS _
+           
+                                                  FROM clin.encounter_type
+          
+                                                 WHERE (encounter_type.pk = c_enc.fk_type)
+                                               )
+                                         ) || to_char
+                                         (c_enc.started
+                                               ,' YYYY-MM-DD HH24:MI'::text
+                                         )
+                                   ) || to_char
+                                   (c_enc.last_affirmed
+                                         ,' - HH24:MI'::text
+                                   )
+                             ) || COALESCE
+                             (
+                                   (
+                                         (
                                                (
                                                      (
                                                            (
-                                                                 (_
-                                                                       ('Allergy'::text) || 
-                                                                    ' ('::text) || _
-                                                                       (at.value)
-                                                                 ) || 
-                                                       '): '::text
-                                                     ) || COALESCE
-                                                     (a.narrative
-                                                           ,''::text
-                                                     )
-                                               ) || '
-'::text
-                                         ) || _
-                                         ('substance'::text)
-                                   ) || ': '::text
-                             ) || a.substance
-                       ) || '; '::text
+                                                                 (
+                                                                       (
+                                                                             ('
+ @ '::text || _
+                                                                                   ('branch'::text)
+                                                                             ) || ' "'::text
+                                                                       ) || d_ou.description
+                                                                 ) || '" '::text
+                                                           ) || _
+                                                           ('of'::text)
+                                                     ) || ' "'::text
+                                               ) || d_o.description
+                                         ) || '"'::text
+                                   )
+                                   ,''::text
+                             )
+                       ) || COALESCE
+                       (
+                             (
+                                   (
+                                         ('
+ '::text || _
+                                               ('RFE'::text)
+                                         ) || ': '::text
+                                   ) || c_enc.reason_for_encounter
+                             )
+                             ,''::text
+                       )
                  ) || COALESCE
                  (
                        (
-                             (
-                                   (_
-                                         ('allergene'::text) || ': '::text
-                                   ) || a.allergene
-                             ) || '; '::text
+                             ('
+'::text || array_to_string
+                                   (
+                                         (
+                                          SELECT array_agg
+                                               (
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (
+                                                                             (
+                                                                                   (
+                                                                                         (
+                                                                                               (r_csr.code || 
+                                                                                                  ' ('::text) || r_ds.name_short
+                                                                                               ) || ' - '::text
+                                                                                         ) || r_ds.version
+                                                                                   ) || ' - '::text
+                                                                             ) || r_ds.lang
+                                                                       ) || 
+                                                             '): '::text
+                                                           ) || r_csr.term
+                                                     )
+                                               ) AS array_agg
+           
+                                            FROM (
+                                                     (clin.lnk_code2rfe c_lc2r
+             
+                                                        JOIN ref.coding_system_root r_csr 
+                                                          ON (
+                                                                 (c_lc2r.fk_generic_code = r_csr.pk_coding_system)
+                                                           )
+                                                     )
+             
+                                                  JOIN ref.data_source r_ds 
+                                                    ON (
+                                                           (r_ds.pk = r_csr.fk_data_source)
+                                                     )
+                                               )
+          
+                                           WHERE (c_lc2r.fk_item = c_enc.pk)
+                                         )
+                                         ,'; '::text
+                                   )
+                             ) || ';'::text
                        )
                        ,''::text
                  )
@@ -71701,37 +85891,123 @@ SELECT encounter.fk_patient
            (
                  (
                        (
-                             (_
-                                   ('generic'::text) || ': '::text
-                             ) || a.generics
-                       ) || '; '::text
+                             ('
+ '::text || _
+                                   ('AOE'::text)
+                             ) || ': '::text
+                       ) || c_enc.assessment_of_encounter
                  )
                  ,''::text
            )
      ) || COALESCE
      (
            (
-                 (
-                       (_
-                             ('ATC code'::text) || ': '::text
-                       ) || a.atc_code
-                 ) || '; '::text
+                 ('
+'::text || array_to_string
+                       (
+                             (
+                              SELECT array_agg
+                                   (
+                                         (
+                                               (
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (
+                                                                             (
+                                                                                   (r_csr.code || 
+                                                                                      ' ('::text) || r_ds.name_short
+                                                                                   ) || ' - '::text
+                                                                             ) || r_ds.version
+                                                                       ) || ' - '::text
+                                                                 ) || r_ds.lang
+                                                           ) || 
+                                                 '): '::text
+                                               ) || r_csr.term
+                                         )
+                                   ) AS array_agg
+           
+                                FROM (
+                                         (clin.lnk_code2aoe c_lc2a
+             
+                                            JOIN ref.coding_system_root r_csr 
+                                              ON (
+                                                     (c_lc2a.fk_generic_code = r_csr.pk_coding_system)
+                                               )
+                                         )
+             
+                                      JOIN ref.data_source r_ds 
+                                        ON (
+                                               (r_ds.pk = r_csr.fk_data_source)
+                                         )
+                                   )
+          
+                               WHERE (c_lc2a.fk_item = c_enc.pk)
+                             )
+                             ,'; '::text
+                       )
+                 ) || ';'::text
            )
            ,''::text
      )
 ) AS narrative
-, a.fk_encounter AS pk_encounter
-, a.fk_episode AS pk_episode
-, (
-SELECT episode.fk_health_issue 
-  FROM clin.episode 
- WHERE (episode.pk = a.fk_episode)
-) AS pk_health_issue
-, a.pk AS src_pk
-,'clin.allergy'::text AS src_table 
-FROM clin.allergy a
-, clin._enum_allergy_type at 
-WHERE (at.pk = a.fk_type);</pre>
+,
+    c_enc.pk AS pk_encounter
+,
+    NULL::integer AS pk_episode
+,
+    NULL::integer AS pk_health_issue
+,
+    c_enc.pk AS src_pk
+,
+    'clin.encounter'::text AS src_table
+,
+    c_enc.row_version
+,
+    NULL::text AS health_issue
+,
+    NULL::text AS issue_laterality
+,
+    NULL::boolean AS issue_active
+,
+    NULL::boolean AS issue_clinically_relevant
+,
+    NULL::boolean AS issue_confidential
+,
+    NULL::text AS episode
+,
+    NULL::boolean AS episode_open
+,
+    c_enc.started AS encounter_started
+,
+    c_enc.last_affirmed AS encounter_last_affirmed
+,
+    c_ety.description AS encounter_type
+,
+    _
+(c_ety.description) AS encounter_l10n_type
+   
+FROM (
+     (
+           (clin.encounter c_enc
+     
+              JOIN clin.encounter_type c_ety 
+                ON (
+                       (c_enc.fk_type = c_ety.pk)
+                 )
+           )
+     
+   LEFT JOIN dem.org_unit d_ou 
+          ON (
+                 (c_enc.fk_location = d_ou.pk)
+           )
+     )
+     
+LEFT JOIN dem.org d_o 
+    ON (
+           (d_ou.fk_org = d_o.pk)
+     )
+);</pre>
 	
 
 	<!-- List off permissions -->
@@ -71745,13 +86021,13 @@ WHERE (at.pk = a.fk_type);</pre>
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-allergy-state">v_pat_allergy_state</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-episodes">v_pat_episodes</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_pat_allergy_state Structure</caption>
+                <caption>clin.v_pat_episodes Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -71779,8 +86055,8 @@ WHERE (at.pk = a.fk_type);</pre>
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>description</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -71795,7 +86071,7 @@ WHERE (at.pk = a.fk_type);</pre>
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
+            	<td>summary</td>
             	<td>text</td>
                 <td><i>
 				
@@ -71811,8 +86087,8 @@ WHERE (at.pk = a.fk_type);</pre>
 				<td>
                 
                 </td>
-            	<td>last_confirmed</td>
-            	<td>timestamp with time zone</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -71827,8 +86103,8 @@ WHERE (at.pk = a.fk_type);</pre>
 				<td>
                 
                 </td>
-            	<td>has_allergy</td>
-            	<td>integer</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -71843,8 +86119,8 @@ WHERE (at.pk = a.fk_type);</pre>
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -71859,8 +86135,8 @@ WHERE (at.pk = a.fk_type);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -71875,24 +86151,8 @@ WHERE (at.pk = a.fk_type);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_allergy_state</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>xmin_allergy_state</td>
-            	<td>xid</td>
+            	<td>started_first</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -71903,84 +86163,12 @@ WHERE (at.pk = a.fk_type);</pre>
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
- WHERE (encounter.pk = a.fk_encounter)
-) AS pk_patient
-, a.modified_when
-, COALESCE
-(
-     (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.db_user = a.modified_by)
-     )
-     , (
-           ('<'::text || 
-                 (a.modified_by)::text
-           ) || '>'::text
-     )
-) AS modified_by
-, a.last_confirmed
-, a.has_allergy
-, a.comment
-, a.fk_encounter AS pk_encounter
-, a.pk AS pk_allergy_state
-, a.xmin AS xmin_allergy_state 
-FROM clin.allergy_state a;</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-allergy-state-journal">v_pat_allergy_state_journal</a>
-		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_pat_allergy_state_journal Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>started_last</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -71995,7 +86183,7 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
+            	<td>last_affirmed</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
@@ -72011,8 +86199,8 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -72027,8 +86215,8 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>text</td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -72043,8 +86231,8 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -72059,8 +86247,8 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>narrative</td>
-            	<td>text</td>
+            	<td>episode_modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -72075,8 +86263,8 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>episode_modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
@@ -72091,8 +86279,8 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>diagnostic_certainty_classification</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -72107,8 +86295,8 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
-            	<td>integer</td>
+            	<td>diagnostic_certainty_classification_issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -72123,8 +86311,8 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>src_pk</td>
-            	<td>integer</td>
+            	<td>pk_generic_codes</td>
+            	<td>integer[]</td>
                 <td><i>
 				
 
@@ -72139,24 +86327,8 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>src_table</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>xmin_episode</td>
+            	<td>xid</td>
                 <td><i>
 				
 
@@ -72186,74 +86358,183 @@ FROM clin.allergy_state a;</pre>
 	<!-- View Definition -->
 	
 	<pre>
-SELECT (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
- WHERE (encounter.pk = a.fk_encounter)
-) AS pk_patient
-, a.modified_when
-, COALESCE
-(a.last_confirmed
-     , a.modified_when
-) AS clin_when
-, COALESCE
+SELECT cenc.fk_patient AS pk_patient
+,
+    cep.description
+,
+    cep.summary
+,
+    cep.is_open AS episode_open
+,
+    NULL::text AS health_issue
+,
+    NULL::boolean AS issue_active
+,
+    NULL::boolean AS issue_clinically_relevant
+,
+    
+(
+SELECT min
+     (cle.started) AS min
+           
+  FROM clin.encounter cle
+          
+ WHERE (cle.pk = cep.fk_encounter)
+         LIMIT 1
+) AS started_first
+,
+    
+(
+SELECT max
+     (cle.started) AS max
+           
+  FROM clin.encounter cle
+          
+ WHERE (cle.pk = cep.fk_encounter)
+         LIMIT 1
+) AS started_last
+,
+    
+(
+SELECT max
+     (cle.last_affirmed) AS max
+           
+  FROM clin.encounter cle
+          
+ WHERE (cle.pk = cep.fk_encounter)
+         LIMIT 1
+) AS last_affirmed
+,
+    cep.pk AS pk_episode
+,
+    cep.fk_encounter AS pk_encounter
+,
+    NULL::integer AS pk_health_issue
+,
+    cep.modified_when AS episode_modified_when
+,
+    cep.modified_by AS episode_modified_by
+,
+    cep.diagnostic_certainty_classification
+,
+    NULL::text AS diagnostic_certainty_classification_issue
+,
+    COALESCE
 (
      (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.db_user = a.modified_by)
+      SELECT array_agg
+           (c_lc2e.fk_generic_code) AS array_agg
+           
+        FROM clin.lnk_code2episode c_lc2e
+          
+       WHERE (c_lc2e.fk_item = cep.pk)
      )
-     , (
-           ('<'::text || 
-                 (a.modified_by)::text
-           ) || '>'::text
+     , ARRAY[]::integer[]
+) AS pk_generic_codes
+,
+    cep.xmin AS xmin_episode
+   
+FROM (clin.episode cep
+     
+  JOIN clin.encounter cenc 
+    ON (
+           (cep.fk_encounter = cenc.pk)
      )
-) AS modified_by
-,'o'::text AS soap_cat
-, (
+)
+  
+WHERE (cep.fk_health_issue IS NULL)
+UNION ALL
+ 
+SELECT cenc.fk_patient AS pk_patient
+,
+    cep.description
+,
+    cep.summary
+,
+    cep.is_open AS episode_open
+,
+    chi.description AS health_issue
+,
+    chi.is_active AS issue_active
+,
+    chi.clinically_relevant AS issue_clinically_relevant
+,
+    
+(
+SELECT min
+     (cle.started) AS min
+           
+  FROM clin.encounter cle
+          
+ WHERE (cle.pk = cep.fk_encounter)
+         LIMIT 1
+) AS started_first
+,
+    
+(
+SELECT max
+     (cle.started) AS max
+           
+  FROM clin.encounter cle
+          
+ WHERE (cle.pk = cep.fk_encounter)
+         LIMIT 1
+) AS started_last
+,
+    
+(
+SELECT max
+     (cle.last_affirmed) AS max
+           
+  FROM clin.encounter cle
+          
+ WHERE (cle.pk = cep.fk_encounter)
+         LIMIT 1
+) AS last_affirmed
+,
+    cep.pk AS pk_episode
+,
+    cep.fk_encounter AS pk_encounter
+,
+    cep.fk_health_issue AS pk_health_issue
+,
+    cep.modified_when AS episode_modified_when
+,
+    cep.modified_by AS episode_modified_by
+,
+    cep.diagnostic_certainty_classification
+,
+    chi.diagnostic_certainty_classification AS diagnostic_certainty_classification_issue
+,
+    COALESCE
+(
      (
-           (
-                 (_
-                       ('Allergy state'::text) || ': '::text
-                 ) || CASE WHEN 
-                 (a.has_allergy IS NULL) THEN _
-                 (
-      'unknown, unasked'::text
-                 ) WHEN 
-                 (a.has_allergy = 0) THEN _
-                 ('no known allergies'::text) WHEN 
-                 (a.has_allergy = 1) THEN _
-                 ('does have allergies'::text) ELSE NULL::text END
-           ) || COALESCE
-           (
-                 (
-                       (
-                             (
-                                ' ('::text || _
-                                         ('last confirmed'::text)
-                                   ) || to_char
-                                   (a.last_confirmed
-                                         ,' YYYY-MM-DD HH24:MI'::text
-                                   )
-                             ) || 
-                     ')'::text
-                 )
-                 ,''::text
+      SELECT array_agg
+           (c_lc2e.fk_generic_code) AS array_agg
+           
+        FROM clin.lnk_code2episode c_lc2e
+          
+       WHERE (c_lc2e.fk_item = cep.pk)
+     )
+     , ARRAY[]::integer[]
+) AS pk_generic_codes
+,
+    cep.xmin AS xmin_episode
+   
+FROM (
+     (clin.episode cep
+     
+        JOIN clin.encounter cenc 
+          ON (
+                 (cep.fk_encounter = cenc.pk)
            )
-     ) || COALESCE
-     (
-           ('
- '::text || a.comment)
-           ,''::text
      )
-) AS narrative
-, a.fk_encounter AS pk_encounter
-, NULL::integer AS pk_episode
-, NULL::integer AS pk_health_issue
-, a.pk AS src_pk
-,'clin.allergy_state'::text AS src_table
-, 0 AS row_version 
-FROM clin.allergy_state a;</pre>
+     
+  JOIN clin.health_issue chi 
+    ON (
+           (cep.fk_health_issue = chi.pk)
+     )
+);</pre>
 	
 
 	<!-- List off permissions -->
@@ -72267,15 +86548,13 @@ FROM clin.allergy_state a;</pre>
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-encounters">v_pat_encounters</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-episodes-journal">v_pat_episodes_journal</a>
 		</h2>
         
-         <p>Details on encounters.</p>
-        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_pat_encounters Structure</caption>
+                <caption>clin.v_pat_episodes_journal Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -72287,7 +86566,7 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
+            	<td>pk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -72303,8 +86582,8 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -72319,7 +86598,7 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>started</td>
+            	<td>clin_when</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
@@ -72335,7 +86614,7 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>type</td>
+            	<td>modified_by</td>
             	<td>text</td>
                 <td><i>
 				
@@ -72351,7 +86630,7 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>l10n_type</td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -72367,23 +86646,7 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>reason_for_encounter</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>assessment_of_encounter</td>
+            	<td>narrative</td>
             	<td>text</td>
                 <td><i>
 				
@@ -72395,28 +86658,12 @@ FROM clin.allergy_state a;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>last_affirmed</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>source_time_zone</td>
-            	<td>interval</td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -72431,8 +86678,8 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>started_original_tz</td>
-            	<td>timestamp without time zone</td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -72447,8 +86694,8 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>last_affirmed_original_tz</td>
-            	<td>timestamp without time zone</td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -72463,8 +86710,8 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>praxis_branch</td>
-            	<td>text</td>
+            	<td>src_pk</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -72479,7 +86726,7 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>praxis</td>
+            	<td>src_table</td>
             	<td>text</td>
                 <td><i>
 				
@@ -72495,7 +86742,7 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_org_unit</td>
+            	<td>row_version</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -72511,8 +86758,8 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_org</td>
-            	<td>integer</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -72527,8 +86774,8 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_unit_type</td>
-            	<td>integer</td>
+            	<td>issue_laterality</td>
+            	<td>character varying(2)</td>
                 <td><i>
 				
 
@@ -72543,8 +86790,8 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_org_type</td>
-            	<td>integer</td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -72559,8 +86806,8 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_type</td>
-            	<td>integer</td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -72575,8 +86822,8 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_generic_codes_rfe</td>
-            	<td>integer[]</td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -72591,24 +86838,8 @@ FROM clin.allergy_state a;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_generic_codes_aoe</td>
-            	<td>integer[]</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>xmin_encounter</td>
-            	<td>xid</td>
+            	<td>episode</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -72619,12 +86850,12 @@ FROM clin.allergy_state a;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -72635,12 +86866,12 @@ FROM clin.allergy_state a;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -72651,11 +86882,11 @@ FROM clin.allergy_state a;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
+            	<td>encounter_last_affirmed</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
@@ -72667,12 +86898,12 @@ FROM clin.allergy_state a;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>modified_by_raw</td>
-            	<td>name</td>
+            	<td>encounter_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -72683,11 +86914,11 @@ FROM clin.allergy_state a;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
+            	<td>encounter_l10n_type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -72718,105 +86949,179 @@ FROM clin.allergy_state a;</pre>
 	<!-- View Definition -->
 	
 	<pre>
-SELECT c_enc.pk AS pk_encounter
-, c_enc.fk_patient AS pk_patient
-, c_enc.started
-, c_et.description AS type
-, _
-(c_et.description) AS l10n_type
-, c_enc.reason_for_encounter
-, c_enc.assessment_of_encounter
-, c_enc.last_affirmed
-, c_enc.source_time_zone
-, (
-SELECT timezone
-     (
-           (
-            SELECT c_enc1.source_time_zone 
-              FROM clin.encounter c_enc1 
-             WHERE (c_enc1.pk = c_enc.pk)
-           )
-           , c_enc.started
-     ) AS timezone
-) AS started_original_tz
-, (
-SELECT timezone
-     (
-           (
-            SELECT c_enc1.source_time_zone 
-              FROM clin.encounter c_enc1 
-             WHERE (c_enc1.pk = c_enc.pk)
-           )
-           , c_enc.last_affirmed
-     ) AS timezone
-) AS last_affirmed_original_tz
-, COALESCE
-(d_ou.description
-     ,'?'::text
-) AS praxis_branch
-, COALESCE
-(d_o.description
-     ,'?'::text
-) AS praxis
-, c_enc.fk_location AS pk_org_unit
-, d_ou.fk_org AS pk_org
-, d_ou.fk_category AS pk_unit_type
-, d_o.fk_category AS pk_org_type
-, c_enc.fk_type AS pk_type
-, COALESCE
-(
-     (
-      SELECT array_agg
-           (c_lc2r.fk_generic_code) AS array_agg 
-        FROM clin.lnk_code2rfe c_lc2r 
-       WHERE (c_lc2r.fk_item = c_enc.pk)
-     )
-     , ARRAY[]::integer[]
-) AS pk_generic_codes_rfe
-, COALESCE
-(
-     (
-      SELECT array_agg
-           (c_lc2a.fk_generic_code) AS array_agg 
-        FROM clin.lnk_code2aoe c_lc2a 
-       WHERE (c_lc2a.fk_item = c_enc.pk)
-     )
-     , ARRAY[]::integer[]
-) AS pk_generic_codes_aoe
-, c_enc.xmin AS xmin_encounter
-, c_enc.row_version
-, c_enc.pk_audit
-, c_enc.modified_when
-, c_enc.modified_by AS modified_by_raw
-, COALESCE
+SELECT c_enc.fk_patient AS pk_patient
+,
+    c_epi.modified_when
+,
+    c_enc.started AS clin_when
+,
+    COALESCE
 (
      (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.db_user = c_enc.modified_by)
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_epi.modified_by)
      )
      , (
            ('<'::text || 
-                 (c_enc.modified_by)::text
+                 (c_epi.modified_by)::text
            ) || '>'::text
      )
-) AS modified_by 
+) AS modified_by
+,
+    'a'::text AS soap_cat
+,
+    
+(
+     (
+           (
+                 (
+                       (
+                             (
+                                   (
+                                         (_
+                                               ('Episode'::text) || 
+                                            ' ('::text) ||
+        CASE
+            WHEN c_epi.is_open THEN _
+                                               ('open'::text)
+            ELSE _
+                                               ('closed'::text)
+        END
+                                         ) || COALESCE
+                                         (
+                                               (
+                                                  ', '::text || c_epi.diagnostic_certainty_classification
+                                               )
+                                               ,''::text
+                                         )
+                                   ) || 
+                         '): '::text
+                       ) || c_epi.description
+                 ) || ';'::text
+           ) || COALESCE
+           (
+                 (
+                       (
+                             (
+                                   ('
+ '::text || _
+                                         ('Synopsis'::text)
+                                   ) || ': '::text
+                             ) || c_epi.summary
+                       ) || ';'::text
+                 )
+                 ,''::text
+           )
+     ) || COALESCE
+     (
+           (
+                 ('
+'::text || array_to_string
+                       (
+                             (
+                              SELECT array_agg
+                                   (
+                                         (
+                                               (
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (
+                                                                             (
+                                                                                   (r_csr.code || 
+                                                                                      ' ('::text) || r_ds.name_short
+                                                                                   ) || ' - '::text
+                                                                             ) || r_ds.version
+                                                                       ) || ' - '::text
+                                                                 ) || r_ds.lang
+                                                           ) || 
+                                                 '): '::text
+                                               ) || r_csr.term
+                                         )
+                                   ) AS array_agg
+           
+                                FROM (
+                                         (clin.lnk_code2episode c_lc2e
+             
+                                            JOIN ref.coding_system_root r_csr 
+                                              ON (
+                                                     (c_lc2e.fk_generic_code = r_csr.pk_coding_system)
+                                               )
+                                         )
+             
+                                      JOIN ref.data_source r_ds 
+                                        ON (
+                                               (r_ds.pk = r_csr.fk_data_source)
+                                         )
+                                   )
+          
+                               WHERE (c_lc2e.fk_item = c_epi.pk)
+                             )
+                             ,'; '::text
+                       )
+                 ) || ';'::text
+           )
+           ,''::text
+     )
+) AS narrative
+,
+    c_epi.fk_encounter AS pk_encounter
+,
+    c_epi.pk AS pk_episode
+,
+    c_epi.fk_health_issue AS pk_health_issue
+,
+    c_epi.pk AS src_pk
+,
+    'clin.episode'::text AS src_table
+,
+    c_epi.row_version
+,
+    c_hi.description AS health_issue
+,
+    c_hi.laterality AS issue_laterality
+,
+    c_hi.is_active AS issue_active
+,
+    c_hi.clinically_relevant AS issue_clinically_relevant
+,
+    c_hi.is_confidential AS issue_confidential
+,
+    c_epi.description AS episode
+,
+    c_epi.is_open AS episode_open
+,
+    c_enc.started AS encounter_started
+,
+    c_enc.last_affirmed AS encounter_last_affirmed
+,
+    c_ety.description AS encounter_type
+,
+    _
+(c_ety.description) AS encounter_l10n_type
+   
 FROM (
      (
-           (clin.encounter c_enc 
-         LEFT JOIN clin.encounter_type c_et 
+           (clin.episode c_epi
+     
+              JOIN clin.encounter c_enc 
                 ON (
-                       (c_enc.fk_type = c_et.pk)
+                       (c_epi.fk_encounter = c_enc.pk)
                  )
            )
-   LEFT JOIN dem.org_unit d_ou 
+     
+        JOIN clin.encounter_type c_ety 
           ON (
-                 (c_enc.fk_location = d_ou.pk)
+                 (c_enc.fk_type = c_ety.pk)
            )
      )
-LEFT JOIN dem.org d_o 
+     
+LEFT JOIN clin.health_issue c_hi 
     ON (
-           (d_ou.fk_org = d_o.pk)
+           (c_epi.fk_health_issue = c_hi.pk)
      )
 );</pre>
 	
@@ -72832,13 +87137,13 @@ LEFT JOIN dem.org d_o
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-encounters-journal">v_pat_encounters_journal</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-items">v_pat_items</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_pat_encounters_journal Structure</caption>
+                <caption>clin.v_pat_items Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -72850,8 +87155,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -72866,8 +87171,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
@@ -72898,8 +87203,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>text</td>
+            	<td>is_modified</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -72914,8 +87219,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -72930,8 +87235,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>narrative</td>
-            	<td>text</td>
+            	<td>pk_item</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -72994,8 +87299,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>src_pk</td>
-            	<td>integer</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -73010,7 +87315,7 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>src_table</td>
+            	<td>narrative</td>
             	<td>text</td>
                 <td><i>
 				
@@ -73026,8 +87331,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>src_table</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -73057,207 +87362,60 @@ LEFT JOIN dem.org d_o
 	<!-- View Definition -->
 	
 	<pre>
-SELECT c_enc.fk_patient AS pk_patient
-, c_enc.modified_when
-, c_enc.started AS clin_when
-, COALESCE
+SELECT cri.modified_when
+,
+    cri.modified_by
+,
+    cri.clin_when
+,
+        CASE cri.row_version
+            WHEN 0 THEN false
+            ELSE true
+        END AS is_modified
+,
+    cenc.fk_patient AS pk_patient
+,
+    cri.pk_item
+,
+    cri.fk_encounter AS pk_encounter
+,
+    cri.fk_episode AS pk_episode
+,
+    cepi.fk_health_issue AS pk_health_issue
+,
+    cri.soap_cat
+,
+    cri.narrative
+,
+    
 (
      (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.db_user = c_enc.modified_by)
-     )
-     , (
-           ('<'::text || 
-                 (c_enc.modified_by)::text
-           ) || '>'::text
+           (pgn.nspname)::text || '.'::text
+     ) || 
+     (pgc.relname)::text
+) AS src_table
+   
+FROM clin.clin_root_item cri
+,
+    clin.encounter cenc
+,
+    clin.episode cepi
+,
+    
+(pg_class pgc
+     
+LEFT JOIN pg_namespace pgn 
+    ON (
+           (pgc.relnamespace = pgn.oid)
      )
-) AS modified_by
-, NULL::text AS soap_cat
-, (
-     (
-           (
-                 (
-                       (
-                             (
-                                   (
-                                         (
-                                               (_
-                                                     ('Encounter'::text) || ': '::text
-                                               ) || 
-                                               (
-                                                SELECT _
-                                                     (encounter_type.description) AS _ 
-                                                  FROM clin.encounter_type 
-                                                 WHERE (encounter_type.pk = c_enc.fk_type)
-                                               )
-                                         ) || to_char
-                                         (c_enc.started
-                                               ,' YYYY-MM-DD HH24:MI'::text
-                                         )
-                                   ) || to_char
-                                   (c_enc.last_affirmed
-                                         ,' - HH24:MI'::text
-                                   )
-                             ) || COALESCE
-                             (
-                                   (
-                                         (
-                                               (
-                                                     (
-                                                           (
-                                                                 (
-                                                                       (
-                                                                             ('
- @ '::text || _
-                                                                                   ('branch'::text)
-                                                                             ) || ' "'::text
-                                                                       ) || d_ou.description
-                                                                 ) || '" '::text
-                                                           ) || _
-                                                           ('of'::text)
-                                                     ) || ' "'::text
-                                               ) || d_o.description
-                                         ) || '"'::text
-                                   )
-                                   ,''::text
-                             )
-                       ) || COALESCE
-                       (
-                             (
-                                   (
-                                         ('
- '::text || _
-                                               ('RFE'::text)
-                                         ) || ': '::text
-                                   ) || c_enc.reason_for_encounter
-                             )
-                             ,''::text
-                       )
-                 ) || COALESCE
-                 (
-                       (
-                             ('
-'::text || array_to_string
-                                   (
-                                         (
-                                          SELECT array_agg
-                                               (
-                                                     (
-                                                           (
-                                                                 (
-                                                                       (
-                                                                             (
-                                                                                   (
-                                                                                         (
-                                                                                               (r_csr.code || 
-                                                                                                  ' ('::text) || r_ds.name_short
-                                                                                               ) || ' - '::text
-                                                                                         ) || r_ds.version
-                                                                                   ) || ' - '::text
-                                                                             ) || r_ds.lang
-                                                                       ) || 
-                                                             '): '::text
-                                                           ) || r_csr.term
-                                                     )
-                                               ) AS array_agg 
-                                            FROM (
-                                                     (clin.lnk_code2rfe c_lc2r 
-                                                        JOIN ref.coding_system_root r_csr 
-                                                          ON (
-                                                                 (c_lc2r.fk_generic_code = r_csr.pk_coding_system)
-                                                           )
-                                                     )
-                                                  JOIN ref.data_source r_ds 
-                                                    ON (
-                                                           (r_ds.pk = r_csr.fk_data_source)
-                                                     )
-                                               )
-                                           WHERE (c_lc2r.fk_item = c_enc.pk)
-                                         )
-                                         ,'; '::text
-                                   )
-                             ) || ';'::text
-                       )
-                       ,''::text
-                 )
-           ) || COALESCE
-           (
-                 (
-                       (
-                             ('
- '::text || _
-                                   ('AOE'::text)
-                             ) || ': '::text
-                       ) || c_enc.assessment_of_encounter
-                 )
-                 ,''::text
-           )
-     ) || COALESCE
+)
+  
+WHERE (
      (
-           (
-                 ('
-'::text || array_to_string
-                       (
-                             (
-                              SELECT array_agg
-                                   (
-                                         (
-                                               (
-                                                     (
-                                                           (
-                                                                 (
-                                                                       (
-                                                                             (
-                                                                                   (r_csr.code || 
-                                                                                      ' ('::text) || r_ds.name_short
-                                                                                   ) || ' - '::text
-                                                                             ) || r_ds.version
-                                                                       ) || ' - '::text
-                                                                 ) || r_ds.lang
-                                                           ) || 
-                                                 '): '::text
-                                               ) || r_csr.term
-                                         )
-                                   ) AS array_agg 
-                                FROM (
-                                         (clin.lnk_code2aoe c_lc2a 
-                                            JOIN ref.coding_system_root r_csr 
-                                              ON (
-                                                     (c_lc2a.fk_generic_code = r_csr.pk_coding_system)
-                                               )
-                                         )
-                                      JOIN ref.data_source r_ds 
-                                        ON (
-                                               (r_ds.pk = r_csr.fk_data_source)
-                                         )
-                                   )
-                               WHERE (c_lc2a.fk_item = c_enc.pk)
-                             )
-                             ,'; '::text
-                       )
-                 ) || ';'::text
-           )
-           ,''::text
-     )
-) AS narrative
-, c_enc.pk AS pk_encounter
-, (-1) AS pk_episode
-, (-1) AS pk_health_issue
-, c_enc.pk AS src_pk
-,'clin.encounter'::text AS src_table
-, c_enc.row_version 
-FROM (
-     (clin.encounter c_enc 
-   LEFT JOIN dem.org_unit d_ou 
-          ON (
-                 (c_enc.fk_location = d_ou.pk)
-           )
-     )
-LEFT JOIN dem.org d_o 
-    ON (
-           (d_ou.fk_org = d_o.pk)
+           (cri.fk_encounter = cenc.pk)
+         AND (cri.fk_episode = cepi.pk)
      )
+   AND (cri.tableoid = pgc.oid)
 );</pre>
 	
 
@@ -73272,13 +87430,15 @@ LEFT JOIN dem.org d_o
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-episodes">v_pat_episodes</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-last-vacc4indication">v_pat_last_vacc4indication</a>
 		</h2>
         
+         <p>Lists *latest* vaccinations with total count per indication.</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_pat_episodes Structure</caption>
+                <caption>clin.v_pat_last_vacc4indication Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -73306,7 +87466,39 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>description</td>
+            	<td>pk_vaccination</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>date_given</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>vaccine</td>
             	<td>text</td>
                 <td><i>
 				
@@ -73322,7 +87514,7 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>summary</td>
+            	<td>indication</td>
             	<td>text</td>
                 <td><i>
 				
@@ -73338,8 +87530,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>episode_open</td>
-            	<td>boolean</td>
+            	<td>l10n_indication</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -73354,7 +87546,7 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>health_issue</td>
+            	<td>site</td>
             	<td>text</td>
                 <td><i>
 				
@@ -73370,8 +87562,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>issue_active</td>
-            	<td>boolean</td>
+            	<td>batch_no</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -73386,8 +87578,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>issue_clinically_relevant</td>
-            	<td>boolean</td>
+            	<td>reaction</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -73402,8 +87594,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>started_first</td>
-            	<td>timestamp with time zone</td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -73418,8 +87610,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>started_last</td>
-            	<td>timestamp with time zone</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -73434,7 +87626,7 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>last_affirmed</td>
+            	<td>modified_when</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
@@ -73450,8 +87642,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
@@ -73466,7 +87658,7 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
+            	<td>row_version</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -73482,7 +87674,7 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
+            	<td>pk_vaccine</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -73498,8 +87690,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>episode_modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_indication</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -73514,8 +87706,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>episode_modified_by</td>
-            	<td>name</td>
+            	<td>pk_provider</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -73530,8 +87722,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>diagnostic_certainty_classification</td>
-            	<td>text</td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -73546,8 +87738,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>diagnostic_certainty_classification_issue</td>
-            	<td>text</td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -73562,8 +87754,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>pk_generic_codes</td>
-            	<td>integer[]</td>
+            	<td>xmin_vaccination</td>
+            	<td>xid</td>
                 <td><i>
 				
 
@@ -73578,8 +87770,8 @@ LEFT JOIN dem.org d_o
 				<td>
                 
                 </td>
-            	<td>xmin_episode</td>
-            	<td>xid</td>
+            	<td>no_of_shots</td>
+            	<td>bigint</td>
                 <td><i>
 				
 
@@ -73609,109 +87801,82 @@ LEFT JOIN dem.org d_o
 	<!-- View Definition -->
 	
 	<pre>
-SELECT cenc.fk_patient AS pk_patient
-, cep.description
-, cep.summary
-, cep.is_open AS episode_open
-, NULL::text AS health_issue
-, NULL::boolean AS issue_active
-, NULL::boolean AS issue_clinically_relevant
-, (
-SELECT min
-     (cle.started) AS min 
-  FROM clin.encounter cle 
- WHERE (cle.pk = cep.fk_encounter) LIMIT 1
-) AS started_first
-, (
-SELECT max
-     (cle.started) AS max 
-  FROM clin.encounter cle 
- WHERE (cle.pk = cep.fk_encounter) LIMIT 1
-) AS started_last
-, (
-SELECT max
-     (cle.last_affirmed) AS max 
-  FROM clin.encounter cle 
- WHERE (cle.pk = cep.fk_encounter) LIMIT 1
-) AS last_affirmed
-, cep.pk AS pk_episode
-, cep.fk_encounter AS pk_encounter
-, NULL::integer AS pk_health_issue
-, cep.modified_when AS episode_modified_when
-, cep.modified_by AS episode_modified_by
-, cep.diagnostic_certainty_classification
-, NULL::text AS diagnostic_certainty_classification_issue
-, COALESCE
-(
-     (
-      SELECT array_agg
-           (c_lc2e.fk_generic_code) AS array_agg 
-        FROM clin.lnk_code2episode c_lc2e 
-       WHERE (c_lc2e.fk_item = cep.pk)
-     )
-     , ARRAY[]::integer[]
-) AS pk_generic_codes
-, cep.xmin AS xmin_episode 
-FROM (clin.episode cep 
-  JOIN clin.encounter cenc 
-    ON (
-           (cep.fk_encounter = cenc.pk)
-     )
-)
-WHERE (cep.fk_health_issue IS NULL)
-UNION ALLSELECT cenc.fk_patient AS pk_patient
-, cep.description
-, cep.summary
-, cep.is_open AS episode_open
-, chi.description AS health_issue
-, chi.is_active AS issue_active
-, chi.clinically_relevant AS issue_clinically_relevant
-, (
-SELECT min
-     (cle.started) AS min 
-  FROM clin.encounter cle 
- WHERE (cle.pk = cep.fk_encounter) LIMIT 1
-) AS started_first
-, (
-SELECT max
-     (cle.started) AS max 
-  FROM clin.encounter cle 
- WHERE (cle.pk = cep.fk_encounter) LIMIT 1
-) AS started_last
-, (
-SELECT max
-     (cle.last_affirmed) AS max 
-  FROM clin.encounter cle 
- WHERE (cle.pk = cep.fk_encounter) LIMIT 1
-) AS last_affirmed
-, cep.pk AS pk_episode
-, cep.fk_encounter AS pk_encounter
-, cep.fk_health_issue AS pk_health_issue
-, cep.modified_when AS episode_modified_when
-, cep.modified_by AS episode_modified_by
-, cep.diagnostic_certainty_classification
-, chi.diagnostic_certainty_classification AS diagnostic_certainty_classification_issue
-, COALESCE
-(
-     (
-      SELECT array_agg
-           (c_lc2e.fk_generic_code) AS array_agg 
-        FROM clin.lnk_code2episode c_lc2e 
-       WHERE (c_lc2e.fk_item = cep.pk)
-     )
-     , ARRAY[]::integer[]
-) AS pk_generic_codes
-, cep.xmin AS xmin_episode 
-FROM (
-     (clin.episode cep 
-        JOIN clin.encounter cenc 
-          ON (
-                 (cep.fk_encounter = cenc.pk)
+SELECT c_vpv4i.pk_patient
+,
+    c_vpv4i.pk_vaccination
+,
+    c_vpv4i.date_given
+,
+    c_vpv4i.vaccine
+,
+    c_vpv4i.indication
+,
+    c_vpv4i.l10n_indication
+,
+    c_vpv4i.site
+,
+    c_vpv4i.batch_no
+,
+    c_vpv4i.reaction
+,
+    c_vpv4i.comment
+,
+    c_vpv4i.soap_cat
+,
+    c_vpv4i.modified_when
+,
+    c_vpv4i.modified_by
+,
+    c_vpv4i.row_version
+,
+    c_vpv4i.pk_vaccine
+,
+    c_vpv4i.pk_indication
+,
+    c_vpv4i.pk_provider
+,
+    c_vpv4i.pk_encounter
+,
+    c_vpv4i.pk_episode
+,
+    c_vpv4i.xmin_vaccination
+,
+    shots_per_ind.no_of_shots
+   
+FROM (clin.v_pat_vaccs4indication c_vpv4i
+     
+  JOIN (
+      SELECT count
+           (1) AS no_of_shots
+           ,
+            v_pat_vaccs4indication.pk_patient
+           ,
+            v_pat_vaccs4indication.pk_indication
+           
+        FROM clin.v_pat_vaccs4indication
+          
+    GROUP BY v_pat_vaccs4indication.pk_patient
+           , v_pat_vaccs4indication.pk_indication
+     ) shots_per_ind 
+    ON (
+           (
+                 (c_vpv4i.pk_patient = shots_per_ind.pk_patient)
+               AND (c_vpv4i.pk_indication = shots_per_ind.pk_indication)
            )
      )
-  JOIN clin.health_issue chi 
-    ON (
-           (cep.fk_health_issue = chi.pk)
+)
+  
+WHERE (c_vpv4i.date_given = 
+     (
+      SELECT max
+           (c_vpv4i_2.date_given) AS max
+           
+        FROM clin.v_pat_vaccs4indication c_vpv4i_2
+          
+       WHERE (
+                 (c_vpv4i.pk_patient = c_vpv4i_2.pk_patient)
+               AND (c_vpv4i.pk_indication = c_vpv4i_2.pk_indication)
+           )
      )
 );</pre>
 	
@@ -73727,13 +87892,13 @@ FROM (
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-episodes-journal">v_pat_episodes_journal</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-narrative-journal">v_pat_narrative_journal</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_pat_episodes_journal Structure</caption>
+                <caption>clin.v_pat_narrative_journal Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -73933,172 +88098,12 @@ FROM (
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT cenc.fk_patient AS pk_patient
-, cep.modified_when
-, cenc.started AS clin_when
-, COALESCE
-(
-     (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.db_user = cep.modified_by)
-     )
-     , (
-           ('<'::text || 
-                 (cep.modified_by)::text
-           ) || '>'::text
-     )
-) AS modified_by
-,'a'::text AS soap_cat
-, (
-     (
-           (
-                 (
-                       (
-                             (
-                                   (
-                                         (_
-                                               ('Episode'::text) || 
-                                            ' ('::text) || CASE WHEN cep.is_open THEN _
-                                               ('open'::text) ELSE _
-                                               ('closed'::text) END
-                                         ) || COALESCE
-                                         (
-                                               (
-                                                  ', '::text || cep.diagnostic_certainty_classification
-                                               )
-                                               ,''::text
-                                         )
-                                   ) || 
-                         '): '::text
-                       ) || cep.description
-                 ) || ';'::text
-           ) || COALESCE
-           (
-                 (
-                       (
-                             (
-                                   ('
- '::text || _
-                                         ('Synopsis'::text)
-                                   ) || ': '::text
-                             ) || cep.summary
-                       ) || ';'::text
-                 )
-                 ,''::text
-           )
-     ) || COALESCE
-     (
-           (
-                 ('
-'::text || array_to_string
-                       (
-                             (
-                              SELECT array_agg
-                                   (
-                                         (
-                                               (
-                                                     (
-                                                           (
-                                                                 (
-                                                                       (
-                                                                             (
-                                                                                   (r_csr.code || 
-                                                                                      ' ('::text) || r_ds.name_short
-                                                                                   ) || ' - '::text
-                                                                             ) || r_ds.version
-                                                                       ) || ' - '::text
-                                                                 ) || r_ds.lang
-                                                           ) || 
-                                                 '): '::text
-                                               ) || r_csr.term
-                                         )
-                                   ) AS array_agg 
-                                FROM (
-                                         (clin.lnk_code2episode c_lc2e 
-                                            JOIN ref.coding_system_root r_csr 
-                                              ON (
-                                                     (c_lc2e.fk_generic_code = r_csr.pk_coding_system)
-                                               )
-                                         )
-                                      JOIN ref.data_source r_ds 
-                                        ON (
-                                               (r_ds.pk = r_csr.fk_data_source)
-                                         )
-                                   )
-                               WHERE (c_lc2e.fk_item = cep.pk)
-                             )
-                             ,'; '::text
-                       )
-                 ) || ';'::text
-           )
-           ,''::text
-     )
-) AS narrative
-, cep.fk_encounter AS pk_encounter
-, cep.pk AS pk_episode
-, cep.fk_health_issue AS pk_health_issue
-, cep.pk AS src_pk
-,'clin.episode'::text AS src_table
-, cep.row_version 
-FROM (clin.episode cep 
-  JOIN clin.encounter cenc 
-    ON (
-           (cep.fk_encounter = cenc.pk)
-     )
-);</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-items">v_pat_items</a>
-		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_pat_items Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -74113,8 +88118,8 @@ FROM (clin.episode cep
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>issue_laterality</td>
+            	<td>character varying(2)</td>
                 <td><i>
 				
 
@@ -74129,8 +88134,8 @@ FROM (clin.episode cep
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -74145,7 +88150,7 @@ FROM (clin.episode cep
 				<td>
                 
                 </td>
-            	<td>is_modified</td>
+            	<td>issue_clinically_relevant</td>
             	<td>boolean</td>
                 <td><i>
 				
@@ -74161,8 +88166,8 @@ FROM (clin.episode cep
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -74177,8 +88182,8 @@ FROM (clin.episode cep
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
-            	<td>integer</td>
+            	<td>episode</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -74193,8 +88198,8 @@ FROM (clin.episode cep
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -74209,8 +88214,8 @@ FROM (clin.episode cep
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -74225,8 +88230,8 @@ FROM (clin.episode cep
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
-            	<td>integer</td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -74241,7 +88246,7 @@ FROM (clin.episode cep
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
+            	<td>encounter_type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -74257,23 +88262,7 @@ FROM (clin.episode cep
 				<td>
                 
                 </td>
-            	<td>narrative</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>src_table</td>
+            	<td>encounter_l10n_type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -74304,38 +88293,111 @@ FROM (clin.episode cep
 	<!-- View Definition -->
 	
 	<pre>
-SELECT cri.modified_when
-, cri.modified_by
-, cri.clin_when
-, CASE cri.row_version WHEN 0 THEN false ELSE true END AS is_modified
-, cenc.fk_patient AS pk_patient
-, cri.pk_item
-, cri.fk_encounter AS pk_encounter
-, cri.fk_episode AS pk_episode
-, cepi.fk_health_issue AS pk_health_issue
-, cri.soap_cat
-, cri.narrative
-, (
+SELECT c_enc.fk_patient AS pk_patient
+,
+    c_n.modified_when
+,
+        CASE
+            WHEN 
+(c_n.soap_cat = ANY 
+     (ARRAY['s'::text
+           ,'o'::text
+           ,'u'::text]
+     )
+) THEN c_enc.started
+            WHEN 
+(c_n.soap_cat IS NULL) THEN c_enc.last_affirmed
+            WHEN 
+(c_n.soap_cat = ANY 
+     (ARRAY['a'::text
+           ,'p'::text]
+     )
+) THEN c_enc.last_affirmed
+            ELSE NULL::timestamp with time zone
+        END AS clin_when
+,
+    COALESCE
+(
      (
-           (pgn.nspname)::text || '.'::text
-     ) || 
-     (pgc.relname)::text
-) AS src_table 
-FROM clin.clin_root_item cri
-, clin.encounter cenc
-, clin.episode cepi
-, (pg_class pgc 
-LEFT JOIN pg_namespace pgn 
-    ON (
-           (pgc.relnamespace = pgn.oid)
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_n.modified_by)
      )
-)
-WHERE (
+     , (
+           ('<'::text || 
+                 (c_n.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    c_n.soap_cat
+,
+    c_n.narrative
+,
+    c_n.fk_encounter AS pk_encounter
+,
+    c_n.fk_episode AS pk_episode
+,
+    c_epi.fk_health_issue AS pk_health_issue
+,
+    c_n.pk AS src_pk
+,
+    'clin.clin_narrative'::text AS src_table
+,
+    c_n.row_version
+,
+    c_hi.description AS health_issue
+,
+    c_hi.laterality AS issue_laterality
+,
+    c_hi.is_active AS issue_active
+,
+    c_hi.clinically_relevant AS issue_clinically_relevant
+,
+    c_hi.is_confidential AS issue_confidential
+,
+    c_epi.description AS episode
+,
+    c_epi.is_open AS episode_open
+,
+    c_enc.started AS encounter_started
+,
+    c_enc.last_affirmed AS encounter_last_affirmed
+,
+    c_ety.description AS encounter_type
+,
+    _
+(c_ety.description) AS encounter_l10n_type
+   
+FROM (
      (
-           (cri.fk_encounter = cenc.pk)
-         AND (cri.fk_episode = cepi.pk)
+           (
+                 (clin.clin_narrative c_n
+     
+                    JOIN clin.encounter c_enc 
+                      ON (
+                             (c_n.fk_encounter = c_enc.pk)
+                       )
+                 )
+     
+              JOIN clin.encounter_type c_ety 
+                ON (
+                       (c_enc.fk_type = c_ety.pk)
+                 )
+           )
+     
+        JOIN clin.episode c_epi 
+          ON (
+                 (c_n.fk_episode = c_epi.pk)
+           )
+     )
+     
+LEFT JOIN clin.health_issue c_hi 
+    ON (
+           (c_epi.fk_health_issue = c_hi.pk)
      )
-   AND (cri.tableoid = pgc.oid)
 );</pre>
 	
 
@@ -74350,15 +88412,15 @@ WHERE (
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-last-vacc4indication">v_pat_last_vacc4indication</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-vaccinations">v_pat_vaccinations</a>
 		</h2>
         
-         <p>Lists *latest* vaccinations with total count per indication.</p>
+         <p>Lists vaccinations for patients</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_pat_last_vacc4indication Structure</caption>
+                <caption>clin.v_pat_vaccinations Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -74418,8 +88480,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>vaccine</td>
-            	<td>text</td>
+            	<td>interval_since_given</td>
+            	<td>interval</td>
                 <td><i>
 				
 
@@ -74434,7 +88496,7 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>indication</td>
+            	<td>vaccine</td>
             	<td>text</td>
                 <td><i>
 				
@@ -74450,8 +88512,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>l10n_indication</td>
-            	<td>text</td>
+            	<td>indications</td>
+            	<td>text[]</td>
                 <td><i>
 				
 
@@ -74466,6 +88528,22 @@ WHERE (
 				<td>
                 
                 </td>
+            	<td>l10n_indications</td>
+            	<td>text[]</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
             	<td>site</td>
             	<td>text</td>
                 <td><i>
@@ -74478,7 +88556,7 @@ WHERE (
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -74494,7 +88572,7 @@ WHERE (
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -74510,7 +88588,7 @@ WHERE (
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -74526,7 +88604,7 @@ WHERE (
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -74542,7 +88620,7 @@ WHERE (
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -74551,19 +88629,305 @@ WHERE (
                 <td><i>
 				
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_indications</td>
+            	<td>integer[]</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_vaccine</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_provider</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>xmin_vaccination</td>
+            	<td>xid</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT cenc.fk_patient AS pk_patient
+,
+    clv.pk AS pk_vaccination
+,
+    clv.clin_when AS date_given
+,
+    
+(now
+     () - clv.clin_when
+) AS interval_since_given
+,
+    rbd.description AS vaccine
+,
+    
+(
+SELECT array_agg
+     (cvi.description) AS array_agg
+           
+  FROM (clin.lnk_vaccine2inds clvi
+             
+        JOIN clin.vacc_indication cvi 
+          ON (
+                 (clvi.fk_indication = cvi.id)
+           )
+     )
+          
+ WHERE (clvi.fk_vaccine = clv.fk_vaccine)
+) AS indications
+,
+    
+(
+SELECT array_agg
+     (_
+           (cvi.description)
+     ) AS array_agg
+           
+  FROM (clin.lnk_vaccine2inds clvi
+             
+        JOIN clin.vacc_indication cvi 
+          ON (
+                 (clvi.fk_indication = cvi.id)
+           )
+     )
+          
+ WHERE (clvi.fk_vaccine = clv.fk_vaccine)
+) AS l10n_indications
+,
+    clv.site
+,
+    clv.batch_no
+,
+    clv.reaction
+,
+    clv.narrative AS comment
+,
+    clv.soap_cat
+,
+    clv.modified_when
+,
+    clv.modified_by
+,
+    clv.row_version
+,
+    
+(
+SELECT array_agg
+     (clvi.fk_indication) AS array_agg
+           
+  FROM (clin.lnk_vaccine2inds clvi
+             
+        JOIN clin.vacc_indication cvi 
+          ON (
+                 (clvi.fk_indication = cvi.id)
+           )
+     )
+          
+ WHERE (clvi.fk_vaccine = clv.pk)
+) AS pk_indications
+,
+    clv.fk_vaccine AS pk_vaccine
+,
+    clv.fk_provider AS pk_provider
+,
+    clv.fk_encounter AS pk_encounter
+,
+    clv.fk_episode AS pk_episode
+,
+    clv.xmin AS xmin_vaccination
+   
+FROM (
+     (
+           (clin.vaccination clv
+     
+              JOIN clin.encounter cenc 
+                ON (
+                       (cenc.pk = clv.fk_encounter)
+                 )
+           )
+     
+        JOIN clin.vaccine 
+          ON (
+                 (vaccine.pk = clv.fk_vaccine)
+           )
+     )
+     
+  JOIN ref.branded_drug rbd 
+    ON (
+           (vaccine.fk_brand = rbd.pk)
+     )
+);</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-vaccs4indication">v_pat_vaccs4indication</a>
+		</h2>
+        
+         <p>Lists vaccinations per indication for patients</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.v_pat_vaccs4indication Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -74578,7 +88942,7 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>row_version</td>
+            	<td>pk_vaccination</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -74594,8 +88958,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_vaccine</td>
-            	<td>integer</td>
+            	<td>date_given</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -74610,8 +88974,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_indication</td>
-            	<td>integer</td>
+            	<td>vaccine</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -74626,8 +88990,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_provider</td>
-            	<td>integer</td>
+            	<td>indication</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -74642,8 +89006,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>l10n_indication</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -74658,8 +89022,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>site</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -74674,24 +89038,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>xmin_vaccination</td>
-            	<td>xid</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>indication_count</td>
-            	<td>bigint</td>
+            	<td>batch_no</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -74702,107 +89050,12 @@ WHERE (
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT cvpv4i1.pk_patient
-, cvpv4i1.pk_vaccination
-, cvpv4i1.date_given
-, cvpv4i1.vaccine
-, cvpv4i1.indication
-, cvpv4i1.l10n_indication
-, cvpv4i1.site
-, cvpv4i1.batch_no
-, cvpv4i1.reaction
-, cvpv4i1.comment
-, cvpv4i1.soap_cat
-, cvpv4i1.modified_when
-, cvpv4i1.modified_by
-, cvpv4i1.row_version
-, cvpv4i1.pk_vaccine
-, cvpv4i1.pk_indication
-, cvpv4i1.pk_provider
-, cvpv4i1.pk_encounter
-, cvpv4i1.pk_episode
-, cvpv4i1.xmin_vaccination
-, cpi.indication_count 
-FROM (clin.v_pat_vaccs4indication cvpv4i1 
-  JOIN (
-      SELECT count
-           (1) AS indication_count
-           , v_pat_vaccs4indication.pk_patient
-           , v_pat_vaccs4indication.pk_indication 
-        FROM clin.v_pat_vaccs4indication 
-    GROUP BY v_pat_vaccs4indication.pk_patient
-           , v_pat_vaccs4indication.pk_indication
-     ) cpi 
-    ON (
-           (
-                 (cvpv4i1.pk_patient = cpi.pk_patient)
-               AND (cvpv4i1.pk_indication = cpi.pk_indication)
-           )
-     )
-)
-WHERE (cvpv4i1.date_given = 
-     (
-      SELECT max
-           (cvpv4i2.date_given) AS max 
-        FROM clin.v_pat_vaccs4indication cvpv4i2 
-       WHERE (
-                 (cvpv4i1.pk_patient = cvpv4i2.pk_patient)
-               AND (cvpv4i1.pk_indication = cvpv4i2.pk_indication)
-           )
-     )
-);</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-narrative-journal">v_pat_narrative_journal</a>
-		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_pat_narrative_journal Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>reaction</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -74817,8 +89070,8 @@ WHERE (cvpv4i1.date_given =
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -74833,8 +89086,8 @@ WHERE (cvpv4i1.date_given =
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -74849,8 +89102,8 @@ WHERE (cvpv4i1.date_given =
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -74865,8 +89118,8 @@ WHERE (cvpv4i1.date_given =
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 
@@ -74881,8 +89134,8 @@ WHERE (cvpv4i1.date_given =
 				<td>
                 
                 </td>
-            	<td>narrative</td>
-            	<td>text</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -74897,7 +89150,7 @@ WHERE (cvpv4i1.date_given =
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
+            	<td>pk_vaccine</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -74913,7 +89166,7 @@ WHERE (cvpv4i1.date_given =
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
+            	<td>pk_indication</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -74929,7 +89182,7 @@ WHERE (cvpv4i1.date_given =
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
+            	<td>pk_provider</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -74945,7 +89198,7 @@ WHERE (cvpv4i1.date_given =
 				<td>
                 
                 </td>
-            	<td>src_pk</td>
+            	<td>pk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -74961,8 +89214,8 @@ WHERE (cvpv4i1.date_given =
 				<td>
                 
                 </td>
-            	<td>src_table</td>
-            	<td>text</td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -74977,8 +89230,8 @@ WHERE (cvpv4i1.date_given =
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>xmin_vaccination</td>
+            	<td>xid</td>
                 <td><i>
 				
 
@@ -75008,50 +89261,58 @@ WHERE (cvpv4i1.date_given =
 	<!-- View Definition -->
 	
 	<pre>
-SELECT cenc.fk_patient AS pk_patient
-, cn.modified_when
-, CASE WHEN 
-(cn.soap_cat = ANY 
-     (ARRAY['s'::text
-           ,'o'::text
-           ,'u'::text]
-     )
-) THEN cenc.started WHEN 
-(cn.soap_cat IS NULL) THEN cenc.last_affirmed WHEN 
-(cn.soap_cat = ANY 
-     (ARRAY['a'::text
-           ,'p'::text]
-     )
-) THEN cenc.last_affirmed ELSE NULL::timestamp with time zone END AS clin_when
-, COALESCE
-(
-     (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.db_user = cn.modified_by)
-     )
-     , (
-           ('<'::text || 
-                 (cn.modified_by)::text
-           ) || '>'::text
+SELECT c_enc.fk_patient AS pk_patient
+,
+    c_shot.pk AS pk_vaccination
+,
+    c_shot.clin_when AS date_given
+,
+    c_vlv2i.vaccine
+,
+    c_vlv2i.indication
+,
+    c_vlv2i.l10n_indication
+,
+    c_shot.site
+,
+    c_shot.batch_no
+,
+    c_shot.reaction
+,
+    c_shot.narrative AS comment
+,
+    c_shot.soap_cat
+,
+    c_shot.modified_when
+,
+    c_shot.modified_by
+,
+    c_shot.row_version
+,
+    c_shot.fk_vaccine AS pk_vaccine
+,
+    c_vlv2i.pk_indication
+,
+    c_shot.fk_provider AS pk_provider
+,
+    c_shot.fk_encounter AS pk_encounter
+,
+    c_shot.fk_episode AS pk_episode
+,
+    c_shot.xmin AS xmin_vaccination
+   
+FROM (
+     (clin.vaccination c_shot
+     
+        JOIN clin.encounter c_enc 
+          ON (
+                 (c_enc.pk = c_shot.fk_encounter)
+           )
      )
-) AS modified_by
-, cn.soap_cat
-, cn.narrative
-, cn.fk_encounter AS pk_encounter
-, cn.fk_episode AS pk_episode
-, (
-SELECT episode.fk_health_issue 
-  FROM clin.episode 
- WHERE (episode.pk = cn.fk_episode)
-) AS pk_health_issue
-, cn.pk AS src_pk
-,'clin.clin_narrative'::text AS src_table
-, cn.row_version 
-FROM (clin.clin_narrative cn 
-  JOIN clin.encounter cenc 
+     
+  JOIN clin.v_lnk_vaccine2inds c_vlv2i 
     ON (
-           (cn.fk_encounter = cenc.pk)
+           (c_vlv2i.pk_vaccine = c_shot.fk_vaccine)
      )
 );</pre>
 	
@@ -75067,13 +89328,13 @@ FROM (clin.clin_narrative cn
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-substance-intake-journal">v_pat_substance_intake_journal</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-potential-problem-list">v_potential_problem_list</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_pat_substance_intake_journal Structure</caption>
+                <caption>clin.v_potential_problem_list Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -75101,8 +89362,8 @@ FROM (clin.clin_narrative cn
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>problem</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -75117,8 +89378,8 @@ FROM (clin.clin_narrative cn
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>summary</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -75133,7 +89394,7 @@ FROM (clin.clin_narrative cn
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
+            	<td>type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -75149,7 +89410,7 @@ FROM (clin.clin_narrative cn
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
+            	<td>l10n_type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -75165,8 +89426,8 @@ FROM (clin.clin_narrative cn
 				<td>
                 
                 </td>
-            	<td>narrative</td>
-            	<td>text</td>
+            	<td>problem_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -75181,8 +89442,8 @@ FROM (clin.clin_narrative cn
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -75214,437 +89475,154 @@ FROM (clin.clin_narrative cn
                 
                 </td>
             	<td>pk_health_issue</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>src_pk</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>src_table</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>row_version</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
- WHERE (encounter.pk = c_si.fk_encounter)
-) AS pk_patient
-, c_si.modified_when
-, c_si.clin_when
-, COALESCE
-(
-     (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.db_user = c_si.modified_by)
-     )
-     , (
-           ('<'::text || 
-                 (c_si.modified_by)::text
-           ) || '>'::text
-     )
-) AS modified_by
-, c_si.soap_cat
-, (
-     (
-           (
-                 (
-                       (
-                             (
-                                   (
-                                         (
-                                               (
-                                                     (
-                                                           (
-                                                                 (
-                                                                       (
-                                                                             (
-                                                                                   (
-                                                                                         (
-                                                                                               (
-                                                                                                     (
-                                                                                                           (CASE WHEN 
-                                                                                                                 (c_si.is_long_term IS TRUE) THEN 
-                                                                                                                 (_
-                                                                                                                       ('long-term'::text) || ' '::text
-                                                                                                                 ) ELSE ''::text END || _
-                                                                                                                 ('substance intake'::text)
-                                                                                                           ) || ' '::text
-                                                                                                     ) || CASE WHEN 
-                                                                                                     (c_si.intake_is_approved_of IS TRUE) THEN _
-                                                                                                     ('(approved of)'::text
-                                                                                               ) WHEN 
-                                                                                               (c_si.intake_is_approved_of IS FALSE) THEN _
-                                                                                               ('(not approved of)'::text
-                                                                                         ) ELSE _
-                                                                                         ('(of unknown approval)'::text
-                                                                                   ) END
-                                                                             ) || ':
-'::text
-                                                                       ) || ' '::text
-                                                                 ) || r_cs.description
-                                                           ) || COALESCE
-                                                           (
-                                                                 (
-                                                                       (' ['::text || r_cs.atc_code) || '] '::text
-                                                                 )
-                                                                 ,' '::text
-                                                           )
-                                                     ) || 
-                                                     (r_cs.amount)::text
-                                               ) || r_cs.unit
-                                         ) || ' '::text
-                                   ) || r_bd.preparation
-                             ) || COALESCE
-                             (
-                                   (' '::text || c_si.schedule)
-                                   ,''::text
-                             )
-                       ) || 
-                    ', '::text
-                 ) || to_char
-                 (c_si.clin_when
-                       ,'YYYY-MM-DD'::text
-                 )
-           ) || COALESCE
-           (
-                 (' -> '::text || c_si.duration)
-                 ,''::text
-           )
-     ) || '
-'::text
-) || COALESCE
-(
-     (
-           (
-                 (
-                       (' '::text || _
-                             ('discontinued'::text)
-                       ) || to_char
-                       (c_si.discontinued
-                             ,': YYYY-MM-DD'::text
-                       )
-                 ) || COALESCE
-                 (
-                       (
-                             (
-                                 '('::text || c_si.discontinue_reason) || 
-                           ')'::text
-                       )
-                       ,''::text
-                 )
-           ) || '
-'::text
-     )
-     ,''::text
-)
-)      || COALESCE
-(     NULLIF
-(
-     (
-           (COALESCE
-                 (
-                       (' '::text || c_si.aim)
-                       ,''::text
-                 ) || COALESCE
-                 (
-                       (
-                             (
-                                ' ('::text || c_si.narrative) || 
-                           ')'::text
-                       )
-                       ,''::text
-                 )
-           ) || '
-'::text
-     )
-     ,'
-'::text
-)
-,''::text
-)     
-)            || COALESCE
-(           
-(     
-(
-     (
-           (' "'::text || r_bd.description) || '"'::text
-     ) || COALESCE
-     (
-           (
-                 (' ['::text || r_bd.atc_code) || ']'::text
-           )
-           ,''::text
-     )
-) || COALESCE
-(
-     (
-           (
-                 (
-                       (
-                          ' ('::text || r_bd.external_code_type) || ': '::text
-                       ) || r_bd.external_code
-                 ) || 
-         ')'::text
-     )
-     ,''::text
-)
-)     
-,     ''::text
-)           
-)                  AS narrative
-,                  c_si.fk_encounter AS pk_encounter
-,                  c_si.fk_episode AS pk_episode
-,                  (
-SELECT       episode.fk_health_issue 
-FROM         clin.episode 
-WHERE        (episode.pk = c_si.fk_episode)
-)                  AS pk_health_issue
-,                  c_si.pk AS src_pk
-,                 'clin.substance_intake'::text AS src_table
-,                  c_si.row_version 
-FROM               (
-(           
-(     clin.substance_intake c_si 
-JOIN ref.lnk_substance2brand r_ls2b 
-ON (
-     (c_si.fk_drug_component = r_ls2b.pk)
-)
-)     
-JOIN   ref.branded_drug r_bd 
-ON     (
-(r_bd.pk = r_ls2b.fk_brand)
-)     
-)           
-JOIN         ref.consumable_substance r_cs 
-ON           (
-(     r_cs.pk = r_ls2b.fk_substance)
-)           
-)                 
-WHERE              (c_si.fk_drug_component IS NOT NULL)
-UNION ALL         SELECT (
-SELECT       encounter.fk_patient 
-FROM         clin.encounter 
-WHERE        (encounter.pk = c_si.fk_encounter)
-)                  AS pk_patient
-,                  c_si.modified_when
-,                  c_si.clin_when
-,                  COALESCE
-(                 
-(           
-SELECT staff.short_alias 
-FROM   dem.staff 
-WHERE  (staff.db_user = c_si.modified_by)
-)           
-,            (
-(     '<'::text || 
-(c_si.modified_by)::text
-)      || '>'::text
-)           
-)                  AS modified_by
-,                  c_si.soap_cat
-,                  (
-(           
-(     
-(
-     (
-           (
-                 (
-                       (
-                             (
-                                   (
-                                         (
-                                               (
-                                                     (
-                                                           (
-                                                                 (
-                                                                       (
-                                                                             (
-                                                                                   (CASE WHEN 
-                                                                                         (c_si.is_long_term IS TRUE) THEN 
-                                                                                         (_
-                                                                                               ('long-term'::text) || ' '::text
-                                                                                         ) ELSE ''::text END || _
-                                                                                         ('substance intake'::text)
-                                                                                   ) || ' '::text
-                                                                             ) || CASE WHEN 
-                                                                             (c_si.intake_is_approved_of IS TRUE) THEN _
-                                                                             ('(approved of)'::text
-                                                                       ) WHEN 
-                                                                       (c_si.intake_is_approved_of IS FALSE) THEN _
-                                                                       ('(not approved of)'::text
-                                                                 ) ELSE _
-                                                                 ('(of unknown approval)'::text
-                                                           ) END
-                                                     ) || ':
-'::text
-                                               ) || ' '::text
-                                         ) || r_cs.description
-                                   ) || COALESCE
-                                   (
-                                         (
-                                               (' ['::text || r_cs.atc_code) || '] '::text
-                                         )
-                                         ,' '::text
-                                   )
-                             ) || r_cs.amount
-                       ) || r_cs.unit
-                 ) || ' '::text
-           ) || c_si.preparation
-     ) || COALESCE
-     (
-           (' '::text || c_si.schedule)
-           ,''::text
-     )
-) || 
-', '::text
-)      || to_char
-(     c_si.clin_when
-,'YYYY-MM-DD'::text
-)     
-)            || COALESCE
-(           
-(     ' -> '::text || c_si.duration)
-,     ''::text
-)           
-)                  || '
-'::text
-)                        || COALESCE
-(                       
-(                 
-(           
-(     
-(' '::text || _
-     ('discontinued'::text)
-) || to_char
-(c_si.discontinued
-     ,': YYYY-MM-DD'::text
-)
-)      || COALESCE
-(     
-(
-     (
-         '('::text || c_si.discontinue_reason) || 
-   ')'::text
-)
-,''::text
-)     
-)            || '
-'::text
-)                 
-,                 ''::text
-)                       
-)                              || COALESCE
-(                             NULLIF
-(                       
-(                 
-(           COALESCE
-(     
-(' '::text || c_si.aim)
-,''::text
-)      || COALESCE
-(     
-(
-     (
-        ' ('::text || c_si.narrative) || 
-   ')'::text
-)
-,''::text
-)     
-)            || '
-'::text
-)                 
-,                 '
-'::text
-)                       
-,                       ''::text
-)                             
-)                                    AS narrative
-,                                    c_si.fk_encounter AS pk_encounter
-,                                    c_si.fk_episode AS pk_episode
-,                                    (
-SELECT                         episode.fk_health_issue 
-FROM                           clin.episode 
-WHERE                          (episode.pk = c_si.fk_episode)
-)                                    AS pk_health_issue
-,                                    c_si.pk AS src_pk
-,                                   'clin.substance_intake'::text AS src_table
-,                                    c_si.row_version 
-FROM                                 (clin.substance_intake c_si 
-JOIN                           ref.consumable_substance r_cs 
-ON                             (
-(                       r_cs.pk = c_si.fk_substance)
-)                             
-)                                   
-WHERE                                (c_si.fk_drug_component IS NULL);</pre>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>diagnostic_certainty_classification</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT (
+SELECT encounter.fk_patient
+           
+  FROM clin.encounter
+          
+ WHERE (encounter.pk = cep.fk_encounter)
+) AS pk_patient
+,
+    cep.description AS problem
+,
+    cep.summary
+,
+    'episode'::text AS type
+,
+    _
+('episode'::text) AS l10n_type
+,
+    false AS problem_active
+,
+    false AS clinically_relevant
+,
+    cep.pk AS pk_episode
+,
+    cep.fk_health_issue AS pk_health_issue
+,
+    cep.diagnostic_certainty_classification
+,
+    cep.fk_encounter AS pk_encounter
+,
+    cep.modified_when
+   
+FROM clin.episode cep
+  
+WHERE (cep.is_open IS FALSE)
+UNION
+ 
+SELECT (
+SELECT encounter.fk_patient
+           
+  FROM clin.encounter
+          
+ WHERE (encounter.pk = chi.fk_encounter)
+) AS pk_patient
+,
+    chi.description AS problem
+,
+    chi.summary
+,
+    'issue'::text AS type
+,
+    _
+('health issue'::text) AS l10n_type
+,
+    chi.is_active AS problem_active
+,
+    false AS clinically_relevant
+,
+    NULL::integer AS pk_episode
+,
+    chi.pk AS pk_health_issue
+,
+    chi.diagnostic_certainty_classification
+,
+    chi.fk_encounter AS pk_encounter
+,
+    chi.modified_when
+   
+FROM clin.health_issue chi
+  
+WHERE (chi.clinically_relevant IS FALSE);</pre>
 	
 
 	<!-- List off permissions -->
@@ -75658,15 +89636,13 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-vaccinations">v_pat_vaccinations</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-problem-list">v_problem_list</a>
 		</h2>
         
-         <p>Lists vaccinations for patients</p>
-        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_pat_vaccinations Structure</caption>
+                <caption>clin.v_problem_list Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -75694,8 +89670,8 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_vaccination</td>
-            	<td>integer</td>
+            	<td>problem</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -75710,8 +89686,8 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>date_given</td>
-            	<td>timestamp with time zone</td>
+            	<td>summary</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -75726,8 +89702,8 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>interval_since_given</td>
-            	<td>interval</td>
+            	<td>type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -75742,7 +89718,7 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>vaccine</td>
+            	<td>l10n_type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -75758,8 +89734,8 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>indications</td>
-            	<td>text[]</td>
+            	<td>problem_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -75774,8 +89750,8 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>l10n_indications</td>
-            	<td>text[]</td>
+            	<td>clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -75790,8 +89766,8 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>site</td>
-            	<td>text</td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -75806,8 +89782,8 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>batch_no</td>
-            	<td>text</td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -75822,7 +89798,7 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>reaction</td>
+            	<td>diagnostic_certainty_classification</td>
             	<td>text</td>
                 <td><i>
 				
@@ -75838,8 +89814,8 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -75854,8 +89830,8 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -75866,12 +89842,128 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				</td>
 			 </tr>
             
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT (
+SELECT encounter.fk_patient
+           
+  FROM clin.encounter
+          
+ WHERE (encounter.pk = cep.fk_encounter)
+) AS pk_patient
+,
+    cep.description AS problem
+,
+    cep.summary
+,
+    'episode'::text AS type
+,
+    _
+('episode'::text) AS l10n_type
+,
+    true AS problem_active
+,
+    true AS clinically_relevant
+,
+    cep.pk AS pk_episode
+,
+    cep.fk_health_issue AS pk_health_issue
+,
+    cep.diagnostic_certainty_classification
+,
+    cep.fk_encounter AS pk_encounter
+,
+    cep.modified_when
+   
+FROM clin.episode cep
+  
+WHERE (cep.is_open IS TRUE)
+UNION
+ 
+SELECT (
+SELECT encounter.fk_patient
+           
+  FROM clin.encounter
+          
+ WHERE (encounter.pk = chi.fk_encounter)
+) AS pk_patient
+,
+    chi.description AS problem
+,
+    chi.summary
+,
+    'issue'::text AS type
+,
+    _
+('health issue'::text) AS l10n_type
+,
+    chi.is_active AS problem_active
+,
+    true AS clinically_relevant
+,
+    NULL::integer AS pk_episode
+,
+    chi.pk AS pk_health_issue
+,
+    chi.diagnostic_certainty_classification
+,
+    chi.fk_encounter AS pk_encounter
+,
+    chi.modified_when
+   
+FROM clin.health_issue chi
+  
+WHERE (chi.clinically_relevant IS TRUE);</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-procedures">v_procedures</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.v_procedures Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_procedure</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -75886,8 +89978,8 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -75902,8 +89994,8 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -75918,8 +90010,8 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_indications</td>
-            	<td>integer[]</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -75934,8 +90026,8 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_vaccine</td>
-            	<td>integer</td>
+            	<td>clin_end</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -75950,8 +90042,8 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_provider</td>
-            	<td>integer</td>
+            	<td>is_ongoing</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -75966,8 +90058,8 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>performed_procedure</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -75982,8 +90074,8 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>unit</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -75998,8 +90090,8 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>xmin_vaccination</td>
-            	<td>xid</td>
+            	<td>organization</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -76010,133 +90102,28 @@ WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT cenc.fk_patient AS pk_patient
-, clv.pk AS pk_vaccination
-, clv.clin_when AS date_given
-, (now
-     () - clv.clin_when
-) AS interval_since_given
-, rbd.description AS vaccine
-, (
-SELECT array_agg
-     (cvi.description) AS array_agg 
-  FROM (clin.lnk_vaccine2inds clvi 
-        JOIN clin.vacc_indication cvi 
-          ON (
-                 (clvi.fk_indication = cvi.id)
-           )
-     )
- WHERE (clvi.fk_vaccine = clv.fk_vaccine)
-) AS indications
-, (
-SELECT array_agg
-     (_
-           (cvi.description)
-     ) AS array_agg 
-  FROM (clin.lnk_vaccine2inds clvi 
-        JOIN clin.vacc_indication cvi 
-          ON (
-                 (clvi.fk_indication = cvi.id)
-           )
-     )
- WHERE (clvi.fk_vaccine = clv.fk_vaccine)
-) AS l10n_indications
-, clv.site
-, clv.batch_no
-, clv.reaction
-, clv.narrative AS comment
-, clv.soap_cat
-, clv.modified_when
-, clv.modified_by
-, clv.row_version
-, (
-SELECT array_agg
-     (clvi.fk_indication) AS array_agg 
-  FROM (clin.lnk_vaccine2inds clvi 
-        JOIN clin.vacc_indication cvi 
-          ON (
-                 (clvi.fk_indication = cvi.id)
-           )
-     )
- WHERE (clvi.fk_vaccine = clv.pk)
-) AS pk_indications
-, clv.fk_vaccine AS pk_vaccine
-, clv.fk_provider AS pk_provider
-, clv.fk_encounter AS pk_encounter
-, clv.fk_episode AS pk_episode
-, clv.xmin AS xmin_vaccination 
-FROM (
-     (
-           (clin.vaccination clv 
-              JOIN clin.encounter cenc 
-                ON (
-                       (cenc.pk = clv.fk_encounter)
-                 )
-           )
-        JOIN clin.vaccine 
-          ON (
-                 (vaccine.pk = clv.fk_vaccine)
-           )
-     )
-  JOIN ref.branded_drug rbd 
-    ON (
-           (vaccine.fk_brand = rbd.pk)
-     )
-);</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-vaccinations-journal">v_pat_vaccinations_journal</a>
-		</h2>
-        
-         <p>Vaccination data denormalized for the EMR journal.</p>
-        
-
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>episode</td>
+            	<td>text</td>
+                <td><i>
+				
 
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_pat_vaccinations_journal Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -76167,8 +90154,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>modified_by</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -76183,8 +90170,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>text</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -76199,8 +90186,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -76215,8 +90202,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>narrative</td>
-            	<td>text</td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -76231,7 +90218,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
+            	<td>pk_hospital_stay</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -76247,7 +90234,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
+            	<td>pk_health_issue</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -76263,7 +90250,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
+            	<td>pk_org</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -76279,7 +90266,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>src_pk</td>
+            	<td>pk_org_unit</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -76295,8 +90282,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>src_table</td>
-            	<td>text</td>
+            	<td>pk_generic_codes</td>
+            	<td>integer[]</td>
                 <td><i>
 				
 
@@ -76311,8 +90298,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>xmin_procedure</td>
+            	<td>xid</td>
                 <td><i>
 				
 
@@ -76342,129 +90329,99 @@ FROM (
 	<!-- View Definition -->
 	
 	<pre>
-SELECT cenc.fk_patient AS pk_patient
-, cv.modified_when
-, cv.clin_when
-, COALESCE
-(
-     (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.db_user = cv.modified_by)
-     )
-     , (
-           ('<'::text || 
-                 (cv.modified_by)::text
-           ) || '>'::text
-     )
-) AS modified_by
-, cv.soap_cat
-, (
-     (
-           (
-                 (
-                       (
-                             (
-                                   (
-                                         (
-                                               (
-                                                     (_
-                                                           ('Vaccination'::text) || ': '::text
-                                                     ) || rbd.description
-                                               ) || ' '::text
-                                         ) || '['::text
-                                   ) || cv.batch_no
-                             ) || ']'::text
-                       ) || COALESCE
-                       (
-                             (
-                                   (
-                                      ' ('::text || cv.site) || 
-                                 ')'::text
-                             )
-                             ,''::text
-                       )
-                 ) || COALESCE
-                 (
-                       (
-                             (
-                                   ('
-'::text || _
-                                         ('Reaction'::text)
-                                   ) || ': '::text
-                             ) || cv.reaction
-                       )
-                       ,''::text
-                 )
-           ) || COALESCE
-           (
-                 (
-                       (
-                             ('
-'::text || _
-                                   ('Comment'::text)
-                             ) || ': '::text
-                       ) || cv.narrative
-                 )
-                 ,''::text
-           )
-     ) || COALESCE
-     (
-           (
-                 (
-                       ('
-'::text || _
-                             ('Indications'::text)
-                       ) || ': '::text
-                 ) || array_to_string
-                 (
-                       (
-                        SELECT array_agg
-                             (_
-                                   (cvi.description)
-                             ) AS array_agg 
-                          FROM (clin.lnk_vaccine2inds clvi 
-                                JOIN clin.vacc_indication cvi 
-                                  ON (
-                                         (clvi.fk_indication = cvi.id)
-                                   )
-                             )
-                         WHERE (clvi.fk_vaccine = cv.fk_vaccine)
-                       )
-                       ,' / '::text
-                 )
-           )
-           ,''::text
-     )
-) AS narrative
-, cv.fk_encounter AS pk_encounter
-, cv.fk_episode AS pk_episode
-, (
-SELECT episode.fk_health_issue 
-  FROM clin.episode 
- WHERE (episode.pk = cv.fk_episode)
-) AS pk_health_issue
-, cv.pk AS src_pk
-,'clin.vaccination'::text AS src_table
-, cv.row_version 
-FROM (
-     (
-           (clin.vaccination cv 
-              JOIN clin.encounter cenc 
-                ON (
-                       (cenc.pk = cv.fk_encounter)
-                 )
-           )
-        JOIN clin.vaccine 
-          ON (
-                 (vaccine.pk = cv.fk_vaccine)
-           )
-     )
-  JOIN ref.branded_drug rbd 
-    ON (
-           (vaccine.fk_brand = rbd.pk)
-     )
-);</pre>
+SELECT v_procedures_at_hospital.pk_procedure
+,
+    v_procedures_at_hospital.pk_patient
+,
+    v_procedures_at_hospital.soap_cat
+,
+    v_procedures_at_hospital.clin_when
+,
+    v_procedures_at_hospital.clin_end
+,
+    v_procedures_at_hospital.is_ongoing
+,
+    v_procedures_at_hospital.performed_procedure
+,
+    v_procedures_at_hospital.unit
+,
+    v_procedures_at_hospital.organization
+,
+    v_procedures_at_hospital.episode
+,
+    v_procedures_at_hospital.health_issue
+,
+    v_procedures_at_hospital.modified_when
+,
+    v_procedures_at_hospital.modified_by
+,
+    v_procedures_at_hospital.row_version
+,
+    v_procedures_at_hospital.pk_encounter
+,
+    v_procedures_at_hospital.pk_episode
+,
+    v_procedures_at_hospital.pk_hospital_stay
+,
+    v_procedures_at_hospital.pk_health_issue
+,
+    v_procedures_at_hospital.pk_org
+,
+    v_procedures_at_hospital.pk_org_unit
+,
+    v_procedures_at_hospital.pk_generic_codes
+,
+    v_procedures_at_hospital.xmin_procedure
+   
+FROM clin.v_procedures_at_hospital
+
+UNION ALL
+ 
+SELECT v_procedures_not_at_hospital.pk_procedure
+,
+    v_procedures_not_at_hospital.pk_patient
+,
+    v_procedures_not_at_hospital.soap_cat
+,
+    v_procedures_not_at_hospital.clin_when
+,
+    v_procedures_not_at_hospital.clin_end
+,
+    v_procedures_not_at_hospital.is_ongoing
+,
+    v_procedures_not_at_hospital.performed_procedure
+,
+    v_procedures_not_at_hospital.unit
+,
+    v_procedures_not_at_hospital.organization
+,
+    v_procedures_not_at_hospital.episode
+,
+    v_procedures_not_at_hospital.health_issue
+,
+    v_procedures_not_at_hospital.modified_when
+,
+    v_procedures_not_at_hospital.modified_by
+,
+    v_procedures_not_at_hospital.row_version
+,
+    v_procedures_not_at_hospital.pk_encounter
+,
+    v_procedures_not_at_hospital.pk_episode
+,
+    v_procedures_not_at_hospital.pk_hospital_stay
+,
+    v_procedures_not_at_hospital.pk_health_issue
+,
+    v_procedures_not_at_hospital.pk_org
+,
+    v_procedures_not_at_hospital.pk_org_unit
+,
+    v_procedures_not_at_hospital.pk_generic_codes
+,
+    v_procedures_not_at_hospital.xmin_procedure
+   
+FROM clin.v_procedures_not_at_hospital;</pre>
 	
 
 	<!-- List off permissions -->
@@ -76478,15 +90435,13 @@ FROM (
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-pat-vaccs4indication">v_pat_vaccs4indication</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-procedures-at-hospital">v_procedures_at_hospital</a>
 		</h2>
         
-         <p>Lists vaccinations per indication for patients</p>
-        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_pat_vaccs4indication Structure</caption>
+                <caption>clin.v_procedures_at_hospital Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -76498,7 +90453,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
+            	<td>pk_procedure</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -76514,7 +90469,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_vaccination</td>
+            	<td>pk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -76530,7 +90485,39 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>date_given</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>clin_end</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
@@ -76546,8 +90533,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>vaccine</td>
-            	<td>text</td>
+            	<td>is_ongoing</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -76562,7 +90549,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>indication</td>
+            	<td>performed_procedure</td>
             	<td>text</td>
                 <td><i>
 				
@@ -76578,7 +90565,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>l10n_indication</td>
+            	<td>unit</td>
             	<td>text</td>
                 <td><i>
 				
@@ -76594,7 +90581,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>site</td>
+            	<td>organization</td>
             	<td>text</td>
                 <td><i>
 				
@@ -76610,7 +90597,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>batch_no</td>
+            	<td>episode</td>
             	<td>text</td>
                 <td><i>
 				
@@ -76626,7 +90613,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>reaction</td>
+            	<td>health_issue</td>
             	<td>text</td>
                 <td><i>
 				
@@ -76642,8 +90629,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -76658,7 +90645,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
+            	<td>modified_by</td>
             	<td>text</td>
                 <td><i>
 				
@@ -76674,8 +90661,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -76690,8 +90677,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -76706,7 +90693,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>row_version</td>
+            	<td>pk_episode</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -76722,7 +90709,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_vaccine</td>
+            	<td>pk_hospital_stay</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -76738,7 +90725,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_indication</td>
+            	<td>pk_health_issue</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -76754,7 +90741,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_provider</td>
+            	<td>pk_org</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -76770,7 +90757,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
+            	<td>pk_org_unit</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -76786,8 +90773,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>pk_generic_codes</td>
+            	<td>integer[]</td>
                 <td><i>
 				
 
@@ -76802,7 +90789,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>xmin_vaccination</td>
+            	<td>xmin_procedure</td>
             	<td>xid</td>
                 <td><i>
 				
@@ -76833,38 +90820,105 @@ FROM (
 	<!-- View Definition -->
 	
 	<pre>
-SELECT cenc.fk_patient AS pk_patient
-, cv.pk AS pk_vaccination
-, cv.clin_when AS date_given
-, cvi4v.vaccine
-, cvi4v.indication
-, cvi4v.l10n_indication
-, cv.site
-, cv.batch_no
-, cv.reaction
-, cv.narrative AS comment
-, cv.soap_cat
-, cv.modified_when
-, cv.modified_by
-, cv.row_version
-, cv.fk_vaccine AS pk_vaccine
-, cvi4v.pk_indication
-, cv.fk_provider AS pk_provider
-, cv.fk_encounter AS pk_encounter
-, cv.fk_episode AS pk_episode
-, cv.xmin AS xmin_vaccination 
+SELECT c_pr.pk AS pk_procedure
+,
+    c_enc.fk_patient AS pk_patient
+,
+    c_pr.soap_cat
+,
+    c_pr.clin_when
+,
+    c_pr.clin_end
+,
+    c_pr.is_ongoing
+,
+    c_pr.narrative AS performed_procedure
+,
+    c_vhs.ward AS unit
+,
+    c_vhs.hospital AS organization
+,
+    c_ep.description AS episode
+,
+    c_hi.description AS health_issue
+,
+    c_pr.modified_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_pr.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (c_pr.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    c_pr.row_version
+,
+    c_pr.fk_encounter AS pk_encounter
+,
+    c_pr.fk_episode AS pk_episode
+,
+    c_pr.fk_hospital_stay AS pk_hospital_stay
+,
+    c_ep.fk_health_issue AS pk_health_issue
+,
+    c_vhs.pk_org
+,
+    c_vhs.pk_org_unit
+,
+    COALESCE
+(
+     (
+      SELECT array_agg
+           (c_lc2p.fk_generic_code) AS array_agg
+           
+        FROM clin.lnk_code2procedure c_lc2p
+          
+       WHERE (c_lc2p.fk_item = c_pr.pk)
+     )
+     , ARRAY[]::integer[]
+) AS pk_generic_codes
+,
+    c_pr.xmin AS xmin_procedure
+   
 FROM (
-     (clin.vaccination cv 
-        JOIN clin.encounter cenc 
+     (
+           (
+                 (clin.procedure c_pr
+     
+                    JOIN clin.encounter c_enc 
+                      ON (
+                             (c_pr.fk_encounter = c_enc.pk)
+                       )
+                 )
+     
+              JOIN clin.episode c_ep 
+                ON (
+                       (c_pr.fk_episode = c_ep.pk)
+                 )
+           )
+     
+   LEFT JOIN clin.health_issue c_hi 
           ON (
-                 (cenc.pk = cv.fk_encounter)
+                 (c_ep.fk_health_issue = c_hi.pk)
            )
      )
-  JOIN clin.v_indications4vaccine cvi4v 
+     
+LEFT JOIN clin.v_hospital_stays c_vhs 
     ON (
-           (cvi4v.pk_vaccine = cv.fk_vaccine)
+           (c_pr.fk_hospital_stay = c_vhs.pk_hospital_stay)
      )
-);</pre>
+)
+  
+WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
 	
 
 	<!-- List off permissions -->
@@ -76878,13 +90932,13 @@ FROM (
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-potential-problem-list">v_potential_problem_list</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-procedures-at-hospital-journal">v_procedures_at_hospital_journal</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_potential_problem_list Structure</caption>
+                <caption>clin.v_procedures_at_hospital_journal Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -76912,8 +90966,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>problem</td>
-            	<td>text</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -76928,8 +90982,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>summary</td>
-            	<td>text</td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -76944,7 +90998,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>type</td>
+            	<td>modified_by</td>
             	<td>text</td>
                 <td><i>
 				
@@ -76960,7 +91014,7 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>l10n_type</td>
+            	<td>soap_cat</td>
             	<td>text</td>
                 <td><i>
 				
@@ -76976,8 +91030,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>problem_active</td>
-            	<td>boolean</td>
+            	<td>narrative</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -76992,8 +91046,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>clinically_relevant</td>
-            	<td>boolean</td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -77040,8 +91094,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>diagnostic_certainty_classification</td>
-            	<td>text</td>
+            	<td>src_pk</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -77056,8 +91110,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>src_table</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -77072,8 +91126,8 @@ FROM (
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -77084,96 +91138,12 @@ FROM (
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
- WHERE (encounter.pk = cep.fk_encounter)
-) AS pk_patient
-, cep.description AS problem
-, cep.summary
-,'episode'::text AS type
-, _
-('episode'::text) AS l10n_type
-, false AS problem_active
-, false AS clinically_relevant
-, cep.pk AS pk_episode
-, cep.fk_health_issue AS pk_health_issue
-, cep.diagnostic_certainty_classification
-, cep.fk_encounter AS pk_encounter
-, cep.modified_when 
-FROM clin.episode cep 
-WHERE (cep.is_open IS FALSE)
-UNIONSELECT (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
- WHERE (encounter.pk = chi.fk_encounter)
-) AS pk_patient
-, chi.description AS problem
-, chi.summary
-,'issue'::text AS type
-, _
-('health issue'::text) AS l10n_type
-, chi.is_active AS problem_active
-, false AS clinically_relevant
-, NULL::integer AS pk_episode
-, chi.pk AS pk_health_issue
-, chi.diagnostic_certainty_classification
-, chi.fk_encounter AS pk_encounter
-, chi.modified_when 
-FROM clin.health_issue chi 
-WHERE (chi.clinically_relevant IS FALSE);</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-problem-list">v_problem_list</a>
-		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_problem_list Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -77188,8 +91158,8 @@ WHERE (chi.clinically_relevant IS FALSE);</pre>
 				<td>
                 
                 </td>
-            	<td>problem</td>
-            	<td>text</td>
+            	<td>issue_laterality</td>
+            	<td>character varying(2)</td>
                 <td><i>
 				
 
@@ -77204,8 +91174,8 @@ WHERE (chi.clinically_relevant IS FALSE);</pre>
 				<td>
                 
                 </td>
-            	<td>summary</td>
-            	<td>text</td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -77220,8 +91190,8 @@ WHERE (chi.clinically_relevant IS FALSE);</pre>
 				<td>
                 
                 </td>
-            	<td>type</td>
-            	<td>text</td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -77236,8 +91206,8 @@ WHERE (chi.clinically_relevant IS FALSE);</pre>
 				<td>
                 
                 </td>
-            	<td>l10n_type</td>
-            	<td>text</td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -77252,8 +91222,8 @@ WHERE (chi.clinically_relevant IS FALSE);</pre>
 				<td>
                 
                 </td>
-            	<td>problem_active</td>
-            	<td>boolean</td>
+            	<td>episode</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -77268,7 +91238,7 @@ WHERE (chi.clinically_relevant IS FALSE);</pre>
 				<td>
                 
                 </td>
-            	<td>clinically_relevant</td>
+            	<td>episode_open</td>
             	<td>boolean</td>
                 <td><i>
 				
@@ -77284,8 +91254,8 @@ WHERE (chi.clinically_relevant IS FALSE);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -77300,8 +91270,8 @@ WHERE (chi.clinically_relevant IS FALSE);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
-            	<td>integer</td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -77316,7 +91286,7 @@ WHERE (chi.clinically_relevant IS FALSE);</pre>
 				<td>
                 
                 </td>
-            	<td>diagnostic_certainty_classification</td>
+            	<td>encounter_type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -77332,24 +91302,8 @@ WHERE (chi.clinically_relevant IS FALSE);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>encounter_l10n_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -77379,44 +91333,213 @@ WHERE (chi.clinically_relevant IS FALSE);</pre>
 	<!-- View Definition -->
 	
 	<pre>
-SELECT (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
- WHERE (encounter.pk = cep.fk_encounter)
-) AS pk_patient
-, cep.description AS problem
-, cep.summary
-,'episode'::text AS type
-, _
-('episode'::text) AS l10n_type
-, true AS problem_active
-, true AS clinically_relevant
-, cep.pk AS pk_episode
-, cep.fk_health_issue AS pk_health_issue
-, cep.diagnostic_certainty_classification
-, cep.fk_encounter AS pk_encounter
-, cep.modified_when 
-FROM clin.episode cep 
-WHERE (cep.is_open IS TRUE)
-UNIONSELECT (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
- WHERE (encounter.pk = chi.fk_encounter)
-) AS pk_patient
-, chi.description AS problem
-, chi.summary
-,'issue'::text AS type
-, _
-('health issue'::text) AS l10n_type
-, chi.is_active AS problem_active
-, true AS clinically_relevant
-, NULL::integer AS pk_episode
-, chi.pk AS pk_health_issue
-, chi.diagnostic_certainty_classification
-, chi.fk_encounter AS pk_encounter
-, chi.modified_when 
-FROM clin.health_issue chi 
-WHERE (chi.clinically_relevant IS TRUE);</pre>
+SELECT c_enc.fk_patient AS pk_patient
+,
+    c_pr.modified_when
+,
+    c_pr.clin_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_pr.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (c_pr.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    c_pr.soap_cat
+,
+    
+(
+     (
+           (
+                 (
+                       (
+                             (
+                                   (
+                                         (
+                                               (
+                                                     (_
+                                                           ('Procedure'::text) || ' "'::text
+                                                     ) || c_pr.narrative
+                                               ) || '"'::text
+                                         ) || 
+                                      ' ('::text) || d_ou.description
+                                   ) || ' @ '::text
+                             ) || d_o.description
+                       ) || COALESCE
+                       (
+                             (
+                                   (
+                                         (
+                                            ', '::text || _
+                                               ('until'::text)
+                                         ) || ' '::text
+                                   ) || to_char
+                                   (c_pr.clin_end
+                                         ,'YYYY Mon DD'::text
+                                   )
+                             )
+                             ,
+        CASE
+            WHEN 
+                             (c_pr.is_ongoing IS TRUE) THEN 
+                             (
+                                ', '::text || _
+                                   ('ongoing'::text)
+                             )
+            ELSE ''::text
+        END
+                       )
+                 ) || 
+         ')'::text
+     ) || COALESCE
+     (
+           (
+                 ('
+'::text || array_to_string
+                       (
+                             (
+                              SELECT array_agg
+                                   (
+                                         (
+                                               (
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (
+                                                                             (
+                                                                                   (r_csr.code || 
+                                                                                      ' ('::text) || r_ds.name_short
+                                                                                   ) || ' - '::text
+                                                                             ) || r_ds.version
+                                                                       ) || ' - '::text
+                                                                 ) || r_ds.lang
+                                                           ) || 
+                                                 '): '::text
+                                               ) || r_csr.term
+                                         )
+                                   ) AS array_agg
+           
+                                FROM (
+                                         (clin.lnk_code2procedure c_lc2p
+             
+                                            JOIN ref.coding_system_root r_csr 
+                                              ON (
+                                                     (c_lc2p.fk_generic_code = r_csr.pk_coding_system)
+                                               )
+                                         )
+             
+                                      JOIN ref.data_source r_ds 
+                                        ON (
+                                               (r_ds.pk = r_csr.fk_data_source)
+                                         )
+                                   )
+          
+                               WHERE (c_lc2p.fk_item = c_pr.pk)
+                             )
+                             ,'; '::text
+                       )
+                 ) || ';'::text
+           )
+           ,''::text
+     )
+) AS narrative
+,
+    c_pr.fk_encounter AS pk_encounter
+,
+    c_pr.fk_episode AS pk_episode
+,
+    c_epi.fk_health_issue AS pk_health_issue
+,
+    c_pr.pk AS src_pk
+,
+    'clin.procedure'::text AS src_table
+,
+    c_pr.row_version
+,
+    c_hi.description AS health_issue
+,
+    c_hi.laterality AS issue_laterality
+,
+    c_hi.is_active AS issue_active
+,
+    c_hi.clinically_relevant AS issue_clinically_relevant
+,
+    c_hi.is_confidential AS issue_confidential
+,
+    c_epi.description AS episode
+,
+    c_epi.is_open AS episode_open
+,
+    c_enc.started AS encounter_started
+,
+    c_enc.last_affirmed AS encounter_last_affirmed
+,
+    c_ety.description AS encounter_type
+,
+    _
+(c_ety.description) AS encounter_l10n_type
+   
+FROM (
+     (
+           (
+                 (
+                       (
+                             (
+                                   (clin.procedure c_pr
+     
+                                      JOIN clin.encounter c_enc 
+                                        ON (
+                                               (c_pr.fk_encounter = c_enc.pk)
+                                         )
+                                   )
+     
+                                JOIN clin.encounter_type c_ety 
+                                  ON (
+                                         (c_enc.fk_type = c_ety.pk)
+                                   )
+                             )
+     
+                          JOIN clin.episode c_epi 
+                            ON (
+                                   (c_pr.fk_episode = c_epi.pk)
+                             )
+                       )
+     
+               LEFT JOIN clin.health_issue c_hi 
+                      ON (
+                             (c_epi.fk_health_issue = c_hi.pk)
+                       )
+                 )
+     
+         LEFT JOIN clin.hospital_stay c_hs 
+                ON (
+                       (c_pr.fk_hospital_stay = c_hs.pk)
+                 )
+           )
+     
+   LEFT JOIN dem.org_unit d_ou 
+          ON (
+                 (c_hs.fk_org_unit = d_ou.pk)
+           )
+     )
+     
+LEFT JOIN dem.org d_o 
+    ON (
+           (d_ou.fk_org = d_o.pk)
+     )
+)
+  
+WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
 	
 
 	<!-- List off permissions -->
@@ -77430,13 +91553,13 @@ WHERE (chi.clinically_relevant IS TRUE);</pre>
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-procedures">v_procedures</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-procedures-journal">v_procedures_journal</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_procedures Structure</caption>
+                <caption>clin.v_procedures_journal Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -77448,7 +91571,7 @@ WHERE (chi.clinically_relevant IS TRUE);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_procedure</td>
+            	<td>pk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -77464,8 +91587,40 @@ WHERE (chi.clinically_relevant IS TRUE);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -77496,8 +91651,8 @@ WHERE (chi.clinically_relevant IS TRUE);</pre>
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>narrative</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -77512,8 +91667,8 @@ WHERE (chi.clinically_relevant IS TRUE);</pre>
 				<td>
                 
                 </td>
-            	<td>clin_end</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -77528,8 +91683,8 @@ WHERE (chi.clinically_relevant IS TRUE);</pre>
 				<td>
                 
                 </td>
-            	<td>is_ongoing</td>
-            	<td>boolean</td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -77544,8 +91699,8 @@ WHERE (chi.clinically_relevant IS TRUE);</pre>
 				<td>
                 
                 </td>
-            	<td>performed_procedure</td>
-            	<td>text</td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -77560,7 +91715,23 @@ WHERE (chi.clinically_relevant IS TRUE);</pre>
 				<td>
                 
                 </td>
-            	<td>unit</td>
+            	<td>src_pk</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>src_table</td>
             	<td>text</td>
                 <td><i>
 				
@@ -77572,11 +91743,27 @@ WHERE (chi.clinically_relevant IS TRUE);</pre>
 				</td>
 			 </tr>
             
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>organization</td>
+            	<td>health_issue</td>
             	<td>text</td>
                 <td><i>
 				
@@ -77592,6 +91779,70 @@ WHERE (chi.clinically_relevant IS TRUE);</pre>
 				<td>
                 
                 </td>
+            	<td>issue_laterality</td>
+            	<td>character varying(2)</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
             	<td>episode</td>
             	<td>text</td>
                 <td><i>
@@ -77608,8 +91859,8 @@ WHERE (chi.clinically_relevant IS TRUE);</pre>
 				<td>
                 
                 </td>
-            	<td>health_issue</td>
-            	<td>text</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -77624,7 +91875,7 @@ WHERE (chi.clinically_relevant IS TRUE);</pre>
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
+            	<td>encounter_started</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
@@ -77640,104 +91891,8 @@ WHERE (chi.clinically_relevant IS TRUE);</pre>
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>row_version</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_hospital_stay</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>pk_health_issue</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_org</td>
-            	<td>integer</td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -77752,8 +91907,8 @@ WHERE (chi.clinically_relevant IS TRUE);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_org_unit</td>
-            	<td>integer</td>
+            	<td>encounter_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -77768,24 +91923,8 @@ WHERE (chi.clinically_relevant IS TRUE);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_generic_codes</td>
-            	<td>integer[]</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>xmin_procedure</td>
-            	<td>xid</td>
+            	<td>encounter_l10n_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -77815,52 +91954,103 @@ WHERE (chi.clinically_relevant IS TRUE);</pre>
 	<!-- View Definition -->
 	
 	<pre>
-SELECT v_procedures_at_hospital.pk_procedure
-, v_procedures_at_hospital.pk_patient
-, v_procedures_at_hospital.soap_cat
-, v_procedures_at_hospital.clin_when
-, v_procedures_at_hospital.clin_end
-, v_procedures_at_hospital.is_ongoing
-, v_procedures_at_hospital.performed_procedure
-, v_procedures_at_hospital.unit
-, v_procedures_at_hospital.organization
-, v_procedures_at_hospital.episode
-, v_procedures_at_hospital.health_issue
-, v_procedures_at_hospital.modified_when
-, v_procedures_at_hospital.modified_by
-, v_procedures_at_hospital.row_version
-, v_procedures_at_hospital.pk_encounter
-, v_procedures_at_hospital.pk_episode
-, v_procedures_at_hospital.pk_hospital_stay
-, v_procedures_at_hospital.pk_health_issue
-, v_procedures_at_hospital.pk_org
-, v_procedures_at_hospital.pk_org_unit
-, v_procedures_at_hospital.pk_generic_codes
-, v_procedures_at_hospital.xmin_procedure 
-FROM clin.v_procedures_at_hospital 
-UNION ALLSELECT v_procedures_not_at_hospital.pk_procedure
-, v_procedures_not_at_hospital.pk_patient
-, v_procedures_not_at_hospital.soap_cat
-, v_procedures_not_at_hospital.clin_when
-, v_procedures_not_at_hospital.clin_end
-, v_procedures_not_at_hospital.is_ongoing
-, v_procedures_not_at_hospital.performed_procedure
-, v_procedures_not_at_hospital.unit
-, v_procedures_not_at_hospital.organization
-, v_procedures_not_at_hospital.episode
-, v_procedures_not_at_hospital.health_issue
-, v_procedures_not_at_hospital.modified_when
-, v_procedures_not_at_hospital.modified_by
-, v_procedures_not_at_hospital.row_version
-, v_procedures_not_at_hospital.pk_encounter
-, v_procedures_not_at_hospital.pk_episode
-, v_procedures_not_at_hospital.pk_hospital_stay
-, v_procedures_not_at_hospital.pk_health_issue
-, v_procedures_not_at_hospital.pk_org
-, v_procedures_not_at_hospital.pk_org_unit
-, v_procedures_not_at_hospital.pk_generic_codes
-, v_procedures_not_at_hospital.xmin_procedure 
-FROM clin.v_procedures_not_at_hospital;</pre>
+SELECT v_procedures_at_hospital_journal.pk_patient
+,
+    v_procedures_at_hospital_journal.modified_when
+,
+    v_procedures_at_hospital_journal.clin_when
+,
+    v_procedures_at_hospital_journal.modified_by
+,
+    v_procedures_at_hospital_journal.soap_cat
+,
+    v_procedures_at_hospital_journal.narrative
+,
+    v_procedures_at_hospital_journal.pk_encounter
+,
+    v_procedures_at_hospital_journal.pk_episode
+,
+    v_procedures_at_hospital_journal.pk_health_issue
+,
+    v_procedures_at_hospital_journal.src_pk
+,
+    v_procedures_at_hospital_journal.src_table
+,
+    v_procedures_at_hospital_journal.row_version
+,
+    v_procedures_at_hospital_journal.health_issue
+,
+    v_procedures_at_hospital_journal.issue_laterality
+,
+    v_procedures_at_hospital_journal.issue_active
+,
+    v_procedures_at_hospital_journal.issue_clinically_relevant
+,
+    v_procedures_at_hospital_journal.issue_confidential
+,
+    v_procedures_at_hospital_journal.episode
+,
+    v_procedures_at_hospital_journal.episode_open
+,
+    v_procedures_at_hospital_journal.encounter_started
+,
+    v_procedures_at_hospital_journal.encounter_last_affirmed
+,
+    v_procedures_at_hospital_journal.encounter_type
+,
+    v_procedures_at_hospital_journal.encounter_l10n_type
+   
+FROM clin.v_procedures_at_hospital_journal
+
+UNION ALL
+ 
+SELECT v_procedures_not_at_hospital_journal.pk_patient
+,
+    v_procedures_not_at_hospital_journal.modified_when
+,
+    v_procedures_not_at_hospital_journal.clin_when
+,
+    v_procedures_not_at_hospital_journal.modified_by
+,
+    v_procedures_not_at_hospital_journal.soap_cat
+,
+    v_procedures_not_at_hospital_journal.narrative
+,
+    v_procedures_not_at_hospital_journal.pk_encounter
+,
+    v_procedures_not_at_hospital_journal.pk_episode
+,
+    v_procedures_not_at_hospital_journal.pk_health_issue
+,
+    v_procedures_not_at_hospital_journal.src_pk
+,
+    v_procedures_not_at_hospital_journal.src_table
+,
+    v_procedures_not_at_hospital_journal.row_version
+,
+    v_procedures_not_at_hospital_journal.health_issue
+,
+    v_procedures_not_at_hospital_journal.issue_laterality
+,
+    v_procedures_not_at_hospital_journal.issue_active
+,
+    v_procedures_not_at_hospital_journal.issue_clinically_relevant
+,
+    v_procedures_not_at_hospital_journal.issue_confidential
+,
+    v_procedures_not_at_hospital_journal.episode
+,
+    v_procedures_not_at_hospital_journal.episode_open
+,
+    v_procedures_not_at_hospital_journal.encounter_started
+,
+    v_procedures_not_at_hospital_journal.encounter_last_affirmed
+,
+    v_procedures_not_at_hospital_journal.encounter_type
+,
+    v_procedures_not_at_hospital_journal.encounter_l10n_type
+   
+FROM clin.v_procedures_not_at_hospital_journal;</pre>
 	
 
 	<!-- List off permissions -->
@@ -77874,13 +92064,13 @@ FROM clin.v_procedures_not_at_hospital;</pre>
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-procedures-at-hospital">v_procedures_at_hospital</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-procedures-not-at-hospital">v_procedures_not_at_hospital</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_procedures_at_hospital Structure</caption>
+                <caption>clin.v_procedures_not_at_hospital Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -78260,22 +92450,36 @@ FROM clin.v_procedures_not_at_hospital;</pre>
 	
 	<pre>
 SELECT c_pr.pk AS pk_procedure
-, c_enc.fk_patient AS pk_patient
-, c_pr.soap_cat
-, c_pr.clin_when
-, c_pr.clin_end
-, c_pr.is_ongoing
-, c_pr.narrative AS performed_procedure
-, c_vhs.ward AS unit
-, c_vhs.hospital AS organization
-, c_ep.description AS episode
-, c_hi.description AS health_issue
-, c_pr.modified_when
-, COALESCE
+,
+    c_enc.fk_patient AS pk_patient
+,
+    c_pr.soap_cat
+,
+    c_pr.clin_when
+,
+    c_pr.clin_end
+,
+    c_pr.is_ongoing
+,
+    c_pr.narrative AS performed_procedure
+,
+    d_ou.description AS unit
+,
+    d_o.description AS organization
+,
+    c_ep.description AS episode
+,
+    c_hi.description AS health_issue
+,
+    c_pr.modified_when
+,
+    COALESCE
 (
      (
-      SELECT staff.short_alias 
-        FROM dem.staff 
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
        WHERE (staff.db_user = c_pr.modified_by)
      )
      , (
@@ -78284,49 +92488,73 @@ SELECT c_pr.pk AS pk_procedure
            ) || '>'::text
      )
 ) AS modified_by
-, c_pr.row_version
-, c_pr.fk_encounter AS pk_encounter
-, c_pr.fk_episode AS pk_episode
-, c_pr.fk_hospital_stay AS pk_hospital_stay
-, c_ep.fk_health_issue AS pk_health_issue
-, c_vhs.pk_org
-, c_vhs.pk_org_unit
-, COALESCE
+,
+    c_pr.row_version
+,
+    c_pr.fk_encounter AS pk_encounter
+,
+    c_pr.fk_episode AS pk_episode
+,
+    c_pr.fk_hospital_stay AS pk_hospital_stay
+,
+    c_ep.fk_health_issue AS pk_health_issue
+,
+    d_o.pk AS pk_org
+,
+    d_ou.pk AS pk_org_unit
+,
+    COALESCE
 (
      (
       SELECT array_agg
-           (c_lc2p.fk_generic_code) AS array_agg 
-        FROM clin.lnk_code2procedure c_lc2p 
+           (c_lc2p.fk_generic_code) AS array_agg
+           
+        FROM clin.lnk_code2procedure c_lc2p
+          
        WHERE (c_lc2p.fk_item = c_pr.pk)
      )
      , ARRAY[]::integer[]
 ) AS pk_generic_codes
-, c_pr.xmin AS xmin_procedure 
+,
+    c_pr.xmin AS xmin_procedure
+   
 FROM (
      (
            (
-                 (clin.procedure c_pr 
-                    JOIN clin.encounter c_enc 
+                 (
+                       (clin.procedure c_pr
+     
+                          JOIN clin.encounter c_enc 
+                            ON (
+                                   (c_pr.fk_encounter = c_enc.pk)
+                             )
+                       )
+     
+                    JOIN clin.episode c_ep 
                       ON (
-                             (c_pr.fk_encounter = c_enc.pk)
+                             (c_pr.fk_episode = c_ep.pk)
                        )
                  )
-              JOIN clin.episode c_ep 
+     
+         LEFT JOIN clin.health_issue c_hi 
                 ON (
-                       (c_pr.fk_episode = c_ep.pk)
+                       (c_ep.fk_health_issue = c_hi.pk)
                  )
            )
-   LEFT JOIN clin.health_issue c_hi 
+     
+   LEFT JOIN dem.org_unit d_ou 
           ON (
-                 (c_ep.fk_health_issue = c_hi.pk)
+                 (d_ou.pk = c_pr.fk_org_unit)
            )
      )
-LEFT JOIN clin.v_hospital_stays c_vhs 
+     
+LEFT JOIN dem.org d_o 
     ON (
-           (c_pr.fk_hospital_stay = c_vhs.pk_hospital_stay)
+           (d_o.pk = d_ou.fk_org)
      )
 )
-WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
+  
+WHERE (c_pr.fk_hospital_stay IS NULL);</pre>
 	
 
 	<!-- List off permissions -->
@@ -78340,13 +92568,13 @@ WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-procedures-at-hospital-journal">v_procedures_at_hospital_journal</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-procedures-not-at-hospital-journal">v_procedures_not_at_hospital_journal</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_procedures_at_hospital_journal Structure</caption>
+                <caption>clin.v_procedures_not_at_hospital_journal Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -78358,7 +92586,135 @@ WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>soap_cat</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>narrative</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_health_issue</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -78374,8 +92730,8 @@ WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>src_pk</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -78390,8 +92746,8 @@ WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>src_table</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -78406,8 +92762,8 @@ WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>text</td>
+            	<td>row_version</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -78422,7 +92778,7 @@ WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
+            	<td>health_issue</td>
             	<td>text</td>
                 <td><i>
 				
@@ -78438,8 +92794,8 @@ WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>narrative</td>
-            	<td>text</td>
+            	<td>issue_laterality</td>
+            	<td>character varying(2)</td>
                 <td><i>
 				
 
@@ -78454,8 +92810,8 @@ WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -78470,8 +92826,8 @@ WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -78486,8 +92842,8 @@ WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
-            	<td>integer</td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -78502,8 +92858,8 @@ WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>src_pk</td>
-            	<td>integer</td>
+            	<td>episode</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -78518,8 +92874,8 @@ WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>src_table</td>
-            	<td>text</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -78534,8 +92890,56 @@ WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>encounter_type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>encounter_l10n_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -78566,13 +92970,18 @@ WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
 	
 	<pre>
 SELECT c_enc.fk_patient AS pk_patient
-, c_pr.modified_when
-, c_pr.clin_when
-, COALESCE
+,
+    c_pr.modified_when
+,
+    c_pr.clin_when
+,
+    COALESCE
 (
      (
-      SELECT staff.short_alias 
-        FROM dem.staff 
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
        WHERE (staff.db_user = c_pr.modified_by)
      )
      , (
@@ -78581,8 +92990,11 @@ SELECT c_enc.fk_patient AS pk_patient
            ) || '>'::text
      )
 ) AS modified_by
-, c_pr.soap_cat
-, (
+,
+    c_pr.soap_cat
+,
+    
+(
      (
            (
                  (
@@ -78612,12 +93024,16 @@ SELECT c_enc.fk_patient AS pk_patient
                                          ,'YYYY Mon DD'::text
                                    )
                              )
-                             , CASE WHEN 
+                             ,
+        CASE
+            WHEN 
                              (c_pr.is_ongoing IS TRUE) THEN 
                              (
                                 ', '::text || _
                                    ('ongoing'::text)
-                             ) ELSE ''::text END
+                             )
+            ELSE ''::text
+        END
                        )
                  ) || 
          ')'::text
@@ -78647,19 +93063,23 @@ SELECT c_enc.fk_patient AS pk_patient
                                                  '): '::text
                                                ) || r_csr.term
                                          )
-                                   ) AS array_agg 
+                                   ) AS array_agg
+           
                                 FROM (
-                                         (clin.lnk_code2procedure c_lc2p 
+                                         (clin.lnk_code2procedure c_lc2p
+             
                                             JOIN ref.coding_system_root r_csr 
                                               ON (
                                                      (c_lc2p.fk_generic_code = r_csr.pk_coding_system)
                                                )
                                          )
+             
                                       JOIN ref.data_source r_ds 
                                         ON (
                                                (r_ds.pk = r_csr.fk_data_source)
                                          )
                                    )
+          
                                WHERE (c_lc2p.fk_item = c_pr.pk)
                              )
                              ,'; '::text
@@ -78669,43 +93089,86 @@ SELECT c_enc.fk_patient AS pk_patient
            ,''::text
      )
 ) AS narrative
-, c_pr.fk_encounter AS pk_encounter
-, c_pr.fk_episode AS pk_episode
-, cep.fk_health_issue AS pk_health_issue
-, c_pr.pk AS src_pk
-,'clin.procedure'::text AS src_table
-, c_pr.row_version 
+,
+    c_pr.fk_encounter AS pk_encounter
+,
+    c_pr.fk_episode AS pk_episode
+,
+    c_epi.fk_health_issue AS pk_health_issue
+,
+    c_pr.pk AS src_pk
+,
+    'clin.procedure'::text AS src_table
+,
+    c_pr.row_version
+,
+    c_hi.description AS health_issue
+,
+    c_hi.laterality AS issue_laterality
+,
+    c_hi.is_active AS issue_active
+,
+    c_hi.clinically_relevant AS issue_clinically_relevant
+,
+    c_hi.is_confidential AS issue_confidential
+,
+    c_epi.description AS episode
+,
+    c_epi.is_open AS episode_open
+,
+    c_enc.started AS encounter_started
+,
+    c_enc.last_affirmed AS encounter_last_affirmed
+,
+    c_ety.description AS encounter_type
+,
+    _
+(c_ety.description) AS encounter_l10n_type
+   
 FROM (
      (
            (
                  (
-                       (clin.procedure c_pr 
-                          JOIN clin.encounter c_enc 
+                       (
+                             (clin.procedure c_pr
+     
+                                JOIN clin.encounter c_enc 
+                                  ON (
+                                         (c_pr.fk_encounter = c_enc.pk)
+                                   )
+                             )
+     
+                          JOIN clin.encounter_type c_ety 
                             ON (
-                                   (c_pr.fk_encounter = c_enc.pk)
+                                   (c_enc.fk_type = c_ety.pk)
                              )
                        )
-                    JOIN clin.episode cep 
+     
+                    JOIN clin.episode c_epi 
                       ON (
-                             (c_pr.fk_episode = cep.pk)
+                             (c_pr.fk_episode = c_epi.pk)
                        )
                  )
-         LEFT JOIN clin.hospital_stay c_hs 
+     
+         LEFT JOIN clin.health_issue c_hi 
                 ON (
-                       (c_pr.fk_hospital_stay = c_hs.pk)
+                       (c_epi.fk_health_issue = c_hi.pk)
                  )
            )
+     
    LEFT JOIN dem.org_unit d_ou 
           ON (
-                 (c_hs.fk_org_unit = d_ou.pk)
+                 (c_pr.fk_org_unit = d_ou.pk)
            )
      )
+     
 LEFT JOIN dem.org d_o 
     ON (
            (d_ou.fk_org = d_o.pk)
      )
 )
-WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
+  
+WHERE (c_pr.fk_hospital_stay IS NULL);</pre>
 	
 
 	<!-- List off permissions -->
@@ -78719,13 +93182,13 @@ WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-procedures-journal">v_procedures_journal</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-reminders-journal">v_reminders_journal</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_procedures_journal Structure</caption>
+                <caption>clin.v_reminders_journal Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -78925,6 +93388,182 @@ WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
 				</td>
 			 </tr>
             
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>health_issue</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>issue_laterality</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>episode</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>encounter_type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>encounter_l10n_type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
         </table>
 
         <!-- Inherits -->
@@ -78940,36 +93579,675 @@ WHERE (c_pr.fk_hospital_stay IS NOT NULL);</pre>
 
     <!-- Indexes -->
     
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT v_procedures_at_hospital_journal.pk_patient
-, v_procedures_at_hospital_journal.modified_when
-, v_procedures_at_hospital_journal.clin_when
-, v_procedures_at_hospital_journal.modified_by
-, v_procedures_at_hospital_journal.soap_cat
-, v_procedures_at_hospital_journal.narrative
-, v_procedures_at_hospital_journal.pk_encounter
-, v_procedures_at_hospital_journal.pk_episode
-, v_procedures_at_hospital_journal.pk_health_issue
-, v_procedures_at_hospital_journal.src_pk
-, v_procedures_at_hospital_journal.src_table
-, v_procedures_at_hospital_journal.row_version 
-FROM clin.v_procedures_at_hospital_journal 
-UNION ALLSELECT v_procedures_not_at_hospital_journal.pk_patient
-, v_procedures_not_at_hospital_journal.modified_when
-, v_procedures_not_at_hospital_journal.clin_when
-, v_procedures_not_at_hospital_journal.modified_by
-, v_procedures_not_at_hospital_journal.soap_cat
-, v_procedures_not_at_hospital_journal.narrative
-, v_procedures_not_at_hospital_journal.pk_encounter
-, v_procedures_not_at_hospital_journal.pk_episode
-, v_procedures_not_at_hospital_journal.pk_health_issue
-, v_procedures_not_at_hospital_journal.src_pk
-, v_procedures_not_at_hospital_journal.src_table
-, v_procedures_not_at_hospital_journal.row_version 
-FROM clin.v_procedures_not_at_hospital_journal;</pre>
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT d_mi.fk_patient AS pk_patient
+,
+    d_mi.modified_when
+,
+    d_mi.due_date AS clin_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = d_mi.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (d_mi.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    NULL::text AS soap_cat
+,
+    
+(
+     (
+           (
+                 (
+                       (
+                             (
+                                   (
+                                         (
+                                               (
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (
+                                                                             (
+                                                                                   (
+                                                                                         (_
+                                                                                               ('Due today'::text) || 
+                                                                                            ' ('::text) || d_vit.l10n_category
+                                                                                         ) || ' - '::text
+                                                                                   ) || d_vit.l10n_type
+                                                                             ) || 
+                                                                     ')'::text
+                                                                 ) || '
+'::text
+                                                           ) || COALESCE
+                                                           (
+                                                                 (
+                                                                       (' '::text || d_mi.comment) || '
+'::text
+                                                                 )
+                                                                 ,''::text
+                                                           )
+                                                     ) || COALESCE
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (
+                                                                             (' '::text || _
+                                                                                   ('Will expire:'::text)
+                                                                             ) || ' '::text
+                                                                       ) || to_char
+                                                                       (
+                                                                             (d_mi.expiry_date)::timestamp with time zone
+                                                                             ,'YYYY-MM-DD'::text
+                                                                       )
+                                                                 ) || '
+'::text
+                                                           )
+                                                           ,''::text
+                                                     )
+                                               ) || ' '::text
+                                         ) || _
+                                         ('Importance:'::text)
+                                   ) || ' '::text
+                             ) || d_mi.importance
+                       ) || '
+'::text
+                 ) || COALESCE
+                 (
+                       (
+                             (
+                                   (
+                                         (' '::text || _
+                                               ('Context:'::text)
+                                         ) || ' '::text
+                                   ) || array_to_string
+                                   (d_mi.ufk_context
+                                         ,','::text
+                                         ,'?'::text
+                                   )
+                             ) || '
+'::text
+                       )
+                       ,''::text
+                 )
+           ) || COALESCE
+           (
+                 (
+                       (
+                             (
+                                   (' '::text || _
+                                         ('Data:'::text)
+                                   ) || ' '::text
+                             ) || d_mi.data
+                       ) || '
+'::text
+                 )
+                 ,''::text
+           )
+     ) || COALESCE
+     (
+           (
+                 (
+                       (' '::text || _
+                             ('Provider:'::text)
+                       ) || ' '::text
+                 ) || d_st.short_alias
+           )
+           ,''::text
+     )
+) AS narrative
+,
+    
+(
+SELECT c_e.pk
+           
+  FROM clin.encounter c_e
+          
+ WHERE (c_e.fk_patient = d_mi.fk_patient)
+          
+ORDER BY c_e.started DESC
+         LIMIT 1
+) AS pk_encounter
+,
+    NULL::integer AS pk_episode
+,
+    NULL::integer AS pk_health_issue
+,
+    d_mi.pk AS src_pk
+,
+    'dem.message_inbox'::text AS src_table
+,
+    d_mi.row_version
+,
+    NULL::text AS health_issue
+,
+    NULL::text AS issue_laterality
+,
+    NULL::boolean AS issue_active
+,
+    NULL::boolean AS issue_clinically_relevant
+,
+    NULL::boolean AS issue_confidential
+,
+    NULL::text AS episode
+,
+    NULL::boolean AS episode_open
+,
+    
+(
+SELECT c_e.started
+           
+  FROM clin.encounter c_e
+          
+ WHERE (c_e.fk_patient = d_mi.fk_patient)
+          
+ORDER BY c_e.started DESC
+         LIMIT 1
+) AS encounter_started
+,
+    
+(
+SELECT c_e.last_affirmed
+           
+  FROM clin.encounter c_e
+          
+ WHERE (c_e.fk_patient = d_mi.fk_patient)
+          
+ORDER BY c_e.started DESC
+         LIMIT 1
+) AS encounter_last_affirmed
+,
+    NULL::text AS encounter_type
+,
+    NULL::text AS encounter_l10n_type
+   
+FROM (
+     (dem.message_inbox d_mi
+     
+        JOIN dem.v_inbox_item_type d_vit 
+          ON (
+                 (d_mi.fk_inbox_item_type = d_vit.pk_type)
+           )
+     )
+     
+LEFT JOIN dem.staff d_st 
+    ON (
+           (d_mi.fk_staff = d_st.pk)
+     )
+)
+  
+WHERE (
+     (
+           (d_mi.fk_patient IS NOT NULL)
+         AND (d_vit.category = 'clinical'::text)
+     )
+   AND (d_mi.due_date IS NOT NULL)
+)
+UNION
+ 
+SELECT d_mi.fk_patient AS pk_patient
+,
+    d_mi.modified_when
+,
+    d_mi.expiry_date AS clin_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = d_mi.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (d_mi.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    NULL::text AS soap_cat
+,
+    
+(
+     (
+           (
+                 (
+                       (
+                             (
+                                   (
+                                         (
+                                               (
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (
+                                                                             (
+                                                                                   (
+                                                                                         (_
+                                                                                               ('Epires today'::text) || 
+                                                                                            ' ('::text) || d_vit.l10n_category
+                                                                                         ) || ' - '::text
+                                                                                   ) || d_vit.l10n_type
+                                                                             ) || 
+                                                                     ')'::text
+                                                                 ) || '
+'::text
+                                                           ) || COALESCE
+                                                           (
+                                                                 (
+                                                                       (' '::text || d_mi.comment) || '
+'::text
+                                                                 )
+                                                                 ,''::text
+                                                           )
+                                                     ) || COALESCE
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (
+                                                                             (' '::text || _
+                                                                                   ('Was due:'::text)
+                                                                             ) || ' '::text
+                                                                       ) || to_char
+                                                                       (
+                                                                             (d_mi.due_date)::timestamp with time zone
+                                                                             ,'YYYY-MM-DD'::text
+                                                                       )
+                                                                 ) || '
+'::text
+                                                           )
+                                                           ,''::text
+                                                     )
+                                               ) || ' '::text
+                                         ) || _
+                                         ('Importance:'::text)
+                                   ) || ' '::text
+                             ) || d_mi.importance
+                       ) || '
+'::text
+                 ) || COALESCE
+                 (
+                       (
+                             (
+                                   (
+                                         (' '::text || _
+                                               ('Context:'::text)
+                                         ) || ' '::text
+                                   ) || array_to_string
+                                   (d_mi.ufk_context
+                                         ,','::text
+                                         ,'?'::text
+                                   )
+                             ) || '
+'::text
+                       )
+                       ,''::text
+                 )
+           ) || COALESCE
+           (
+                 (
+                       (
+                             (
+                                   (' '::text || _
+                                         ('Data:'::text)
+                                   ) || ' '::text
+                             ) || d_mi.data
+                       ) || '
+'::text
+                 )
+                 ,''::text
+           )
+     ) || COALESCE
+     (
+           (
+                 (
+                       (' '::text || _
+                             ('Provider:'::text)
+                       ) || ' '::text
+                 ) || d_st.short_alias
+           )
+           ,''::text
+     )
+) AS narrative
+,
+    
+(
+SELECT c_e.pk
+           
+  FROM clin.encounter c_e
+          
+ WHERE (c_e.fk_patient = d_mi.fk_patient)
+          
+ORDER BY c_e.started DESC
+         LIMIT 1
+) AS pk_encounter
+,
+    NULL::integer AS pk_episode
+,
+    NULL::integer AS pk_health_issue
+,
+    d_mi.pk AS src_pk
+,
+    'dem.message_inbox'::text AS src_table
+,
+    d_mi.row_version
+,
+    NULL::text AS health_issue
+,
+    NULL::text AS issue_laterality
+,
+    NULL::boolean AS issue_active
+,
+    NULL::boolean AS issue_clinically_relevant
+,
+    NULL::boolean AS issue_confidential
+,
+    NULL::text AS episode
+,
+    NULL::boolean AS episode_open
+,
+    
+(
+SELECT c_e.started
+           
+  FROM clin.encounter c_e
+          
+ WHERE (c_e.fk_patient = d_mi.fk_patient)
+          
+ORDER BY c_e.started DESC
+         LIMIT 1
+) AS encounter_started
+,
+    
+(
+SELECT c_e.last_affirmed
+           
+  FROM clin.encounter c_e
+          
+ WHERE (c_e.fk_patient = d_mi.fk_patient)
+          
+ORDER BY c_e.started DESC
+         LIMIT 1
+) AS encounter_last_affirmed
+,
+    NULL::text AS encounter_type
+,
+    NULL::text AS encounter_l10n_type
+   
+FROM (
+     (dem.message_inbox d_mi
+     
+        JOIN dem.v_inbox_item_type d_vit 
+          ON (
+                 (d_mi.fk_inbox_item_type = d_vit.pk_type)
+           )
+     )
+     
+LEFT JOIN dem.staff d_st 
+    ON (
+           (d_mi.fk_staff = d_st.pk)
+     )
+)
+  
+WHERE (
+     (
+           (d_mi.fk_patient IS NOT NULL)
+         AND (d_vit.category = 'clinical'::text)
+     )
+   AND (d_mi.expiry_date IS NOT NULL)
+)
+UNION
+ 
+SELECT d_mi.fk_patient AS pk_patient
+,
+    d_mi.modified_when
+,
+    d_mi.modified_when AS clin_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = d_mi.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (d_mi.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    NULL::text AS soap_cat
+,
+    
+(
+     (
+           (
+                 (
+                       (
+                             (
+                                   (
+                                         (
+                                               (
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (
+                                                                             (
+                                                                                   (
+                                                                                         (
+                                                                                               (_
+                                                                                                     ('Clinical reminder'::text) || 
+                                                                                                  ' ('::text) || d_vit.l10n_category
+                                                                                               ) || ' - '::text
+                                                                                         ) || d_vit.l10n_type
+                                                                                   ) || 
+                                                                           ')'::text
+                                                                       ) || '
+'::text
+                                                                 ) || COALESCE
+                                                                 (
+                                                                       (
+                                                                             (' '::text || d_mi.comment) || '
+'::text
+                                                                       )
+                                                                       ,''::text
+                                                                 )
+                                                           ) || COALESCE
+                                                           (
+                                                                 (
+                                                                       (
+                                                                             (
+                                                                                   (' '::text || _
+                                                                                         ('Due:'::text)
+                                                                                   ) || ' '::text
+                                                                             ) || to_char
+                                                                             (
+                                                                                   (d_mi.due_date)::timestamp with time zone
+                                                                                   ,'YYYY-MM-DD'::text
+                                                                             )
+                                                                       ) || '
+'::text
+                                                                 )
+                                                                 ,''::text
+                                                           )
+                                                     ) || COALESCE
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (
+                                                                             (' '::text || _
+                                                                                   ('Expires:'::text)
+                                                                             ) || ' '::text
+                                                                       ) || to_char
+                                                                       (
+                                                                             (d_mi.expiry_date)::timestamp with time zone
+                                                                             ,'YYYY-MM-DD'::text
+                                                                       )
+                                                                 ) || '
+'::text
+                                                           )
+                                                           ,''::text
+                                                     )
+                                               ) || ' '::text
+                                         ) || _
+                                         ('Importance:'::text)
+                                   ) || ' '::text
+                             ) || d_mi.importance
+                       ) || '
+'::text
+                 ) || COALESCE
+                 (
+                       (
+                             (
+                                   (
+                                         (' '::text || _
+                                               ('Context:'::text)
+                                         ) || ' '::text
+                                   ) || array_to_string
+                                   (d_mi.ufk_context
+                                         ,','::text
+                                         ,'?'::text
+                                   )
+                             ) || '
+'::text
+                       )
+                       ,''::text
+                 )
+           ) || COALESCE
+           (
+                 (
+                       (
+                             (
+                                   (' '::text || _
+                                         ('Data:'::text)
+                                   ) || ' '::text
+                             ) || d_mi.data
+                       ) || '
+'::text
+                 )
+                 ,''::text
+           )
+     ) || COALESCE
+     (
+           (
+                 (
+                       (' '::text || _
+                             ('Provider:'::text)
+                       ) || ' '::text
+                 ) || d_st.short_alias
+           )
+           ,''::text
+     )
+) AS narrative
+,
+    
+(
+SELECT c_e.pk
+           
+  FROM clin.encounter c_e
+          
+ WHERE (c_e.fk_patient = d_mi.fk_patient)
+          
+ORDER BY c_e.started DESC
+         LIMIT 1
+) AS pk_encounter
+,
+    NULL::integer AS pk_episode
+,
+    NULL::integer AS pk_health_issue
+,
+    d_mi.pk AS src_pk
+,
+    'dem.message_inbox'::text AS src_table
+,
+    d_mi.row_version
+,
+    NULL::text AS health_issue
+,
+    NULL::text AS issue_laterality
+,
+    NULL::boolean AS issue_active
+,
+    NULL::boolean AS issue_clinically_relevant
+,
+    NULL::boolean AS issue_confidential
+,
+    NULL::text AS episode
+,
+    NULL::boolean AS episode_open
+,
+    
+(
+SELECT c_e.started
+           
+  FROM clin.encounter c_e
+          
+ WHERE (c_e.fk_patient = d_mi.fk_patient)
+          
+ORDER BY c_e.started DESC
+         LIMIT 1
+) AS encounter_started
+,
+    
+(
+SELECT c_e.last_affirmed
+           
+  FROM clin.encounter c_e
+          
+ WHERE (c_e.fk_patient = d_mi.fk_patient)
+          
+ORDER BY c_e.started DESC
+         LIMIT 1
+) AS encounter_last_affirmed
+,
+    NULL::text AS encounter_type
+,
+    NULL::text AS encounter_l10n_type
+   
+FROM (
+     (dem.message_inbox d_mi
+     
+        JOIN dem.v_inbox_item_type d_vit 
+          ON (
+                 (d_mi.fk_inbox_item_type = d_vit.pk_type)
+           )
+     )
+     
+LEFT JOIN dem.staff d_st 
+    ON (
+           (d_mi.fk_staff = d_st.pk)
+     )
+)
+  
+WHERE (
+     (
+           (d_mi.fk_patient IS NOT NULL)
+         AND (d_vit.category = 'clinical'::text)
+     )
+   AND (
+           (d_mi.due_date IS NOT NULL)
+          OR (d_mi.expiry_date IS NOT NULL)
+     )
+);</pre>
 	
 
 	<!-- List off permissions -->
@@ -78983,13 +94261,15 @@ FROM clin.v_procedures_not_at_hospital_journal;</pre>
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-procedures-not-at-hospital">v_procedures_not_at_hospital</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-reviewed-items">v_reviewed_items</a>
 		</h2>
         
+         <p>denormalization of parent table of reviewed items</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_procedures_not_at_hospital Structure</caption>
+                <caption>clin.v_reviewed_items Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -79001,40 +94281,8 @@ FROM clin.v_procedures_not_at_hospital_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_procedure</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>src_schema</td>
+            	<td>oid</td>
                 <td><i>
 				
 
@@ -79049,8 +94297,8 @@ FROM clin.v_procedures_not_at_hospital_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>src_table</td>
+            	<td>name</td>
                 <td><i>
 				
 
@@ -79065,8 +94313,8 @@ FROM clin.v_procedures_not_at_hospital_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>clin_end</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_reviewed_row</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -79081,7 +94329,7 @@ FROM clin.v_procedures_not_at_hospital_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>is_ongoing</td>
+            	<td>is_technically_abnormal</td>
             	<td>boolean</td>
                 <td><i>
 				
@@ -79097,8 +94345,8 @@ FROM clin.v_procedures_not_at_hospital_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>performed_procedure</td>
-            	<td>text</td>
+            	<td>clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -79113,7 +94361,7 @@ FROM clin.v_procedures_not_at_hospital_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>unit</td>
+            	<td>reviewer</td>
             	<td>text</td>
                 <td><i>
 				
@@ -79129,7 +94377,7 @@ FROM clin.v_procedures_not_at_hospital_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>organization</td>
+            	<td>comment</td>
             	<td>text</td>
                 <td><i>
 				
@@ -79145,8 +94393,8 @@ FROM clin.v_procedures_not_at_hospital_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>episode</td>
-            	<td>text</td>
+            	<td>pk_review_root</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -79161,8 +94409,8 @@ FROM clin.v_procedures_not_at_hospital_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>health_issue</td>
-            	<td>text</td>
+            	<td>pk_reviewer</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -79173,59 +94421,96 @@ FROM clin.v_procedures_not_at_hospital_journal;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
+        </table>
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>modified_by</td>
-            	<td>text</td>
-                <td><i>
-				
+        <!-- Inherits -->
+		
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>row_version</td>
-            	<td>integer</td>
-                <td><i>
-				
+		
 
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT (
+SELECT pg_class.relnamespace
+           
+  FROM pg_class
+          
+ WHERE (pg_class.oid = rr.tableoid)
+) AS src_schema
+,
+    
+(
+SELECT pg_class.relname
+           
+  FROM pg_class
+          
+ WHERE (pg_class.oid = rr.tableoid)
+) AS src_table
+,
+    rr.fk_reviewed_row AS pk_reviewed_row
+,
+    rr.is_technically_abnormal
+,
+    rr.clinically_relevant
+,
+    
+(
+SELECT staff.short_alias
+           
+  FROM dem.staff
+          
+ WHERE (staff.pk = rr.fk_reviewer)
+) AS reviewer
+,
+    rr.comment
+,
+    rr.pk AS pk_review_root
+,
+    rr.fk_reviewer AS pk_reviewer
+   
+FROM clin.review_root rr;</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-subst-intake4narr-search">v_subst_intake4narr_search</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.v_subst_intake4narr_search Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
+            	<td>pk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -79241,8 +94526,8 @@ FROM clin.v_procedures_not_at_hospital_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -79257,8 +94542,8 @@ FROM clin.v_procedures_not_at_hospital_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_hospital_stay</td>
-            	<td>integer</td>
+            	<td>narrative</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -79273,7 +94558,7 @@ FROM clin.v_procedures_not_at_hospital_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
+            	<td>pk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -79289,7 +94574,7 @@ FROM clin.v_procedures_not_at_hospital_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_org</td>
+            	<td>pk_episode</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -79305,7 +94590,7 @@ FROM clin.v_procedures_not_at_hospital_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_org_unit</td>
+            	<td>pk_health_issue</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -79321,8 +94606,8 @@ FROM clin.v_procedures_not_at_hospital_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_generic_codes</td>
-            	<td>integer[]</td>
+            	<td>src_pk</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -79337,8 +94622,8 @@ FROM clin.v_procedures_not_at_hospital_journal;</pre>
 				<td>
                 
                 </td>
-            	<td>xmin_procedure</td>
-            	<td>xid</td>
+            	<td>src_table</td>
+            	<td>unknown</td>
                 <td><i>
 				
 
@@ -79368,80 +94653,63 @@ FROM clin.v_procedures_not_at_hospital_journal;</pre>
 	<!-- View Definition -->
 	
 	<pre>
-SELECT c_pr.pk AS pk_procedure
-, c_enc.fk_patient AS pk_patient
-, c_pr.soap_cat
-, c_pr.clin_when
-, c_pr.clin_end
-, c_pr.is_ongoing
-, c_pr.narrative AS performed_procedure
-, d_ou.description AS unit
-, d_o.description AS organization
-, c_ep.description AS episode
-, c_hi.description AS health_issue
-, c_pr.modified_when
-, COALESCE
-(
-     (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.db_user = c_pr.modified_by)
-     )
-     , (
-           ('<'::text || 
-                 (c_pr.modified_by)::text
-           ) || '>'::text
-     )
-) AS modified_by
-, c_pr.row_version
-, c_pr.fk_encounter AS pk_encounter
-, c_pr.fk_episode AS pk_episode
-, c_pr.fk_hospital_stay AS pk_hospital_stay
-, c_ep.fk_health_issue AS pk_health_issue
-, d_o.pk AS pk_org
-, d_ou.pk AS pk_org_unit
-, COALESCE
+SELECT c_enc.fk_patient AS pk_patient
+,
+    c_si.soap_cat
+,
+    
 (
      (
-      SELECT array_agg
-           (c_lc2p.fk_generic_code) AS array_agg 
-        FROM clin.lnk_code2procedure c_lc2p 
-       WHERE (c_lc2p.fk_item = c_pr.pk)
-     )
-     , ARRAY[]::integer[]
-) AS pk_generic_codes
-, c_pr.xmin AS xmin_procedure 
-FROM (
-     (
            (
-                 (
-                       (clin.procedure c_pr 
-                          JOIN clin.encounter c_enc 
-                            ON (
-                                   (c_pr.fk_encounter = c_enc.pk)
-                             )
-                       )
-                    JOIN clin.episode c_ep 
-                      ON (
-                             (c_pr.fk_episode = c_ep.pk)
+                 (COALESCE
+                       (c_si.narrative
+                             ,''::text
+                       ) || COALESCE
+                       (
+                             (' / '::text || c_si.comment_on_start)
+                             ,''::text
                        )
+                 ) || COALESCE
+                 (
+                       (' / '::text || c_si.schedule)
+                       ,''::text
                  )
-         LEFT JOIN clin.health_issue c_hi 
-                ON (
-                       (c_ep.fk_health_issue = c_hi.pk)
-                 )
+           ) || COALESCE
+           (
+                 (' / '::text || c_si.aim)
+                 ,''::text
            )
-   LEFT JOIN dem.org_unit d_ou 
+     ) || COALESCE
+     (
+           (' / '::text || c_si.discontinue_reason)
+           ,''::text
+     )
+) AS narrative
+,
+    c_si.fk_encounter AS pk_encounter
+,
+    c_si.fk_episode AS pk_episode
+,
+    c_epi.fk_health_issue AS pk_health_issue
+,
+    c_si.pk AS src_pk
+,
+    'clin.substance_intake' AS src_table
+   
+FROM (
+     (clin.substance_intake c_si
+     
+        JOIN clin.encounter c_enc 
           ON (
-                 (d_ou.pk = c_pr.fk_org_unit)
+                 (c_si.fk_encounter = c_enc.pk)
            )
      )
-LEFT JOIN dem.org d_o 
+     
+  JOIN clin.episode c_epi 
     ON (
-           (d_o.pk = d_ou.fk_org)
+           (c_si.fk_episode = c_epi.pk)
      )
-)
-WHERE (c_pr.fk_hospital_stay IS NULL);</pre>
+);</pre>
 	
 
 	<!-- List off permissions -->
@@ -79455,13 +94723,13 @@ WHERE (c_pr.fk_hospital_stay IS NULL);</pre>
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-procedures-not-at-hospital-journal">v_procedures_not_at_hospital_journal</a>
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-substance-intake-journal">v_substance_intake_journal</a>
 		</h2>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_procedures_not_at_hospital_journal Structure</caption>
+                <caption>clin.v_substance_intake_journal Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -79647,209 +94915,26 @@ WHERE (c_pr.fk_hospital_stay IS NULL);</pre>
             
             <tr class="tr1">
 				<td>
-                
-                </td>
-            	<td>row_version</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT c_enc.fk_patient AS pk_patient
-, c_pr.modified_when
-, c_pr.clin_when
-, COALESCE
-(
-     (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.db_user = c_pr.modified_by)
-     )
-     , (
-           ('<'::text || 
-                 (c_pr.modified_by)::text
-           ) || '>'::text
-     )
-) AS modified_by
-, c_pr.soap_cat
-, (
-     (
-           (
-                 (
-                       (
-                             (
-                                   (
-                                         (
-                                               (
-                                                     (_
-                                                           ('Procedure'::text) || ' "'::text
-                                                     ) || c_pr.narrative
-                                               ) || '"'::text
-                                         ) || 
-                                      ' ('::text) || d_ou.description
-                                   ) || ' @ '::text
-                             ) || d_o.description
-                       ) || COALESCE
-                       (
-                             (
-                                   (
-                                         (
-                                            ', '::text || _
-                                               ('until'::text)
-                                         ) || ' '::text
-                                   ) || to_char
-                                   (c_pr.clin_end
-                                         ,'YYYY Mon DD'::text
-                                   )
-                             )
-                             , CASE WHEN 
-                             (c_pr.is_ongoing IS TRUE) THEN 
-                             (
-                                ', '::text || _
-                                   ('ongoing'::text)
-                             ) ELSE ''::text END
-                       )
-                 ) || 
-         ')'::text
-     ) || COALESCE
-     (
-           (
-                 ('
-'::text || array_to_string
-                       (
-                             (
-                              SELECT array_agg
-                                   (
-                                         (
-                                               (
-                                                     (
-                                                           (
-                                                                 (
-                                                                       (
-                                                                             (
-                                                                                   (r_csr.code || 
-                                                                                      ' ('::text) || r_ds.name_short
-                                                                                   ) || ' - '::text
-                                                                             ) || r_ds.version
-                                                                       ) || ' - '::text
-                                                                 ) || r_ds.lang
-                                                           ) || 
-                                                 '): '::text
-                                               ) || r_csr.term
-                                         )
-                                   ) AS array_agg 
-                                FROM (
-                                         (clin.lnk_code2procedure c_lc2p 
-                                            JOIN ref.coding_system_root r_csr 
-                                              ON (
-                                                     (c_lc2p.fk_generic_code = r_csr.pk_coding_system)
-                                               )
-                                         )
-                                      JOIN ref.data_source r_ds 
-                                        ON (
-                                               (r_ds.pk = r_csr.fk_data_source)
-                                         )
-                                   )
-                               WHERE (c_lc2p.fk_item = c_pr.pk)
-                             )
-                             ,'; '::text
-                       )
-                 ) || ';'::text
-           )
-           ,''::text
-     )
-) AS narrative
-, c_pr.fk_encounter AS pk_encounter
-, c_pr.fk_episode AS pk_episode
-, cep.fk_health_issue AS pk_health_issue
-, c_pr.pk AS src_pk
-,'clin.procedure'::text AS src_table
-, c_pr.row_version 
-FROM (
-     (
-           (
-                 (clin.procedure c_pr 
-                    JOIN clin.encounter c_enc 
-                      ON (
-                             (c_pr.fk_encounter = c_enc.pk)
-                       )
-                 )
-              JOIN clin.episode cep 
-                ON (
-                       (c_pr.fk_episode = cep.pk)
-                 )
-           )
-   LEFT JOIN dem.org_unit d_ou 
-          ON (
-                 (c_pr.fk_org_unit = d_ou.pk)
-           )
-     )
-LEFT JOIN dem.org d_o 
-    ON (
-           (d_ou.fk_org = d_o.pk)
-     )
-)
-WHERE (c_pr.fk_hospital_stay IS NULL);</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-reviewed-items">v_reviewed_items</a>
-		</h2>
-        
-         <p>denormalization of parent table of reviewed items</p>
-        
-
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
 
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_reviewed_items Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
             
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>src_schema</td>
-            	<td>oid</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -79864,8 +94949,8 @@ WHERE (c_pr.fk_hospital_stay IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>src_table</td>
-            	<td>name</td>
+            	<td>issue_laterality</td>
+            	<td>character varying(2)</td>
                 <td><i>
 				
 
@@ -79880,8 +94965,8 @@ WHERE (c_pr.fk_hospital_stay IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_reviewed_row</td>
-            	<td>integer</td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -79896,7 +94981,7 @@ WHERE (c_pr.fk_hospital_stay IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>is_technically_abnormal</td>
+            	<td>issue_clinically_relevant</td>
             	<td>boolean</td>
                 <td><i>
 				
@@ -79912,7 +94997,7 @@ WHERE (c_pr.fk_hospital_stay IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>clinically_relevant</td>
+            	<td>issue_confidential</td>
             	<td>boolean</td>
                 <td><i>
 				
@@ -79928,7 +95013,7 @@ WHERE (c_pr.fk_hospital_stay IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>reviewer</td>
+            	<td>episode</td>
             	<td>text</td>
                 <td><i>
 				
@@ -79944,8 +95029,8 @@ WHERE (c_pr.fk_hospital_stay IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>comment</td>
-            	<td>text</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -79960,8 +95045,8 @@ WHERE (c_pr.fk_hospital_stay IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_review_root</td>
-            	<td>integer</td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -79976,8 +95061,40 @@ WHERE (c_pr.fk_hospital_stay IS NULL);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_reviewer</td>
-            	<td>integer</td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>encounter_type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>encounter_l10n_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -80007,28 +95124,651 @@ WHERE (c_pr.fk_hospital_stay IS NULL);</pre>
 	<!-- View Definition -->
 	
 	<pre>
-SELECT (
-SELECT pg_class.relnamespace 
-  FROM pg_class 
- WHERE (pg_class.oid = rr.tableoid)
-) AS src_schema
-, (
-SELECT pg_class.relname 
-  FROM pg_class 
- WHERE (pg_class.oid = rr.tableoid)
-) AS src_table
-, rr.fk_reviewed_row AS pk_reviewed_row
-, rr.is_technically_abnormal
-, rr.clinically_relevant
-, (
-SELECT staff.short_alias 
-  FROM dem.staff 
- WHERE (staff.pk = rr.fk_reviewer)
-) AS reviewer
-, rr.comment
-, rr.pk AS pk_review_root
-, rr.fk_reviewer AS pk_reviewer 
-FROM clin.review_root rr;</pre>
+SELECT c_enc.fk_patient AS pk_patient
+,
+    c_si.modified_when
+,
+    c_si.clin_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_si.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (c_si.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    c_si.soap_cat
+,
+    
+(
+     (
+           (
+                 (
+                       (
+                             (
+                                   (
+                                         (
+                                               (
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (
+                                                                             (
+                                                                                   (
+                                                                                         (
+                                                                                               (
+                                                                                                     (
+                                                                                                           (
+                                                                                                                 (
+                                                                                                                       (
+        CASE
+            WHEN 
+                                                                                                                             (c_si.is_long_term IS TRUE) THEN 
+                                                                                                                             (_
+                                                                                                                                   ('long-term'::text) || ' '::text
+                                                                                                                             )
+            ELSE ''::text
+        END || _
+                                                                                                                             ('substance intake'::text)
+                                                                                                                       ) || ' '::text
+                                                                                                                 ) ||
+        CASE
+            WHEN 
+                                                                                                                 (c_si.intake_is_approved_of IS TRUE) THEN _
+                                                                                                                 ('(approved of)'::text
+                                                                                                           )
+            WHEN 
+                                                                                                           (c_si.intake_is_approved_of IS FALSE) THEN _
+                                                                                                           ('(not approved of)'::text
+                                                                                                     )
+            ELSE _
+                                                                                                     ('(of unknown approval)'::text
+                                                                                               )
+        END
+                                                                                         ) ||
+        CASE
+            WHEN 
+                                                                                         (c_si.harmful_use_type IS NULL) THEN ''::text
+            WHEN 
+                                                                                         (c_si.harmful_use_type = 0) THEN _
+                                                                                         ('no harmful use'::text)
+            WHEN 
+                                                                                         (c_si.harmful_use_type = 1) THEN _
+                                                                                         ('harmful use'::text)
+            WHEN 
+                                                                                         (c_si.harmful_use_type = 2) THEN _
+                                                                                         ('addiction'::text)
+            WHEN 
+                                                                                         (c_si.harmful_use_type = 3) THEN _
+                                                                                         ('previous addiction'::text)
+            ELSE NULL::text
+        END
+                                                                                   ) || ':
+'::text
+                                                                             ) || ' '::text
+                                                                       ) || r_cs.description
+                                                                 ) || COALESCE
+                                                                 (
+                                                                       (
+                                                                             (' ['::text || r_cs.atc_code) || '] '::text
+                                                                       )
+                                                                       ,' '::text
+                                                                 )
+                                                           ) || 
+                                                           (r_cs.amount)::text
+                                                     ) || r_cs.unit
+                                               ) || ' '::text
+                                         ) || r_bd.preparation
+                                   ) || COALESCE
+                                   (
+                                         (' '::text || c_si.schedule)
+                                         ,''::text
+                                   )
+                             ) || 
+                          ', '::text
+                       ) ||
+        CASE
+            WHEN 
+                       (c_si.comment_on_start = '?'::text) THEN '?'::text
+            WHEN 
+                       (c_si.comment_on_start IS NULL) THEN to_char
+                       (c_si.clin_when
+                             ,'YYYY-MM-DD'::text
+                       )
+            ELSE 
+                       (
+                             (
+                                   (
+                                         ('~'::text || to_char
+                                               (c_si.clin_when
+                                                     ,'YYYY-MM-DD'::text
+                                               )
+                                         ) || 
+                                      ' ('::text) || c_si.comment_on_start
+                                   ) || 
+                           ')'::text
+                       )
+        END
+                 ) || COALESCE
+                 (
+                       (' -> '::text || c_si.duration)
+                       ,''::text
+                 )
+           ) || '
+'::text
+     ) || COALESCE
+     (
+           (
+                 (
+                       (
+                             (' '::text || _
+                                   ('Discontinued'::text)
+                             ) || to_char
+                             (c_si.discontinued
+                                   ,': YYYY-MM-DD'::text
+                             )
+                       ) || COALESCE
+                       (
+                             (
+                                   (
+                                      ' ('::text || c_si.discontinue_reason) || 
+                                 ')'::text
+                             )
+                             ,''::text
+                       )
+                 ) || '
+'::text
+           )
+           ,''::text
+     )
+) || COALESCE
+(
+     (
+           (
+                 ('
+ '::text || _
+                       ('Aim'::text)
+                 ) || ': '::text
+           ) || c_si.aim
+     )
+     ,''::text
+)
+)      || COALESCE
+(     
+(
+     (
+           ('
+ '::text || _
+                 ('Notes'::text)
+           ) || ': '::text
+     ) || c_si.narrative
+)
+,''::text
+)     
+)            || COALESCE
+(           
+(     
+(
+     (
+           (' "'::text || r_bd.description) || '"'::text
+     ) || COALESCE
+     (
+           (
+                 (' ['::text || r_bd.atc_code) || ']'::text
+           )
+           ,''::text
+     )
+) || COALESCE
+(
+     (
+           (
+                 (
+                       (
+                          ' ('::text || r_bd.external_code_type) || ': '::text
+                       ) || r_bd.external_code
+                 ) || 
+         ')'::text
+     )
+     ,''::text
+)
+)     
+,     ''::text
+)           
+)                  AS narrative
+,                 
+    c_si.fk_encounter AS pk_encounter
+,                 
+    c_si.fk_episode AS pk_episode
+,                 
+    
+(                 
+SELECT       episode.fk_health_issue
+           
+FROM         clin.episode
+          
+WHERE        (episode.pk = c_si.fk_episode)
+)                  AS pk_health_issue
+,                 
+    c_si.pk AS src_pk
+,                 
+    'clin.substance_intake'::text AS src_table
+,                 
+    c_si.row_version
+,                 
+    c_hi.description AS health_issue
+,                 
+    c_hi.laterality AS issue_laterality
+,                 
+    c_hi.is_active AS issue_active
+,                 
+    c_hi.clinically_relevant AS issue_clinically_relevant
+,                 
+    c_hi.is_confidential AS issue_confidential
+,                 
+    c_epi.description AS episode
+,                 
+    c_epi.is_open AS episode_open
+,                 
+    c_enc.started AS encounter_started
+,                 
+    c_enc.last_affirmed AS encounter_last_affirmed
+,                 
+    c_ety.description AS encounter_type
+,                 
+    _
+(                 c_ety.description) AS encounter_l10n_type
+   
+FROM               (
+(           
+(     
+(
+     (
+           (
+                 (clin.substance_intake c_si
+     
+                    JOIN ref.lnk_substance2brand r_ls2b 
+                      ON (
+                             (c_si.fk_drug_component = r_ls2b.pk)
+                       )
+                 )
+     
+              JOIN ref.branded_drug r_bd 
+                ON (
+                       (r_bd.pk = r_ls2b.fk_brand)
+                 )
+           )
+     
+        JOIN ref.consumable_substance r_cs 
+          ON (
+                 (r_cs.pk = r_ls2b.fk_substance)
+           )
+     )
+     
+  JOIN clin.encounter c_enc 
+    ON (
+           (c_si.fk_encounter = c_enc.pk)
+     )
+)
+     
+JOIN clin.encounter_type c_ety 
+ON (
+     (c_enc.fk_type = c_ety.pk)
+)
+)     
+     
+JOIN   clin.episode c_epi 
+ON     (
+(c_si.fk_episode = c_epi.pk)
+)     
+)           
+     
+LEFT JOIN    clin.health_issue c_hi 
+ON           (
+(     c_epi.fk_health_issue = c_hi.pk)
+)           
+)                 
+  
+WHERE              (c_si.fk_drug_component IS NOT NULL)
+UNION ALL         
+ 
+SELECT             c_enc.fk_patient AS pk_patient
+,                 
+    c_si.modified_when
+,                 
+    c_si.clin_when
+,                 
+    COALESCE
+(                 
+(           
+SELECT staff.short_alias
+           
+FROM   dem.staff
+          
+WHERE  (staff.db_user = c_si.modified_by)
+)           
+,            (
+(     '<'::text || 
+(c_si.modified_by)::text
+)      || '>'::text
+)           
+)                  AS modified_by
+,                 
+    c_si.soap_cat
+,                 
+    
+(                 
+(           
+(     
+(
+     (
+           (
+                 (
+                       (
+                             (
+                                   (
+                                         (
+                                               (
+                                                     (
+                                                           (
+                                                                 (
+                                                                       (
+                                                                             (
+                                                                                   (
+                                                                                         (
+        CASE
+            WHEN 
+                                                                                               (c_si.is_long_term IS TRUE) THEN 
+                                                                                               (_
+                                                                                                     ('long-term'::text) || ' '::text
+                                                                                               )
+            ELSE ''::text
+        END ||
+        CASE
+            WHEN 
+                                                                                               (c_si.harmful_use_type IS NULL) THEN 
+                                                                                               (_
+                                                                                                     ('Substance intake'::text) || ' '::text
+                                                                                               )
+            ELSE 
+                                                                                               (_
+                                                                                                     ('Substance abuse'::text) || ' '::text
+                                                                                               )
+        END
+                                                                                         ) ||
+        CASE
+            WHEN 
+                                                                                         (c_si.intake_is_approved_of IS TRUE) THEN _
+                                                                                         ('(approved of)'::text
+                                                                                   )
+            WHEN 
+                                                                                   (c_si.intake_is_approved_of IS FALSE) THEN _
+                                                                                   ('(not approved of)'::text
+                                                                             )
+            ELSE _
+                                                                             ('(of unknown approval)'::text
+                                                                       )
+        END
+                                                                 ) ||
+        CASE
+            WHEN 
+                                                                 (c_si.harmful_use_type IS NULL) THEN ''::text
+            WHEN 
+                                                                 (c_si.harmful_use_type = 0) THEN 
+                                                                 (
+                                                                       (
+                                                                             (
+                                                                                   (
+                                                                                      ', '::text || _
+                                                                                         ('no harmful use'::text)
+                                                                                   ) || 
+                                                                                ' ('::text) || to_char
+                                                                                   (c_enc.started
+                                                                                         ,'YYYY-MM-DD'::text
+                                                                                   )
+                                                                             ) || 
+                                                                     ')'::text
+                                                                 )
+            WHEN 
+                                                                 (c_si.harmful_use_type = 1) THEN 
+                                                                 (
+                                                                       (
+                                                                             (
+                                                                                   (
+                                                                                      ', '::text || _
+                                                                                         ('harmful use'::text)
+                                                                                   ) || 
+                                                                                ' ('::text) || to_char
+                                                                                   (c_enc.started
+                                                                                         ,'YYYY-MM-DD'::text
+                                                                                   )
+                                                                             ) || 
+                                                                     ')'::text
+                                                                 )
+            WHEN 
+                                                                 (c_si.harmful_use_type = 2) THEN 
+                                                                 (
+                                                                       (
+                                                                             (
+                                                                                   (
+                                                                                      ', '::text || _
+                                                                                         ('addiction'::text)
+                                                                                   ) || 
+                                                                                ' ('::text) || to_char
+                                                                                   (c_enc.started
+                                                                                         ,'YYYY-MM-DD'::text
+                                                                                   )
+                                                                             ) || 
+                                                                     ')'::text
+                                                                 )
+            WHEN 
+                                                                 (c_si.harmful_use_type = 3) THEN 
+                                                                 (
+                                                                       (
+                                                                             (
+                                                                                   (
+                                                                                      ', '::text || _
+                                                                                         ('previous addiction'::text)
+                                                                                   ) || 
+                                                                                ' ('::text) || to_char
+                                                                                   (c_enc.started
+                                                                                         ,'YYYY-MM-DD'::text
+                                                                                   )
+                                                                             ) || 
+                                                                     ')'::text
+                                                                 )
+            ELSE NULL::text
+        END
+                                                           ) || ':
+'::text
+                                                     ) || ' '::text
+                                               ) || r_cs.description
+                                         ) || COALESCE
+                                         (
+                                               (
+                                                     (' ['::text || r_cs.atc_code) || '] '::text
+                                               )
+                                               ,' '::text
+                                         )
+                                   ) || r_cs.amount
+                             ) || r_cs.unit
+                       ) || ' '::text
+                 ) || c_si.preparation
+           ) || COALESCE
+           (
+                 (' '::text || c_si.schedule)
+                 ,''::text
+           )
+     ) || 
+  ', '::text
+) ||
+        CASE
+            WHEN 
+(c_si.comment_on_start = '?'::text) THEN '?'::text
+            WHEN 
+(c_si.comment_on_start IS NULL) THEN to_char
+(c_si.clin_when
+     ,'YYYY-MM-DD'::text
+)
+            ELSE 
+(
+     (
+           (
+                 ('~'::text || to_char
+                       (c_si.clin_when
+                             ,'YYYY-MM-DD'::text
+                       )
+                 ) || 
+              ' ('::text) || c_si.comment_on_start
+           ) || 
+   ')'::text
+)
+        END
+)      || COALESCE
+(     
+(' -> '::text || c_si.duration)
+,''::text
+)     
+)            || '
+'::text
+)                  || COALESCE
+(                 
+(           
+(     
+(
+     (' '::text || _
+           ('Discontinued'::text)
+     ) || to_char
+     (c_si.discontinued
+           ,': YYYY-MM-DD'::text
+     )
+) || COALESCE
+(
+     (
+           (
+              ' ('::text || c_si.discontinue_reason) || 
+         ')'::text
+     )
+     ,''::text
+)
+)      || '
+'::text
+)           
+,           ''::text
+)                 
+)                        || COALESCE
+(                       
+(                 
+(           
+(     '
+ '::text || _
+('Aim'::text)
+)      || ': '::text
+)            || c_si.aim
+)                 
+,                 ''::text
+)                       
+)                              || COALESCE
+(                             
+(                       
+(                 
+(           '
+ '::text || _
+(     'Notes'::text)
+)            || ': '::text
+)                  || c_si.narrative
+)                       
+,                       ''::text
+)                             
+)                                    AS narrative
+,                                   
+    c_si.fk_encounter AS pk_encounter
+,                                   
+    c_si.fk_episode AS pk_episode
+,                                   
+    
+(                                   
+SELECT                         episode.fk_health_issue
+           
+FROM                           clin.episode
+          
+WHERE                          (episode.pk = c_si.fk_episode)
+)                                    AS pk_health_issue
+,                                   
+    c_si.pk AS src_pk
+,                                   
+    'clin.substance_intake'::text AS src_table
+,                                   
+    c_si.row_version
+,                                   
+    c_hi.description AS health_issue
+,                                   
+    c_hi.laterality AS issue_laterality
+,                                   
+    c_hi.is_active AS issue_active
+,                                   
+    c_hi.clinically_relevant AS issue_clinically_relevant
+,                                   
+    c_hi.is_confidential AS issue_confidential
+,                                   
+    c_epi.description AS episode
+,                                   
+    c_epi.is_open AS episode_open
+,                                   
+    c_enc.started AS encounter_started
+,                                   
+    c_enc.last_affirmed AS encounter_last_affirmed
+,                                   
+    c_ety.description AS encounter_type
+,                                   
+    _
+(                                   c_ety.description) AS encounter_l10n_type
+   
+FROM                                 (
+(                             
+(                       
+(                 
+(           clin.substance_intake c_si
+     
+JOIN   ref.consumable_substance r_cs 
+ON     (
+(r_cs.pk = c_si.fk_substance)
+)     
+)           
+     
+JOIN         clin.encounter c_enc 
+ON           (
+(     c_si.fk_encounter = c_enc.pk)
+)           
+)                 
+     
+JOIN               clin.encounter_type c_ety 
+ON                 (
+(           c_enc.fk_type = c_ety.pk)
+)                 
+)                       
+     
+JOIN                     clin.episode c_epi 
+ON                       (
+(                 c_si.fk_episode = c_epi.pk)
+)                       
+)                             
+     
+LEFT JOIN                      clin.health_issue c_hi 
+ON                             (
+(                       c_epi.fk_health_issue = c_hi.pk)
+)                             
+)                                   
+  
+WHERE                                (c_si.fk_drug_component IS NULL);</pre>
 	
 
 	<!-- List off permissions -->
@@ -80268,6 +96008,54 @@ FROM clin.review_root rr;</pre>
 				<td>
                 
                 </td>
+            	<td>comment_on_start</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>start_is_unknown</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>start_is_approximate</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
             	<td>intake_is_approved_of</td>
             	<td>boolean</td>
                 <td><i>
@@ -80280,10 +96068,42 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>harmful_use_type</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
             <tr class="tr0">
 				<td>
                 
                 </td>
+            	<td>last_checked_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
             	<td>schedule</td>
             	<td>text</td>
                 <td><i>
@@ -80296,7 +96116,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -80312,7 +96132,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -80328,7 +96148,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -80344,7 +96164,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -80360,7 +96180,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -80376,7 +96196,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -80392,7 +96212,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -80408,7 +96228,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -80424,7 +96244,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -80440,7 +96260,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -80456,7 +96276,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -80472,7 +96292,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -80488,7 +96308,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -80504,7 +96324,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -80520,7 +96340,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -80536,7 +96356,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -80552,7 +96372,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -80568,7 +96388,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -80584,7 +96404,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -80600,7 +96420,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -80616,7 +96436,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -80632,7 +96452,7 @@ FROM clin.review_root rr;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -80668,80 +96488,177 @@ FROM clin.review_root rr;</pre>
 	
 	<pre>
 SELECT v_brand_intakes.pk_substance_intake
-, v_brand_intakes.pk_patient
-, v_brand_intakes.soap_cat
-, v_brand_intakes.brand
-, v_brand_intakes.preparation
-, v_brand_intakes.substance
-, v_brand_intakes.amount
-, v_brand_intakes.unit
-, v_brand_intakes.atc_substance
-, v_brand_intakes.atc_brand
-, v_brand_intakes.external_code_brand
-, v_brand_intakes.external_code_type_brand
-, v_brand_intakes.started
-, v_brand_intakes.intake_is_approved_of
-, v_brand_intakes.schedule
-, v_brand_intakes.duration
-, v_brand_intakes.discontinued
-, v_brand_intakes.discontinue_reason
-, v_brand_intakes.is_long_term
-, v_brand_intakes.aim
-, v_brand_intakes.episode
-, v_brand_intakes.health_issue
-, v_brand_intakes.notes
-, v_brand_intakes.fake_brand
-, v_brand_intakes.is_currently_active
-, v_brand_intakes.seems_inactive
-, v_brand_intakes.pk_brand
-, v_brand_intakes.pk_data_source
-, v_brand_intakes.pk_substance
-, v_brand_intakes.pk_drug_component
-, v_brand_intakes.pk_encounter
-, v_brand_intakes.pk_episode
-, v_brand_intakes.pk_health_issue
-, v_brand_intakes.modified_when
-, v_brand_intakes.modified_by
-, v_brand_intakes.row_version
-, v_brand_intakes.xmin_substance_intake 
-FROM clin.v_brand_intakes 
-UNION ALLSELECT v_nonbrand_intakes.pk_substance_intake
-, v_nonbrand_intakes.pk_patient
-, v_nonbrand_intakes.soap_cat
-, v_nonbrand_intakes.brand
-, v_nonbrand_intakes.preparation
-, v_nonbrand_intakes.substance
-, v_nonbrand_intakes.amount
-, v_nonbrand_intakes.unit
-, v_nonbrand_intakes.atc_substance
-, v_nonbrand_intakes.atc_brand
-, v_nonbrand_intakes.external_code_brand
-, v_nonbrand_intakes.external_code_type_brand
-, v_nonbrand_intakes.started
-, v_nonbrand_intakes.intake_is_approved_of
-, v_nonbrand_intakes.schedule
-, v_nonbrand_intakes.duration
-, v_nonbrand_intakes.discontinued
-, v_nonbrand_intakes.discontinue_reason
-, v_nonbrand_intakes.is_long_term
-, v_nonbrand_intakes.aim
-, v_nonbrand_intakes.episode
-, v_nonbrand_intakes.health_issue
-, v_nonbrand_intakes.notes
-, v_nonbrand_intakes.fake_brand
-, v_nonbrand_intakes.is_currently_active
-, v_nonbrand_intakes.seems_inactive
-, v_nonbrand_intakes.pk_brand
-, v_nonbrand_intakes.pk_data_source
-, v_nonbrand_intakes.pk_substance
-, v_nonbrand_intakes.pk_drug_component
-, v_nonbrand_intakes.pk_encounter
-, v_nonbrand_intakes.pk_episode
-, v_nonbrand_intakes.pk_health_issue
-, v_nonbrand_intakes.modified_when
-, v_nonbrand_intakes.modified_by
-, v_nonbrand_intakes.row_version
-, v_nonbrand_intakes.xmin_substance_intake 
+,
+    v_brand_intakes.pk_patient
+,
+    v_brand_intakes.soap_cat
+,
+    v_brand_intakes.brand
+,
+    v_brand_intakes.preparation
+,
+    v_brand_intakes.substance
+,
+    v_brand_intakes.amount
+,
+    v_brand_intakes.unit
+,
+    v_brand_intakes.atc_substance
+,
+    v_brand_intakes.atc_brand
+,
+    v_brand_intakes.external_code_brand
+,
+    v_brand_intakes.external_code_type_brand
+,
+    v_brand_intakes.started
+,
+    v_brand_intakes.comment_on_start
+,
+    v_brand_intakes.start_is_unknown
+,
+    v_brand_intakes.start_is_approximate
+,
+    v_brand_intakes.intake_is_approved_of
+,
+    v_brand_intakes.harmful_use_type
+,
+    v_brand_intakes.last_checked_when
+,
+    v_brand_intakes.schedule
+,
+    v_brand_intakes.duration
+,
+    v_brand_intakes.discontinued
+,
+    v_brand_intakes.discontinue_reason
+,
+    v_brand_intakes.is_long_term
+,
+    v_brand_intakes.aim
+,
+    v_brand_intakes.episode
+,
+    v_brand_intakes.health_issue
+,
+    v_brand_intakes.notes
+,
+    v_brand_intakes.fake_brand
+,
+    v_brand_intakes.is_currently_active
+,
+    v_brand_intakes.seems_inactive
+,
+    v_brand_intakes.pk_brand
+,
+    v_brand_intakes.pk_data_source
+,
+    v_brand_intakes.pk_substance
+,
+    v_brand_intakes.pk_drug_component
+,
+    v_brand_intakes.pk_encounter
+,
+    v_brand_intakes.pk_episode
+,
+    v_brand_intakes.pk_health_issue
+,
+    v_brand_intakes.modified_when
+,
+    v_brand_intakes.modified_by
+,
+    v_brand_intakes.row_version
+,
+    v_brand_intakes.xmin_substance_intake
+   
+FROM clin.v_brand_intakes
+
+UNION ALL
+ 
+SELECT v_nonbrand_intakes.pk_substance_intake
+,
+    v_nonbrand_intakes.pk_patient
+,
+    v_nonbrand_intakes.soap_cat
+,
+    v_nonbrand_intakes.brand
+,
+    v_nonbrand_intakes.preparation
+,
+    v_nonbrand_intakes.substance
+,
+    v_nonbrand_intakes.amount
+,
+    v_nonbrand_intakes.unit
+,
+    v_nonbrand_intakes.atc_substance
+,
+    v_nonbrand_intakes.atc_brand
+,
+    v_nonbrand_intakes.external_code_brand
+,
+    v_nonbrand_intakes.external_code_type_brand
+,
+    v_nonbrand_intakes.started
+,
+    v_nonbrand_intakes.comment_on_start
+,
+    v_nonbrand_intakes.start_is_unknown
+,
+    v_nonbrand_intakes.start_is_approximate
+,
+    v_nonbrand_intakes.intake_is_approved_of
+,
+    v_nonbrand_intakes.harmful_use_type
+,
+    v_nonbrand_intakes.last_checked_when
+,
+    v_nonbrand_intakes.schedule
+,
+    v_nonbrand_intakes.duration
+,
+    v_nonbrand_intakes.discontinued
+,
+    v_nonbrand_intakes.discontinue_reason
+,
+    v_nonbrand_intakes.is_long_term
+,
+    v_nonbrand_intakes.aim
+,
+    v_nonbrand_intakes.episode
+,
+    v_nonbrand_intakes.health_issue
+,
+    v_nonbrand_intakes.notes
+,
+    v_nonbrand_intakes.fake_brand
+,
+    v_nonbrand_intakes.is_currently_active
+,
+    v_nonbrand_intakes.seems_inactive
+,
+    v_nonbrand_intakes.pk_brand
+,
+    v_nonbrand_intakes.pk_data_source
+,
+    v_nonbrand_intakes.pk_substance
+,
+    v_nonbrand_intakes.pk_drug_component
+,
+    v_nonbrand_intakes.pk_encounter
+,
+    v_nonbrand_intakes.pk_episode
+,
+    v_nonbrand_intakes.pk_health_issue
+,
+    v_nonbrand_intakes.modified_when
+,
+    v_nonbrand_intakes.modified_by
+,
+    v_nonbrand_intakes.row_version
+,
+    v_nonbrand_intakes.xmin_substance_intake
+   
 FROM clin.v_nonbrand_intakes;</pre>
 	
 
@@ -80854,7 +96771,7 @@ FROM clin.v_nonbrand_intakes;</pre>
 				<td>
                 
                 </td>
-            	<td>url</td>
+            	<td>recommendation</td>
             	<td>text</td>
                 <td><i>
 				
@@ -80870,6 +96787,22 @@ FROM clin.v_nonbrand_intakes;</pre>
 				<td>
                 
                 </td>
+            	<td>url</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
             	<td>is_active</td>
             	<td>boolean</td>
                 <td><i>
@@ -80882,7 +96815,7 @@ FROM clin.v_nonbrand_intakes;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -80898,7 +96831,7 @@ FROM clin.v_nonbrand_intakes;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -80914,7 +96847,7 @@ FROM clin.v_nonbrand_intakes;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -80930,7 +96863,7 @@ FROM clin.v_nonbrand_intakes;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -80946,7 +96879,7 @@ FROM clin.v_nonbrand_intakes;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -80962,7 +96895,7 @@ FROM clin.v_nonbrand_intakes;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -80978,7 +96911,7 @@ FROM clin.v_nonbrand_intakes;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -80994,7 +96927,7 @@ FROM clin.v_nonbrand_intakes;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -81010,7 +96943,7 @@ FROM clin.v_nonbrand_intakes;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -81046,26 +96979,47 @@ FROM clin.v_nonbrand_intakes;</pre>
 	
 	<pre>
 SELECT (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
+SELECT encounter.fk_patient
+           
+  FROM clin.encounter
+          
  WHERE (encounter.pk = c_sh.fk_encounter)
 ) AS pk_identity
-, c_sh.pk AS pk_suppressed_hint
-, c_sh.fk_hint AS pk_hint
-, r_vah.title
-, r_vah.hint
-, r_vah.url
-, r_vah.is_active
-, r_vah.source
-, r_vah.query
-, r_vah.lang
-, c_sh.rationale
-, c_sh.md5_sum AS md5_suppressed
-, r_vah.md5_sum AS md5_hint
-, c_sh.suppressed_by
-, c_sh.suppressed_when
-, c_sh.fk_encounter AS pk_encounter 
-FROM (clin.suppressed_hint c_sh 
+,
+    c_sh.pk AS pk_suppressed_hint
+,
+    c_sh.fk_hint AS pk_hint
+,
+    r_vah.title
+,
+    r_vah.hint
+,
+    r_vah.recommendation
+,
+    r_vah.url
+,
+    r_vah.is_active
+,
+    r_vah.source
+,
+    r_vah.query
+,
+    r_vah.lang
+,
+    c_sh.rationale
+,
+    c_sh.md5_sum AS md5_suppressed
+,
+    r_vah.md5_sum AS md5_hint
+,
+    c_sh.suppressed_by
+,
+    c_sh.suppressed_when
+,
+    c_sh.fk_encounter AS pk_encounter
+   
+FROM (clin.suppressed_hint c_sh
+     
   JOIN ref.v_auto_hints r_vah 
     ON (
            (c_sh.fk_hint = r_vah.pk_auto_hint)
@@ -81102,7 +97056,7 @@ FROM (clin.suppressed_hint c_sh
 				<td>
                 
                 </td>
-            	<td>pk_identity</td>
+            	<td>pk_patient</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -81290,6 +97244,182 @@ FROM (clin.suppressed_hint c_sh
 				</td>
 			 </tr>
             
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>health_issue</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>issue_laterality</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>episode</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>encounter_type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>encounter_l10n_type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
         </table>
 
         <!-- Inherits -->
@@ -81309,16 +97439,18 @@ FROM (clin.suppressed_hint c_sh
 	<!-- View Definition -->
 	
 	<pre>
-SELECT (
-SELECT encounter.fk_patient 
-  FROM clin.encounter 
- WHERE (encounter.pk = c_sh.fk_encounter)
-) AS pk_identity
-, c_sh.modified_when
-, c_sh.suppressed_when AS clin_when
-, c_sh.modified_by
-,'p'::text AS soap_cat
-, (
+SELECT c_enc.fk_patient AS pk_patient
+,
+    c_sh.modified_when
+,
+    c_sh.suppressed_when AS clin_when
+,
+    c_sh.modified_by
+,
+    'p'::text AS soap_cat
+,
+    
+(
      (
            (
                  (
@@ -81330,24 +97462,39 @@ SELECT encounter.fk_patient
                                                      (
                                                            (
                                                                  (
-                                                                       (CASE WHEN 
-                                                                             (r_vah.is_active IS TRUE) THEN _
-                                                                             ('Active hint'::text) ELSE _
-                                                                             ('Inactive hint'::text) END || ' #'::text
-                                                                       ) || c_sh.fk_hint
-                                                                 ) || ' '::text
-                                                           ) || _
-                                                           ('suppressed by'::text)
-                                                     ) || ' '::text
-                                               ) || 
-                                               (c_sh.suppressed_by)::text
-                                         ) || '
+                                                                       (
+                                                                             (
+        CASE
+            WHEN 
+                                                                                   (r_vah.is_active IS TRUE) THEN _
+                                                                                   ('Active hint'::text)
+            ELSE _
+                                                                                   ('Inactive hint'::text)
+        END || ' #'::text
+                                                                             ) || c_sh.fk_hint
+                                                                       ) || ' '::text
+                                                                 ) || _
+                                                                 ('suppressed by'::text)
+                                                           ) || ' '::text
+                                                     ) || 
+                                                     (c_sh.suppressed_by)::text
+                                               ) || '
+'::text
+                                         ) || COALESCE
+                                         (
+                                               (
+                                                     (_
+                                                           ('Title: '::text) || r_vah.title
+                                                     ) || '
 '::text
+                                               )
+                                               ,''::text
+                                         )
                                    ) || COALESCE
                                    (
                                          (
                                                (_
-                                                     ('Title: '::text) || r_vah.title
+                                                     ('URL: '::text) || r_vah.url
                                                ) || '
 '::text
                                          )
@@ -81357,7 +97504,7 @@ SELECT encounter.fk_patient
                              (
                                    (
                                          (_
-                                               ('URL: '::text) || r_vah.url
+                                               ('Source: '::text) || r_vah.source
                                          ) || '
 '::text
                                    )
@@ -81367,43 +97514,92 @@ SELECT encounter.fk_patient
                        (
                              (
                                    (_
-                                         ('Source: '::text) || r_vah.source
+                                         ('Rationale: '::text) || c_sh.rationale
                                    ) || '
 '::text
                              )
                              ,''::text
                        )
-                 ) || COALESCE
-                 (
-                       (
-                             (_
-                                   ('Rationale: '::text) || c_sh.rationale
-                             ) || '
+                 ) ||
+        CASE
+            WHEN 
+                 (c_sh.md5_sum <> r_vah.md5_sum) THEN 
+                 (_
+                       ('Hint definition has been modified since suppression. Rationale for suppression may no longer apply.'::text) || '
 '::text
-                       )
-                       ,''::text
                  )
-           ) || CASE WHEN 
-           (c_sh.md5_sum <> r_vah.md5_sum) THEN 
-           (_
-                 ('Hint definition has been modified since suppression. Rationale for suppression may no longer apply.'::text) || '
+            ELSE ''::text
+        END
+           ) || COALESCE
+           (
+                 (
+                       (_
+                             ('Hint: '::text) || r_vah.hint
+                       ) || '
 '::text
-           ) ELSE ''::text END
+                 )
+                 ,''::text
+           )
      ) || COALESCE
      (
            (_
-                 ('Hint: '::text) || r_vah.hint
+                 ('Recommendation: '::text) || r_vah.recommendation
            )
            ,''::text
      )
 ) AS narrative
-, c_sh.fk_encounter
-, NULL::integer AS pk_episode
-, NULL::integer AS pk_health_issue
-, c_sh.pk AS src_pk
-,'clin.suppressed_hint'::text AS src_table
-, c_sh.row_version 
-FROM (clin.suppressed_hint c_sh 
+,
+    c_sh.fk_encounter
+,
+    NULL::integer AS pk_episode
+,
+    NULL::integer AS pk_health_issue
+,
+    c_sh.pk AS src_pk
+,
+    'clin.suppressed_hint'::text AS src_table
+,
+    c_sh.row_version
+,
+    NULL::text AS health_issue
+,
+    NULL::text AS issue_laterality
+,
+    NULL::boolean AS issue_active
+,
+    NULL::boolean AS issue_clinically_relevant
+,
+    NULL::boolean AS issue_confidential
+,
+    NULL::text AS episode
+,
+    NULL::boolean AS episode_open
+,
+    c_enc.started AS encounter_started
+,
+    c_enc.last_affirmed AS encounter_last_affirmed
+,
+    c_ety.description AS encounter_type
+,
+    _
+(c_ety.description) AS encounter_l10n_type
+   
+FROM (
+     (
+           (clin.suppressed_hint c_sh
+     
+              JOIN clin.encounter c_enc 
+                ON (
+                       (c_sh.fk_encounter = c_enc.pk)
+                 )
+           )
+     
+        JOIN clin.encounter_type c_ety 
+          ON (
+                 (c_enc.fk_type = c_ety.pk)
+           )
+     )
+     
   JOIN ref.v_auto_hints r_vah 
     ON (
            (c_sh.fk_hint = r_vah.pk_auto_hint)
@@ -81664,25 +97860,40 @@ FROM (clin.suppressed_hint c_sh
 	
 	<pre>
 SELECT c_to.pk AS pk_test_org
-, d_o.description AS organization
-, d_ou.description AS unit
-, c_to.comment
-, c_to.contact AS test_org_contact
-, c_to.fk_adm_contact AS pk_adm_contact
-, c_to.fk_med_contact AS pk_med_contact
-, d_o.pk AS pk_org
-, d_o.fk_category AS category_org
-, d_ou.pk AS pk_org_unit
-, d_ou.fk_category AS category_unit
-, d_ou.fk_address AS pk_address_unit
-, c_to.xmin AS xmin_test_org 
+,
+    d_o.description AS organization
+,
+    d_ou.description AS unit
+,
+    c_to.comment
+,
+    c_to.contact AS test_org_contact
+,
+    c_to.fk_adm_contact AS pk_adm_contact
+,
+    c_to.fk_med_contact AS pk_med_contact
+,
+    d_o.pk AS pk_org
+,
+    d_o.fk_category AS category_org
+,
+    d_ou.pk AS pk_org_unit
+,
+    d_ou.fk_category AS category_unit
+,
+    d_ou.fk_address AS pk_address_unit
+,
+    c_to.xmin AS xmin_test_org
+   
 FROM (
-     (clin.test_org c_to 
+     (clin.test_org c_to
+     
    LEFT JOIN dem.org_unit d_ou 
           ON (
                  (c_to.fk_org_unit = d_ou.pk)
            )
      )
+     
 LEFT JOIN dem.org d_o 
     ON (
            (d_ou.fk_org = d_o.pk)
@@ -81879,23 +98090,34 @@ LEFT JOIN dem.org d_o
 	
 	<pre>
 SELECT c_tp.pk AS pk_test_panel
-, c_tp.description
-, c_tp.comment
-, c_tp.fk_test_types AS pk_test_types
-, c_tp.modified_when
-, c_tp.modified_by
-, COALESCE
+,
+    c_tp.description
+,
+    c_tp.comment
+,
+    c_tp.fk_test_types AS pk_test_types
+,
+    c_tp.modified_when
+,
+    c_tp.modified_by
+,
+    COALESCE
 (
      (
       SELECT array_agg
-           (c_lc2tp.fk_generic_code) AS array_agg 
-        FROM clin.lnk_code2tst_pnl c_lc2tp 
+           (c_lc2tp.fk_generic_code) AS array_agg
+           
+        FROM clin.lnk_code2tst_pnl c_lc2tp
+          
        WHERE (c_lc2tp.fk_item = c_tp.pk)
      )
      , ARRAY[]::integer[]
 ) AS pk_generic_codes
-, c_tp.row_version
-, c_tp.xmin AS xmin_test_panel 
+,
+    c_tp.row_version
+,
+    c_tp.xmin AS xmin_test_panel
+   
 FROM clin.test_panel c_tp;</pre>
 	
 
@@ -82827,8 +99049,555 @@ FROM clin.test_panel c_tp;</pre>
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_item</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_test_type</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_intended_reviewer</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_request</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>xmin_test_result</td>
+            	<td>xid</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_test_org</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_meta_test_type</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_last_reviewer</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT cenc.fk_patient AS pk_patient
+,
+    tr.pk AS pk_test_result
+,
+    tr.clin_when
+,
+    c_vtt.unified_abbrev
+,
+    c_vtt.unified_name
+,
+    c_vtt.unified_loinc
+,
+        CASE
+            WHEN 
+(COALESCE
+     (btrim
+           (tr.val_alpha)
+           ,''::text
+     ) = ''::text
+) THEN 
+(tr.val_num)::text
+            ELSE
+            CASE
+                WHEN 
+(tr.val_num IS NULL) THEN tr.val_alpha
+                ELSE 
+(
+     (
+           (
+                 (tr.val_num)::text || 
+              ' ('::text) || tr.val_alpha
+           ) || 
+   ')'::text
+)
+            END
+        END AS unified_val
+,
+    COALESCE
+(tr.val_target_min
+     , tr.val_normal_min
+) AS unified_target_min
+,
+    COALESCE
+(tr.val_target_max
+     , tr.val_normal_max
+) AS unified_target_max
+,
+    COALESCE
+(tr.val_target_range
+     , tr.val_normal_range
+) AS unified_target_range
+,
+    tr.status
+,
+    tr.soap_cat
+,
+    tr.narrative AS comment
+,
+    tr.val_num
+,
+    tr.val_alpha
+,
+    tr.val_unit
+,
+    c_vtt.reference_unit
+,
+    tr.val_normal_min
+,
+    tr.val_normal_max
+,
+    tr.val_normal_range
+,
+    tr.val_target_min
+,
+    tr.val_target_max
+,
+    tr.val_target_range
+,
+    tr.abnormality_indicator
+,
+    tr.norm_ref_group
+,
+    tr.note_test_org
+,
+    tr.material
+,
+    tr.material_detail
+,
+    c_vtt.abbrev AS abbrev_tt
+,
+    c_vtt.name AS name_tt
+,
+    c_vtt.loinc AS loinc_tt
+,
+    c_vtt.comment_type AS comment_tt
+,
+    c_vtt.name_org AS name_test_org
+,
+    c_vtt.contact_org AS contact_test_org
+,
+    c_vtt.comment_org AS comment_test_org
+,
+    c_vtt.is_fake_meta_type
+,
+    c_vtt.abbrev_meta
+,
+    c_vtt.name_meta
+,
+    c_vtt.loinc_meta
+,
+    c_vtt.comment_meta
+,
+    epi.description AS episode
+,
+    chi.description AS health_issue
+,
+    
+(COALESCE
+     (rtr.fk_reviewed_row
+           , 0
+     )
+)::boolean AS reviewed
+,
+    rtr.is_technically_abnormal
+,
+    rtr.clinically_relevant AS is_clinically_relevant
+,
+    rtr.comment AS review_comment
+,
+    
+(
+SELECT staff.short_alias
+           
+  FROM dem.staff
+          
+ WHERE (staff.pk = rtr.fk_reviewer)
+) AS last_reviewer
+,
+    rtr.modified_when AS last_reviewed
+,
+    COALESCE
+(
+     (rtr.fk_reviewer = 
+           (
+            SELECT staff.pk
+           
+              FROM dem.staff
+          
+             WHERE (staff.db_user = "current_user"
+                       ()
+                 )
+           )
+     )
+     , false
+) AS review_by_you
+,
+    COALESCE
+(
+     (tr.fk_intended_reviewer = rtr.fk_reviewer)
+     , false
+) AS review_by_responsible_reviewer
+,
+    
+(
+SELECT staff.short_alias
+           
+  FROM dem.staff
+          
+ WHERE (staff.pk = tr.fk_intended_reviewer)
+) AS responsible_reviewer
+,
+    COALESCE
+(
+     (tr.fk_intended_reviewer = 
+           (
+            SELECT staff.pk
+           
+              FROM dem.staff
+          
+             WHERE (staff.db_user = "current_user"
+                       ()
+                 )
+           )
+     )
+     , false
+) AS you_are_responsible
+,
+        CASE
+            WHEN 
+(
+     (
+      SELECT 1
+               
+        FROM dem.staff
+              
+       WHERE (staff.db_user = tr.modified_by)
+     ) IS NULL
+) THEN 
+(
+     ('<'::text || 
+           (tr.modified_by)::text
+     ) || '>'::text
+)
+            ELSE 
+(
+SELECT staff.short_alias
+               
+  FROM dem.staff
+              
+ WHERE (staff.db_user = tr.modified_by)
+)
+        END AS modified_by
+,
+    tr.val_grouping
+,
+    tr.source_data
+,
+    tr.modified_when
+,
+    tr.row_version
+,
+    tr.pk_item
+,
+    tr.fk_encounter AS pk_encounter
+,
+    tr.fk_episode AS pk_episode
+,
+    tr.fk_type AS pk_test_type
+,
+    tr.fk_intended_reviewer AS pk_intended_reviewer
+,
+    tr.fk_request AS pk_request
+,
+    tr.xmin AS xmin_test_result
+,
+    c_vtt.pk_test_org
+,
+    c_vtt.pk_meta_test_type
+,
+    epi.fk_health_issue AS pk_health_issue
+,
+    rtr.fk_reviewer AS pk_last_reviewer
+   
+FROM (
+     (
+           (
+                 (clin.test_result tr
+     
+               LEFT JOIN clin.encounter cenc 
+                      ON (
+                             (tr.fk_encounter = cenc.pk)
+                       )
+                 )
+     
+         LEFT JOIN clin.episode epi 
+                ON (
+                       (tr.fk_episode = epi.pk)
+                 )
+           )
+     
+   LEFT JOIN clin.reviewed_test_results rtr 
+          ON (
+                 (tr.pk = rtr.fk_reviewed_row)
+           )
+     )
+     
+LEFT JOIN clin.health_issue chi 
+    ON (
+           (epi.fk_health_issue = chi.pk)
+     )
+)
+,
+    clin.v_test_types c_vtt
+  
+WHERE (tr.fk_type = c_vtt.pk_test_type);</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-test-results-journal">v_test_results_journal</a>
+		</h2>
+        
+         <p>formatting of v_test_results for inclusion in v_emr_journal</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.v_test_results_journal Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -82843,8 +99612,8 @@ FROM clin.test_panel c_tp;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_item</td>
-            	<td>integer</td>
+            	<td>modified_by</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -82859,8 +99628,8 @@ FROM clin.test_panel c_tp;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>soap_cat</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -82875,8 +99644,8 @@ FROM clin.test_panel c_tp;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>narrative</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -82891,7 +99660,7 @@ FROM clin.test_panel c_tp;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_test_type</td>
+            	<td>pk_encounter</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -82907,23 +99676,7 @@ FROM clin.test_panel c_tp;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_intended_reviewer</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_request</td>
+            	<td>pk_episode</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -82935,27 +99688,11 @@ FROM clin.test_panel c_tp;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>xmin_test_result</td>
-            	<td>xid</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_test_org</td>
+            	<td>pk_health_issue</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -82971,7 +99708,7 @@ FROM clin.test_panel c_tp;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_meta_test_type</td>
+            	<td>src_pk</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -82987,8 +99724,8 @@ FROM clin.test_panel c_tp;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
-            	<td>integer</td>
+            	<td>src_table</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -83003,7 +99740,7 @@ FROM clin.test_panel c_tp;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_last_reviewer</td>
+            	<td>row_version</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -83015,236 +99752,12 @@ FROM clin.test_panel c_tp;</pre>
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT cenc.fk_patient AS pk_patient
-, tr.pk AS pk_test_result
-, tr.clin_when
-, c_vtt.unified_abbrev
-, c_vtt.unified_name
-, c_vtt.unified_loinc
-, CASE WHEN 
-(COALESCE
-     (btrim
-           (tr.val_alpha)
-           ,''::text
-     ) = ''::text
-) THEN 
-(tr.val_num)::text ELSE CASE WHEN 
-(tr.val_num IS NULL) THEN tr.val_alpha ELSE 
-(
-     (
-           (
-                 (tr.val_num)::text || 
-              ' ('::text) || tr.val_alpha
-           ) || 
-   ')'::text
-) END END AS unified_val
-, COALESCE
-(tr.val_target_min
-     , tr.val_normal_min
-) AS unified_target_min
-, COALESCE
-(tr.val_target_max
-     , tr.val_normal_max
-) AS unified_target_max
-, COALESCE
-(tr.val_target_range
-     , tr.val_normal_range
-) AS unified_target_range
-, tr.status
-, tr.soap_cat
-, tr.narrative AS comment
-, tr.val_num
-, tr.val_alpha
-, tr.val_unit
-, c_vtt.reference_unit
-, tr.val_normal_min
-, tr.val_normal_max
-, tr.val_normal_range
-, tr.val_target_min
-, tr.val_target_max
-, tr.val_target_range
-, tr.abnormality_indicator
-, tr.norm_ref_group
-, tr.note_test_org
-, tr.material
-, tr.material_detail
-, c_vtt.abbrev AS abbrev_tt
-, c_vtt.name AS name_tt
-, c_vtt.loinc AS loinc_tt
-, c_vtt.comment_type AS comment_tt
-, c_vtt.name_org AS name_test_org
-, c_vtt.contact_org AS contact_test_org
-, c_vtt.comment_org AS comment_test_org
-, c_vtt.is_fake_meta_type
-, c_vtt.abbrev_meta
-, c_vtt.name_meta
-, c_vtt.loinc_meta
-, c_vtt.comment_meta
-, epi.description AS episode
-, chi.description AS health_issue
-, (COALESCE
-     (rtr.fk_reviewed_row
-           , 0
-     )
-)::boolean AS reviewed
-, rtr.is_technically_abnormal
-, rtr.clinically_relevant AS is_clinically_relevant
-, rtr.comment AS review_comment
-, (
-SELECT staff.short_alias 
-  FROM dem.staff 
- WHERE (staff.pk = rtr.fk_reviewer)
-) AS last_reviewer
-, rtr.modified_when AS last_reviewed
-, COALESCE
-(
-     (rtr.fk_reviewer = 
-           (
-            SELECT staff.pk 
-              FROM dem.staff 
-             WHERE (staff.db_user = "current_user"
-                       ()
-                 )
-           )
-     )
-     , false
-) AS review_by_you
-, COALESCE
-(
-     (tr.fk_intended_reviewer = rtr.fk_reviewer)
-     , false
-) AS review_by_responsible_reviewer
-, (
-SELECT staff.short_alias 
-  FROM dem.staff 
- WHERE (staff.pk = tr.fk_intended_reviewer)
-) AS responsible_reviewer
-, COALESCE
-(
-     (tr.fk_intended_reviewer = 
-           (
-            SELECT staff.pk 
-              FROM dem.staff 
-             WHERE (staff.db_user = "current_user"
-                       ()
-                 )
-           )
-     )
-     , false
-) AS you_are_responsible
-, CASE WHEN 
-(
-     (
-      SELECT 1 
-        FROM dem.staff 
-       WHERE (staff.db_user = tr.modified_by)
-     ) IS NULL
-) THEN 
-(
-     ('<'::text || 
-           (tr.modified_by)::text
-     ) || '>'::text
-) ELSE 
-(
-SELECT staff.short_alias 
-  FROM dem.staff 
- WHERE (staff.db_user = tr.modified_by)
-) END AS modified_by
-, tr.val_grouping
-, tr.source_data
-, tr.modified_when
-, tr.row_version
-, tr.pk_item
-, tr.fk_encounter AS pk_encounter
-, tr.fk_episode AS pk_episode
-, tr.fk_type AS pk_test_type
-, tr.fk_intended_reviewer AS pk_intended_reviewer
-, tr.fk_request AS pk_request
-, tr.xmin AS xmin_test_result
-, c_vtt.pk_test_org
-, c_vtt.pk_meta_test_type
-, epi.fk_health_issue AS pk_health_issue
-, rtr.fk_reviewer AS pk_last_reviewer 
-FROM (
-     (
-           (
-                 (clin.test_result tr 
-               LEFT JOIN clin.encounter cenc 
-                      ON (
-                             (tr.fk_encounter = cenc.pk)
-                       )
-                 )
-         LEFT JOIN clin.episode epi 
-                ON (
-                       (tr.fk_episode = epi.pk)
-                 )
-           )
-   LEFT JOIN clin.reviewed_test_results rtr 
-          ON (
-                 (tr.pk = rtr.fk_reviewed_row)
-           )
-     )
-LEFT JOIN clin.health_issue chi 
-    ON (
-           (epi.fk_health_issue = chi.pk)
-     )
-)
-, clin.v_test_types c_vtt 
-WHERE (tr.fk_type = c_vtt.pk_test_type);</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-test-results-journal">v_test_results_journal</a>
-		</h2>
-        
-         <p>formatting of v_test_results for inclusion in v_emr_journal</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>clin.v_test_results_journal Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_patient</td>
-            	<td>integer</td>
+            	<td>health_issue</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -83259,8 +99772,8 @@ WHERE (tr.fk_type = c_vtt.pk_test_type);</pre>
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>issue_laterality</td>
+            	<td>character varying(2)</td>
                 <td><i>
 				
 
@@ -83275,8 +99788,8 @@ WHERE (tr.fk_type = c_vtt.pk_test_type);</pre>
 				<td>
                 
                 </td>
-            	<td>clin_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -83291,8 +99804,8 @@ WHERE (tr.fk_type = c_vtt.pk_test_type);</pre>
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>text</td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -83307,8 +99820,8 @@ WHERE (tr.fk_type = c_vtt.pk_test_type);</pre>
 				<td>
                 
                 </td>
-            	<td>soap_cat</td>
-            	<td>text</td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -83323,7 +99836,7 @@ WHERE (tr.fk_type = c_vtt.pk_test_type);</pre>
 				<td>
                 
                 </td>
-            	<td>narrative</td>
+            	<td>episode</td>
             	<td>text</td>
                 <td><i>
 				
@@ -83339,8 +99852,8 @@ WHERE (tr.fk_type = c_vtt.pk_test_type);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_encounter</td>
-            	<td>integer</td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -83355,8 +99868,8 @@ WHERE (tr.fk_type = c_vtt.pk_test_type);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_episode</td>
-            	<td>integer</td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -83371,8 +99884,8 @@ WHERE (tr.fk_type = c_vtt.pk_test_type);</pre>
 				<td>
                 
                 </td>
-            	<td>pk_health_issue</td>
-            	<td>integer</td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -83387,8 +99900,8 @@ WHERE (tr.fk_type = c_vtt.pk_test_type);</pre>
 				<td>
                 
                 </td>
-            	<td>src_pk</td>
-            	<td>integer</td>
+            	<td>encounter_type</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -83403,7 +99916,7 @@ WHERE (tr.fk_type = c_vtt.pk_test_type);</pre>
 				<td>
                 
                 </td>
-            	<td>src_table</td>
+            	<td>encounter_l10n_type</td>
             	<td>text</td>
                 <td><i>
 				
@@ -83415,22 +99928,6 @@ WHERE (tr.fk_type = c_vtt.pk_test_type);</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>row_version</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
         </table>
 
         <!-- Inherits -->
@@ -83451,11 +99948,16 @@ WHERE (tr.fk_type = c_vtt.pk_test_type);</pre>
 	
 	<pre>
 SELECT c_vtr.pk_patient
-, c_vtr.modified_when
-, c_vtr.clin_when
-, c_vtr.modified_by
-, c_vtr.soap_cat
-, COALESCE
+,
+    c_vtr.modified_when
+,
+    c_vtr.clin_when
+,
+    c_vtr.modified_by
+,
+    c_vtr.soap_cat
+,
+    COALESCE
 (
      (
            (
@@ -83596,15 +100098,23 @@ SELECT c_vtr.pk_patient
                                                                        ,'YYYY-MM-DD HH24:MI'::text
                                                                  )
                                                            ) || ': '::text
-                                                     ) || CASE WHEN c_vtr.is_technically_abnormal THEN 
+                                                     ) ||
+        CASE
+            WHEN c_vtr.is_technically_abnormal THEN 
                                                      (_
                                                            ('abnormal'::text) || 
                                                         ', '::text
-                                                     ) ELSE ''::text END
-                                               ) || CASE WHEN c_vtr.is_clinically_relevant THEN 
+                                                     )
+            ELSE ''::text
+        END
+                                               ) ||
+        CASE
+            WHEN c_vtr.is_clinically_relevant THEN 
                                                (_
                                                      ('relevant'::text) || ' '::text
-                                               ) ELSE ''::text END
+                                               )
+            ELSE ''::text
+        END
                                          ) || COALESCE
                                          (
                                                (
@@ -83638,13 +100148,70 @@ SELECT c_vtr.pk_patient
      )
      ,'faulty clin.v_test_results_journal definition'::text
 ) AS narrative
-, c_vtr.pk_encounter
-, c_vtr.pk_episode
-, c_vtr.pk_health_issue
-, c_vtr.pk_test_result AS src_pk
-,'clin.test_result'::text AS src_table
-, c_vtr.row_version 
-FROM clin.v_test_results c_vtr;</pre>
+,
+    c_vtr.pk_encounter
+,
+    c_vtr.pk_episode
+,
+    c_vtr.pk_health_issue
+,
+    c_vtr.pk_test_result AS src_pk
+,
+    'clin.test_result'::text AS src_table
+,
+    c_vtr.row_version
+,
+    c_vtr.health_issue
+,
+    c_hi.laterality AS issue_laterality
+,
+    c_hi.is_active AS issue_active
+,
+    c_hi.clinically_relevant AS issue_clinically_relevant
+,
+    c_hi.is_confidential AS issue_confidential
+,
+    c_vtr.episode
+,
+    c_epi.is_open AS episode_open
+,
+    c_enc.started AS encounter_started
+,
+    c_enc.last_affirmed AS encounter_last_affirmed
+,
+    c_ety.description AS encounter_type
+,
+    _
+(c_ety.description) AS encounter_l10n_type
+   
+FROM (
+     (
+           (
+                 (clin.v_test_results c_vtr
+     
+                    JOIN clin.encounter c_enc 
+                      ON (
+                             (c_vtr.pk_encounter = c_enc.pk)
+                       )
+                 )
+     
+              JOIN clin.encounter_type c_ety 
+                ON (
+                       (c_enc.fk_type = c_ety.pk)
+                 )
+           )
+     
+        JOIN clin.episode c_epi 
+          ON (
+                 (c_vtr.pk_episode = c_epi.pk)
+           )
+     )
+     
+LEFT JOIN clin.health_issue c_hi 
+    ON (
+           (c_epi.fk_health_issue = c_hi.pk)
+     )
+);</pre>
 	
 
 	<!-- List off permissions -->
@@ -84078,58 +100645,89 @@ FROM clin.v_test_results c_vtr;</pre>
 	
 	<pre>
 SELECT c_tt.pk AS pk_test_type
-, c_tt.abbrev
-, c_tt.name
-, c_tt.loinc
-, c_tt.reference_unit
-, c_tt.comment AS comment_type
-, d_ou.description AS name_org
-, c_to.comment AS comment_org
-, c_to.contact AS contact_org
-, COALESCE
+,
+    c_tt.abbrev
+,
+    c_tt.name
+,
+    c_tt.loinc
+,
+    c_tt.reference_unit
+,
+    c_tt.comment AS comment_type
+,
+    d_ou.description AS name_org
+,
+    c_to.comment AS comment_org
+,
+    c_to.contact AS contact_org
+,
+    COALESCE
 (c_mtt.abbrev
      , c_tt.abbrev
 ) AS unified_abbrev
-, COALESCE
+,
+    COALESCE
 (c_mtt.name
      , c_tt.name
 ) AS unified_name
-, COALESCE
+,
+    COALESCE
 (c_mtt.loinc
      , c_tt.loinc
 ) AS unified_loinc
-, (c_tt.fk_meta_test_type IS NULL) AS is_fake_meta_type
-, c_mtt.abbrev AS abbrev_meta
-, c_mtt.name AS name_meta
-, c_mtt.loinc AS loinc_meta
-, c_mtt.comment AS comment_meta
-, (
+,
+    
+(c_tt.fk_meta_test_type IS NULL) AS is_fake_meta_type
+,
+    c_mtt.abbrev AS abbrev_meta
+,
+    c_mtt.name AS name_meta
+,
+    c_mtt.loinc AS loinc_meta
+,
+    c_mtt.comment AS comment_meta
+,
+    
+(
 SELECT array_agg
-     (c_tp.pk) AS array_agg 
-  FROM clin.test_panel c_tp 
+     (c_tp.pk) AS array_agg
+           
+  FROM clin.test_panel c_tp
+          
  WHERE (c_tt.pk = ANY 
            (c_tp.fk_test_types)
      )
 ) AS pk_test_panels
-, c_tt.fk_test_org AS pk_test_org
-, c_tt.fk_meta_test_type AS pk_meta_test_type
-, c_to.fk_org_unit AS pk_org_unit
-, c_to.fk_adm_contact AS pk_adm_contact_org
-, c_to.fk_med_contact AS pk_med_contact_org
-, c_tt.xmin AS xmin_test_type 
+,
+    c_tt.fk_test_org AS pk_test_org
+,
+    c_tt.fk_meta_test_type AS pk_meta_test_type
+,
+    c_to.fk_org_unit AS pk_org_unit
+,
+    c_to.fk_adm_contact AS pk_adm_contact_org
+,
+    c_to.fk_med_contact AS pk_med_contact_org
+,
+    c_tt.xmin AS xmin_test_type
+   
 FROM (
      (
-           (clin.test_type c_tt 
+           (clin.test_type c_tt
+     
          LEFT JOIN clin.test_org c_to 
                 ON (
                        (c_to.pk = c_tt.fk_test_org)
                  )
            )
+     
    LEFT JOIN dem.org_unit d_ou 
           ON (
                  (c_to.fk_org_unit = d_ou.pk)
            )
      )
+     
 LEFT JOIN clin.meta_test_type c_mtt 
     ON (
            (c_tt.fk_meta_test_type = c_mtt.pk)
@@ -84310,16 +100908,27 @@ LEFT JOIN clin.meta_test_type c_mtt
 	
 	<pre>
 SELECT cvs.name AS vaccination_schedule
-, cvc.is_active
-, cvc.fk_recommended_by AS pk_recommended_by
-, cvc.comment AS comment_course
-, cvs.comment AS comment_schedule
-, cvc.pk AS pk_vaccination_course
-, cvc.fk_indication AS pk_indication
-, cvs.pk AS pk_vaccination_schedule 
+,
+    cvc.is_active
+,
+    cvc.fk_recommended_by AS pk_recommended_by
+,
+    cvc.comment AS comment_course
+,
+    cvs.comment AS comment_schedule
+,
+    cvc.pk AS pk_vaccination_course
+,
+    cvc.fk_indication AS pk_indication
+,
+    cvs.pk AS pk_vaccination_schedule
+   
 FROM clin.vaccination_course cvc
-, clin.vaccination_schedule cvs
-, clin.lnk_vaccination_course2schedule clvc2s 
+,
+    clin.vaccination_schedule cvs
+,
+    clin.lnk_vaccination_course2schedule clvc2s
+  
 WHERE (
      (clvc2s.fk_course = cvc.pk)
    AND (clvc2s.fk_schedule = cvs.pk)
@@ -84596,36 +101205,661 @@ WHERE (
 	<!-- View Definition -->
 	
 	<pre>
-SELECT vcourse.pk AS pk_course
-, vind.description AS indication
-, _
-(vind.description) AS l10n_indication
-, COALESCE
-(vcourse.comment
-     ,''::text
-) AS course_comment
-, vcourse.is_active
-, vdef.id AS pk_vaccination_definition
-, vdef.is_booster
-, vdef.seq_no AS vacc_seq_no
-, vdef.min_age_due AS age_due_min
-, vdef.max_age_due AS age_due_max
-, vdef.min_interval
-, COALESCE
-(vdef.comment
-     ,''::text
-) AS vacc_comment
-, vind.id AS pk_indication
-, vcourse.fk_recommended_by AS pk_recommended_by 
-FROM clin.vaccination_course vcourse
-, clin.vacc_indication vind
-, clin.vaccination_definition vdef 
-WHERE (
-     (vcourse.pk = vdef.fk_course)
-   AND (vcourse.fk_indication = vind.id)
-)
-ORDER BY vind.description
-, vdef.seq_no;</pre>
+SELECT vcourse.pk AS pk_course
+,
+    vind.description AS indication
+,
+    _
+(vind.description) AS l10n_indication
+,
+    COALESCE
+(vcourse.comment
+     ,''::text
+) AS course_comment
+,
+    vcourse.is_active
+,
+    vdef.id AS pk_vaccination_definition
+,
+    vdef.is_booster
+,
+    vdef.seq_no AS vacc_seq_no
+,
+    vdef.min_age_due AS age_due_min
+,
+    vdef.max_age_due AS age_due_max
+,
+    vdef.min_interval
+,
+    COALESCE
+(vdef.comment
+     ,''::text
+) AS vacc_comment
+,
+    vind.id AS pk_indication
+,
+    vcourse.fk_recommended_by AS pk_recommended_by
+   
+FROM clin.vaccination_course vcourse
+,
+    clin.vacc_indication vind
+,
+    clin.vaccination_definition vdef
+  
+WHERE (
+     (vcourse.pk = vdef.fk_course)
+   AND (vcourse.fk_indication = vind.id)
+)
+  
+ORDER BY vind.description
+, vdef.seq_no;</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#clin.schema">Schema clin</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.view.v-vaccinations-journal">v_vaccinations_journal</a>
+		</h2>
+        
+         <p>Vaccination data denormalized for the EMR journal.</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>clin.v_vaccinations_journal Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_patient</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>clin_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>soap_cat</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>narrative</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_encounter</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_episode</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_health_issue</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>src_pk</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>src_table</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>health_issue</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>issue_laterality</td>
+            	<td>character varying(2)</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>issue_active</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>issue_clinically_relevant</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>issue_confidential</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>episode</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>episode_open</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>encounter_started</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>encounter_last_affirmed</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>encounter_type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>encounter_l10n_type</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT c_enc.fk_patient AS pk_patient
+,
+    c_vacc.modified_when
+,
+    c_vacc.clin_when
+,
+    COALESCE
+(
+     (
+      SELECT staff.short_alias
+           
+        FROM dem.staff
+          
+       WHERE (staff.db_user = c_vacc.modified_by)
+     )
+     , (
+           ('<'::text || 
+                 (c_vacc.modified_by)::text
+           ) || '>'::text
+     )
+) AS modified_by
+,
+    c_vacc.soap_cat
+,
+    
+(
+     (
+           (
+                 (
+                       (
+                             (
+                                   (
+                                         (
+                                               (
+                                                     (_
+                                                           ('Vaccination'::text) || ': '::text
+                                                     ) || r_bd.description
+                                               ) || ' '::text
+                                         ) || '['::text
+                                   ) || c_vacc.batch_no
+                             ) || ']'::text
+                       ) || COALESCE
+                       (
+                             (
+                                   (
+                                      ' ('::text || c_vacc.site) || 
+                                 ')'::text
+                             )
+                             ,''::text
+                       )
+                 ) || COALESCE
+                 (
+                       (
+                             (
+                                   ('
+'::text || _
+                                         ('Reaction'::text)
+                                   ) || ': '::text
+                             ) || c_vacc.reaction
+                       )
+                       ,''::text
+                 )
+           ) || COALESCE
+           (
+                 (
+                       (
+                             ('
+'::text || _
+                                   ('Comment'::text)
+                             ) || ': '::text
+                       ) || c_vacc.narrative
+                 )
+                 ,''::text
+           )
+     ) || COALESCE
+     (
+           (
+                 (
+                       ('
+'::text || _
+                             ('Indications'::text)
+                       ) || ': '::text
+                 ) || array_to_string
+                 (
+                       (
+                        SELECT array_agg
+                             (_
+                                   (cvi.description)
+                             ) AS array_agg
+           
+                          FROM (clin.lnk_vaccine2inds c_lv2i
+             
+                                JOIN clin.vacc_indication cvi 
+                                  ON (
+                                         (c_lv2i.fk_indication = cvi.id)
+                                   )
+                             )
+          
+                         WHERE (c_lv2i.fk_vaccine = c_vacc.fk_vaccine)
+                       )
+                       ,' / '::text
+                 )
+           )
+           ,''::text
+     )
+) AS narrative
+,
+    c_vacc.fk_encounter AS pk_encounter
+,
+    c_vacc.fk_episode AS pk_episode
+,
+    
+(
+SELECT episode.fk_health_issue
+           
+  FROM clin.episode
+          
+ WHERE (episode.pk = c_vacc.fk_episode)
+) AS pk_health_issue
+,
+    c_vacc.pk AS src_pk
+,
+    'clin.vaccination'::text AS src_table
+,
+    c_vacc.row_version
+,
+    c_hi.description AS health_issue
+,
+    c_hi.laterality AS issue_laterality
+,
+    c_hi.is_active AS issue_active
+,
+    c_hi.clinically_relevant AS issue_clinically_relevant
+,
+    c_hi.is_confidential AS issue_confidential
+,
+    c_epi.description AS episode
+,
+    c_epi.is_open AS episode_open
+,
+    c_enc.started AS encounter_started
+,
+    c_enc.last_affirmed AS encounter_last_affirmed
+,
+    c_ety.description AS encounter_type
+,
+    _
+(c_ety.description) AS encounter_l10n_type
+   
+FROM (
+     (
+           (
+                 (
+                       (
+                             (clin.vaccination c_vacc
+     
+                                JOIN clin.encounter c_enc 
+                                  ON (
+                                         (c_enc.pk = c_vacc.fk_encounter)
+                                   )
+                             )
+     
+                          JOIN clin.encounter_type c_ety 
+                            ON (
+                                   (c_enc.fk_type = c_ety.pk)
+                             )
+                       )
+     
+                    JOIN clin.episode c_epi 
+                      ON (
+                             (c_vacc.fk_episode = c_epi.pk)
+                       )
+                 )
+     
+         LEFT JOIN clin.health_issue c_hi 
+                ON (
+                       (c_epi.fk_health_issue = c_hi.pk)
+                 )
+           )
+     
+        JOIN clin.vaccine 
+          ON (
+                 (vaccine.pk = c_vacc.fk_vaccine)
+           )
+     )
+     
+  JOIN ref.branded_drug r_bd 
+    ON (
+           (vaccine.fk_brand = r_bd.pk)
+     )
+);</pre>
 	
 
 	<!-- List off permissions -->
@@ -84995,64 +102229,98 @@ ORDER BY vind.description
 	
 	<pre>
 SELECT cv.pk AS pk_vaccine
-, rbd.description AS vaccine
-, rbd.preparation
-, rbd.atc_code
-, rbd.is_fake AS is_fake_vaccine
-, cvr.abbreviation AS route_abbreviation
-, cvr.description AS route_description
-, cv.is_live
-, cv.min_age
-, cv.max_age
-, cv.comment
-, (
+,
+    rbd.description AS vaccine
+,
+    rbd.preparation
+,
+    rbd.atc_code
+,
+    rbd.is_fake AS is_fake_vaccine
+,
+    cvr.abbreviation AS route_abbreviation
+,
+    cvr.description AS route_description
+,
+    cv.is_live
+,
+    cv.min_age
+,
+    cv.max_age
+,
+    cv.comment
+,
+    
+(
 SELECT array_agg
-     (cvi.description) AS array_agg 
-  FROM (clin.lnk_vaccine2inds clvi 
+     (cvi.description) AS array_agg
+           
+  FROM (clin.lnk_vaccine2inds clvi
+             
         JOIN clin.vacc_indication cvi 
           ON (
                  (clvi.fk_indication = cvi.id)
            )
      )
+          
  WHERE (clvi.fk_vaccine = cv.pk)
 ) AS indications
-, (
+,
+    
+(
 SELECT array_agg
      (_
            (cvi.description)
-     ) AS array_agg 
-  FROM (clin.lnk_vaccine2inds clvi 
+     ) AS array_agg
+           
+  FROM (clin.lnk_vaccine2inds clvi
+             
         JOIN clin.vacc_indication cvi 
           ON (
                  (clvi.fk_indication = cvi.id)
            )
      )
+          
  WHERE (clvi.fk_vaccine = cv.pk)
 ) AS l10n_indications
-, rbd.external_code
-, rbd.external_code_type
-, (
+,
+    rbd.external_code
+,
+    rbd.external_code_type
+,
+    
+(
 SELECT array_agg
-     (clvi.fk_indication) AS array_agg 
-  FROM (clin.lnk_vaccine2inds clvi 
+     (clvi.fk_indication) AS array_agg
+           
+  FROM (clin.lnk_vaccine2inds clvi
+             
         JOIN clin.vacc_indication cvi 
           ON (
                  (clvi.fk_indication = cvi.id)
            )
      )
+          
  WHERE (clvi.fk_vaccine = cv.pk)
 ) AS pk_indications
-, cv.id_route AS pk_route
-, cv.fk_brand AS pk_brand
-, rbd.fk_data_source AS pk_data_source
-, cv.xmin AS xmin_vaccine 
+,
+    cv.id_route AS pk_route
+,
+    cv.fk_brand AS pk_brand
+,
+    rbd.fk_data_source AS pk_data_source
+,
+    cv.xmin AS xmin_vaccine
+   
 FROM (
-     (clin.vaccine cv 
+     (clin.vaccine cv
+     
         JOIN ref.branded_drug rbd 
           ON (
                  (cv.fk_brand = rbd.pk)
            )
      )
+     
 LEFT JOIN clin.vacc_route cvr 
     ON (
            (cv.id_route = cvr.id)
@@ -85249,8 +102517,8 @@ LEFT JOIN clin.vacc_route cvr
 				<td>
                 
                 </td>
-            	<td>registered</td>
-            	<td>timestamp with time zone</td>
+            	<td>comment_identity</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -85265,8 +102533,8 @@ LEFT JOIN clin.vacc_route cvr
 				<td>
                 
                 </td>
-            	<td>waiting_time</td>
-            	<td>interval</td>
+            	<td>registered</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -85281,8 +102549,8 @@ LEFT JOIN clin.vacc_route cvr
 				<td>
                 
                 </td>
-            	<td>waiting_time_formatted</td>
-            	<td>text</td>
+            	<td>waiting_time</td>
+            	<td>interval</td>
                 <td><i>
 				
 
@@ -85297,7 +102565,7 @@ LEFT JOIN clin.vacc_route cvr
 				<td>
                 
                 </td>
-            	<td>comment</td>
+            	<td>waiting_time_formatted</td>
             	<td>text</td>
                 <td><i>
 				
@@ -85313,8 +102581,8 @@ LEFT JOIN clin.vacc_route cvr
 				<td>
                 
                 </td>
-            	<td>pk_identity</td>
-            	<td>integer</td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -85329,7 +102597,7 @@ LEFT JOIN clin.vacc_route cvr
 				<td>
                 
                 </td>
-            	<td>pk_name</td>
+            	<td>pk_identity</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -85345,8 +102613,8 @@ LEFT JOIN clin.vacc_route cvr
 				<td>
                 
                 </td>
-            	<td>pupic</td>
-            	<td>character(24)</td>
+            	<td>pk_name</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -85392,50 +102660,73 @@ LEFT JOIN clin.vacc_route cvr
 	<!-- View Definition -->
 	
 	<pre>
-SELECT wl.list_position
-, wl.area AS waiting_zone
-, wl.urgency
-, i.title
-, n.firstnames
-, n.lastnames
-, n.preferred AS preferred_name
-, i.dob
-, i.gender
-, _
-(i.gender) AS l10n_gender
-, wl.registered
-, (
+SELECT c_wl.list_position
+,
+    c_wl.area AS waiting_zone
+,
+    c_wl.urgency
+,
+    d_i.title
+,
+    d_n.firstnames
+,
+    d_n.lastnames
+,
+    d_n.preferred AS preferred_name
+,
+    d_i.dob
+,
+    d_i.gender
+,
+    _
+(d_i.gender) AS l10n_gender
+,
+    d_i.comment AS comment_identity
+,
+    c_wl.registered
+,
+    
+(
 SELECT (now
-           () - wl.registered
+           () - c_wl.registered
      )
 ) AS waiting_time
-, (
+,
+    
+(
 SELECT to_char
      (age
            (now
                  ()
-                 , wl.registered
+                 , c_wl.registered
            )
            ,'DDD HH24:MI'::text
      ) AS to_char
 ) AS waiting_time_formatted
-, wl.comment
-, i.pk AS pk_identity
-, n.id AS pk_name
-, i.pupic
-, wl.pk AS pk_waiting_list 
-FROM clin.waiting_list wl
-, dem.identity i
-, dem.names n 
+,
+    c_wl.comment
+,
+    d_i.pk AS pk_identity
+,
+    d_n.id AS pk_name
+,
+    c_wl.pk AS pk_waiting_list
+   
+FROM clin.waiting_list c_wl
+,
+    dem.identity d_i
+,
+    dem.names d_n
+  
 WHERE (
      (
            (
-                 (wl.fk_patient = i.pk)
-               AND (wl.fk_patient = n.id_identity)
+                 (c_wl.fk_patient = d_i.pk)
+               AND (c_wl.fk_patient = d_n.id_identity)
            )
-         AND (i.deceased IS NULL)
+         AND (d_i.deceased IS NULL)
      )
-   AND (n.active IS TRUE)
+   AND (d_n.active IS TRUE)
 );</pre>
 	
 
@@ -85517,11 +102808,19 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -85640,11 +102939,16 @@ WHERE (
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>vacc_indication_sane_combi_atcs</td>
                 <td>CHECK (((atcs_combi_indication IS NULL) OR (array_upper(atcs_combi_indication, 1) > 0)))</td>
             </tr>
 			
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>vacc_indication_sane_single_atcs</td>
                 <td>CHECK (((atcs_single_indication IS NULL) OR (array_upper(atcs_single_indication, 1) > 0)))</td>
             </tr>
@@ -85753,11 +103057,19 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -85855,6 +103167,21 @@ WHERE (
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.vacc_route Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
@@ -85950,11 +103277,19 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -86221,21 +103556,26 @@ WHERE (
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>clin_root_item_sane_soap_cat</td>
                 <td>CHECK (((soap_cat IS NULL) OR (lower(soap_cat) = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))</td>
             </tr>
 			
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>vaccination_sane_narrative</td>
                 <td>CHECK ((gm.is_null_or_non_empty_string(narrative) IS TRUE))</td>
             </tr>
 			
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>vaccination_sane_reaction</td>
                 <td>CHECK ((gm.is_null_or_non_empty_string(reaction) IS TRUE))</td>
             </tr>
 			
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>vaccination_sane_site</td>
                 <td>CHECK ((gm.is_null_or_non_empty_string(site) IS TRUE))</td>
             </tr>
@@ -86248,10 +103588,16 @@ WHERE (
 
     <!-- Indexes -->
     
+       idx_clin_vaccination_clin_when clin_when
+    
        idx_clin_vaccination_fk_encounter fk_encounter
     
        idx_clin_vaccination_fk_episode fk_episode
     
+       idx_clin_vaccination_fk_provider fk_provider
+    
+       idx_clin_vaccination_fk_vaccine fk_vaccine
+    
 
 	<!-- View Definition -->
 	
@@ -86340,11 +103686,19 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -86469,6 +103823,21 @@ WHERE (
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.vaccination_course Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
@@ -86576,11 +103945,19 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -86654,6 +104031,21 @@ WHERE (
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.vaccination_course_constraint Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
@@ -86749,11 +104141,19 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -86957,21 +104357,26 @@ WHERE (
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>numbered_shot_xor_booster</td>
                 <td>CHECK ((((is_booster IS TRUE) AND (seq_no IS NULL)) OR ((is_booster IS FALSE) AND (seq_no > 0))))</td>
             </tr>
 			
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>sensible_min_interval</td>
                 <td>CHECK (((((min_interval IS NULL) AND (seq_no = 1)) OR (((min_interval IS NOT NULL) AND (min_interval > '00:00:00'::interval)) AND (is_booster IS TRUE))) OR (((min_interval IS NOT NULL) AND (min_interval > '00:00:00'::interval)) AND (seq_no > 1))))</td>
             </tr>
 			
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>vaccination_definition_check</td>
                 <td>CHECK ((((max_age_due >= min_age_due) AND (max_age_due <= '150 years'::interval)) OR (max_age_due = '01:32:35'::interval)))</td>
             </tr>
 			
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>vaccination_definition_min_age_due_check</td>
                 <td>CHECK (((min_age_due >= '00:00:01'::interval) AND (min_age_due <= '150 years'::interval)))</td>
             </tr>
@@ -87071,11 +104476,19 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -87165,6 +104578,21 @@ WHERE (
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.vaccination_schedule Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
@@ -87260,11 +104688,19 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -87444,11 +104880,16 @@ WHERE (
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>vaccine_sane_max_age</td>
                 <td>CHECK (((max_age IS NULL) OR (max_age < '150 years'::interval)))</td>
             </tr>
 			
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>vaccine_sane_min_age</td>
                 <td>CHECK (((min_age IS NULL) OR (((max_age IS NULL) AND (min_age < '150 years'::interval)) OR ((max_age IS NOT NULL) AND (min_age <= max_age)))))</td>
             </tr>
@@ -87558,11 +104999,19 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -87661,6 +105110,21 @@ WHERE (
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>clin.vaccine_batches Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
@@ -87749,11 +105213,19 @@ WHERE (
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -87929,11 +105401,16 @@ WHERE (
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>non_empty_area</td>
                 <td>CHECK ((btrim(area) <> ''::text))</td>
             </tr>
 			
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>waiting_list_list_position_check</td>
                 <td>CHECK ((list_position > 0))</td>
             </tr>
@@ -87963,6 +105440,50 @@ WHERE (
 	
 		<hr>
 		<h2>Function:
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.function.-get-recommendation-for-patient-hint-text-integer">_get_recommendation_for_patient_hint(text, integer)</a>
+		</h2>
+<h3>Returns: text</h3>
+<h3>Language: PLPGSQL</h3>
+        
+        <pre>
+DECLARE
+	_raw_query ALIAS FOR $1;
+	_pk_identity ALIAS FOR $2;
+	_query text;
+	_recommendation text;
+BEGIN
+	IF _raw_query IS NULL THEN
+		RETURN NULL::text;
+	END IF;
+	_query := replace(_raw_query, 'ID_ACTIVE_PATIENT', _pk_identity::text);
+	BEGIN
+		EXECUTE _query INTO STRICT _recommendation;
+	EXCEPTION
+		--WHEN insufficient_privilege THEN RAISE WARNING 'auto hint recommendation query failed: %', _query;
+		WHEN others THEN
+			RAISE WARNING 'auto hint recommendation query failed: %', _query;
+			-- only available starting with PG 9.2:
+			--GET STACKED DIAGNOSTICS
+			--	_exc_state = RETURNED_SQLSTATE,
+			--	_exc_msg = MESSAGE_TEXT,
+			--	_exc_detail = PG_EXCEPTION_DETAIL,
+			--	_exc_hint = PG_EXCEPTION_HINT,
+			--	_exc_context = PG_EXCEPTION_CONTEXT;
+			--RAISE WARNING 'SQL STATE: %', _exc_state;
+			--RAISE WARNING 'MESSAGE: %', _exc_msg;
+			--RAISE WARNING 'DETAIL: %', _exc_detail;
+			--RAISE WARNING 'HINT: %', _exc_hint;
+			--RAISE WARNING 'CONTEXT: %', _exc_context;
+			-- workaround for 9.1:
+			RAISE WARNING 'SQL STATE: %', SQLSTATE;
+			RAISE WARNING 'MESSAGE: %', SQLERRM;
+			_recommendation := 'ERROR running hint recommendation query [' || _query || ']';
+	END;
+	RETURN _recommendation;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
 			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.function.add-coded-phrase-text-text-text">add_coded_phrase(text, text, text)</a>
 		</h2>
 <h3>Returns: boolean</h3>
@@ -88135,17 +105656,21 @@ DECLARE
 	_rationale4suppression text;
 	_suppression_exists boolean;		-- does not mean that the suppression applies
 	_hint_currently_applies boolean;	-- regardless of whether suppressed or not
+	_hint_recommendation text;
 --	_exc_state text;
 --	_exc_msg text;
 --	_exc_detail text;
 --	_exc_hint text;
 --	_exc_context text;
 BEGIN
+	-- loop over all defined hints
 	FOR _hint IN SELECT * FROM ref.v_auto_hints WHERE is_active LOOP
 		-- is the hint suppressed ?
 		SELECT
 			md5_sum,
-			rationale INTO _md5_suppressed,
+			rationale
+				INTO
+			_md5_suppressed,
 			_rationale4suppression
 		FROM clin.suppressed_hint WHERE
 			fk_hint = _hint.pk_auto_hint
@@ -88208,10 +105733,11 @@ BEGIN
 				-- however - since it does not currently apply it - it will
 				-- still not be returned until it applies again ...
 				--
-				-- UNFORTUNATELY, this is currently not _possible_ because we
-				-- are running inside a READONLY transaction (due to inherent
-				-- security risks when running arbitrary user queries [=the hint
-				-- SQL]	-- against the database) and we cannot execute a
+				-- -----------------------------------------------------------------------
+				-- UNFORTUNATELY, the following is currently not _possible_ because
+				-- we are running inside a READONLY transaction (due to inherent
+				-- security risks when running arbitrary user queries [IOW the hint
+				-- SQL] against the database) and we cannot execute a
 				-- sub-transaction as READWRITE :-/
 				--
 				--UPDATE clin.suppressed_hint
@@ -88222,12 +105748,13 @@ BEGIN
 				--	)
 				--		AND
 				--	fk_hint = _hint.pk_auto_hint;
+				-- -----------------------------------------------------------------------
 				--
 				-- hence our our workaround is to, indeed, return the hint but
 				-- tag it with a magic rationale, by means of which the client
-				-- can detect it to be in need of invalidation
+				-- can detect it to be in need of invalidation:
 				_hint.title := 'HINT DOES NOT APPLY BUT NEEDS INVALIDATION OF EXISTING SUPPRESSION [' || _hint.title || '].';
-				_hint.rationale4suppression := 'please_invalidate_suppression';
+				_hint.rationale4suppression := 'magic_tag::please_invalidate_suppression';
 				RETURN NEXT _hint;
 				CONTINUE;
 			END IF;
@@ -88237,6 +105764,9 @@ BEGIN
 				-- yes: ignore the suppression but provide previous
 				-- rationale for suppression to the user
 				_hint.rationale4suppression := _rationale4suppression;
+				-- retrieve recommendation
+				SELECT clin._get_recommendation_for_patient_hint(_hint.recommendation_query, _pk_identity) INTO STRICT _hint_recommendation;
+				_hint.recommendation := _hint_recommendation;
 				RETURN NEXT _hint;
 				CONTINUE;
 			END IF;
@@ -88250,7 +105780,9 @@ BEGIN
 		-- hint is not suppressed
 		-- does the hint currently apply ?
 		IF _hint_currently_applies THEN
-			-- yes: return it
+			-- yes: retrieve recommendation
+			SELECT clin._get_recommendation_for_patient_hint(_hint.recommendation_query, _pk_identity) INTO STRICT _hint_recommendation;
+			_hint.recommendation := _hint_recommendation;
 			RETURN NEXT _hint;
 		END IF;
 		-- no: ignore it and process next hint in LOOP
@@ -88496,7 +106028,7 @@ BEGIN
 	select
 		* into _row
 	from
-		clin.v_pat_substance_intake_journal
+		clin.v_substance_intake_journal
 	where
 		src_pk = OLD.pk;
 	_pk_episode := _row.pk_episode;
@@ -88669,6 +106201,26 @@ end;</pre>
 	
 		<hr>
 		<h2>Function:
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.function.trf-ins-intake-set-substance-from-component">trf_ins_intake_set_substance_from_component()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        <p>On INSERT of a substance intake set fk_substance from fk_drug_component if the latter is NOT NULL.</p>
+        <pre>
+BEGIN
+	-- load fk_substance from drug_component table
+	select
+		r_ls2b.fk_substance into strict NEW.fk_substance
+	from
+		ref.lnk_substance2brand r_ls2b
+	where
+		r_ls2b.pk = NEW.fk_drug_component
+	;
+	return NEW;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
 			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.function.trf-ins-lc2sth-fk-generic-code">trf_ins_lc2sth_fk_generic_code()</a>
 		</h2>
 <h3>Returns: trigger</h3>
@@ -88692,6 +106244,47 @@ END;</pre>
 	
 		<hr>
 		<h2>Function:
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.function.trf-ins-upd-intake-prevent-duplicate-substance-links">trf_ins_upd_intake_prevent_duplicate_substance_links()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        <p>Prevent patient from being put on a particular substance more than once.</p>
+        <pre>
+DECLARE
+	_pk_patient integer;
+	_link_count integer;
+	_msg text;
+BEGIN
+	-- which patient ?
+	select fk_patient into _pk_patient
+	from clin.encounter
+	where pk = NEW.fk_encounter;
+	-- more than one link ?
+	select count(1) into _link_count
+	from clin.substance_intake
+	where
+		-- for this substance
+		fk_substance = NEW.fk_substance
+			and
+		-- either already linked as component OR
+		-- already linked as substance
+		fk_drug_component IS NOT DISTINCT FROM NEW.fk_drug_component
+			and
+		-- in this one patient
+		fk_encounter in (
+			select pk from clin.encounter where fk_patient = _pk_patient
+		)
+	;
+	if _link_count > 1 then
+		_msg := '[clin.trf_ins_upd_intake_prevent_duplicate_substance_links]: substance ref.consumable_substance.pk=(' || NEW.fk_substance || ') '
+			|| 'already linked to patient=(' || _pk_patient || ') ';
+		raise exception unique_violation using message = _msg;
+	end if;
+	return NEW;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
 			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.function.trf-ins-upd-validate-test-type-pks">trf_ins_upd_validate_test_type_pks()</a>
 		</h2>
 <h3>Returns: trigger</h3>
@@ -88857,47 +106450,6 @@ END;</pre>
 	
 		<hr>
 		<h2>Function:
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.function.trf-insert-update-intake-prevent-duplicate-substance-links">trf_insert_update_intake_prevent_duplicate_substance_links()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        <p>Prevent patient from being put on a particular substance more than once.</p>
-        <pre>
-DECLARE
-	_pk_patient integer;
-	_link_count integer;
-	_msg text;
-BEGIN
-	-- any substance at all (rather than drug component) ?
-	if NEW.fk_substance is NULL then
-		return NEW;
-	end if;
-	-- which patient ?
-	select fk_patient into _pk_patient
-	from clin.encounter
-	where pk = NEW.fk_encounter;
-	-- more than one link ?
-	select count(1) into _link_count
-	from clin.substance_intake
-	where
-		-- for this substance
-		fk_substance = NEW.fk_substance
-			and
-		-- in this one patient
-		fk_encounter in (
-			select pk from clin.encounter where fk_patient = _pk_patient
-		)
-	;
-	if _link_count > 1 then
-		_msg := '[clin.trf_insert_update_intake_prevent_duplicate_substance_links]: substance ref.consumable_substance.pk=(' || NEW.fk_substance || ') '
-			|| 'already linked to patient=(' || _pk_patient || ') ';
-		raise exception unique_violation using message = _msg;
-	end if;
-	return NEW;
-END;</pre>
-	
-		<hr>
-		<h2>Function:
 			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.function.trf-invalidate-review-on-result-change">trf_invalidate_review_on_result_change()</a>
 		</h2>
 <h3>Returns: trigger</h3>
@@ -88939,9 +106491,6 @@ END;</pre>
         
         <pre>
 BEGIN
-	if NEW.clin_end is NULL then
-		return NEW;
-	end if;
 	if NEW.clin_end > clock_timestamp() then
 		NEW.is_ongoing := TRUE;
 	else
@@ -89022,6 +106571,69 @@ end;</pre>
 	
 		<hr>
 		<h2>Function:
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.function.trf-sane-identity-comment">trf_sane_identity_comment()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        <p>Ensures unique(identity.dob, names.firstnames, names.lastnames, identity.comment)</p>
+        <pre>
+DECLARE
+	_identity_row record;
+	_names_row record;
+BEGIN
+	if TG_TABLE_NAME = 'identity' then
+		if TG_OP = 'UPDATE' then
+			if NEW.comment IS NOT DISTINCT FROM OLD.comment then
+				return NEW;
+			end if;
+		end if;
+		_identity_row := NEW;
+		select * into _names_row from dem.names where id_identity = NEW.pk;
+	else
+		select * into _identity_row from dem.identity where pk = NEW.id_identity;
+		_names_row := NEW;
+	end if;
+	-- any row with
+	PERFORM 1 FROM
+		dem.v_all_persons
+	WHERE
+		-- same firstname
+		firstnames = _names_row.firstnames
+			and
+		-- same lastname
+		lastnames = _names_row.lastnames
+			and
+		-- same gender
+		gender is not distinct from _identity_row.gender
+			and
+		-- same dob (day)
+		dob_only is not distinct from _identity_row.dob
+			and
+		-- same discriminator
+		comment is not distinct from _identity_row.comment
+			and
+		-- but not the currently updated or inserted row
+		pk_identity != _identity_row.pk
+	;
+	if FOUND then
+		RAISE EXCEPTION
+			'% on %.%: More than one person with (firstnames=%), (lastnames=%), (dob=%), (comment=%)',
+				TG_OP,
+				TG_TABLE_SCHEMA,
+				TG_TABLE_NAME,
+				_names_row.firstnames,
+				_names_row.lastnames,
+				_identity_row.dob,
+				_identity_row.comment
+			USING ERRCODE = 'unique_violation'
+		;
+		RETURN NULL;
+	end if;
+	return NEW;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
 			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.function.trf-sanity-check-enc-epi-ins-upd">trf_sanity_check_enc_epi_ins_upd()</a>
 		</h2>
 <h3>Returns: trigger</h3>
@@ -89162,49 +106774,6 @@ END;</pre>
 	
 		<hr>
 		<h2>Function:
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.function.trf-sanity-check-substance-episode">trf_sanity_check_substance_episode()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-declare
-	_identity_from_encounter integer;
-	_identity_from_episode integer;
-begin
-	-- episode can only be NULL if intake is not approved of,
-	-- IOW, if clinician approves of intake she better know why
-	if NEW.intake_is_approved_of is True then
-		if NEW.fk_episode is NULL then
-			raise exception 'clin.trf_sanity_check_substance_episode(): substance intake is approved of but .fk_episode is NULL';
-			return NULL;
-		end if;
-	end if;
-	-- .fk_episode can be NULL (except in the above case)
-	if NEW.fk_episode is NULL then
-		return NEW;
-	end if;
-	-- .fk_episode must belong to the same patient as .fk_encounter
-	select fk_patient into _identity_from_encounter from clin.encounter where pk = NEW.fk_encounter;
-	select fk_patient into _identity_from_episode from clin.encounter where pk = (
-		select fk_encounter from clin.episode where pk = NEW.fk_episode
-	);
-	if _identity_from_encounter <> _identity_from_episode then
-		raise exception 'INSERT/UPDATE into %.%: Sanity check failed. Encounter % patient = %. Episode % patient = %.',
-			TG_TABLE_SCHEMA,
-			TG_TABLE_NAME,
-			NEW.fk_encounter,
-			_identity_from_encounter,
-			NEW.fk_episode,
-			_identity_from_episode
-		;
-		return NULL;
-	end if;
-	return NEW;
-end;</pre>
-	
-		<hr>
-		<h2>Function:
 			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.function.trf-sanity-check-uniq-hint-per-pat-ins-upd">trf_sanity_check_uniq_hint_per_pat_ins_upd()</a>
 		</h2>
 <h3>Returns: trigger</h3>
@@ -89347,6 +106916,101 @@ END;</pre>
 	
 		<hr>
 		<h2>Function:
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.function.trf-upd-intake-set-substance-from-component">trf_upd_intake_set_substance_from_component()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        <p>On UPDATE of a substance intake set fk_substance from fk_drug_component if the latter changes.</p>
+        <pre>
+BEGIN
+	-- load fk_substance from drug_component table
+	select
+		r_ls2b.fk_substance into strict NEW.fk_substance
+	from
+		ref.lnk_substance2brand r_ls2b
+	where
+		r_ls2b.pk = NEW.fk_drug_component
+	;
+	return NEW;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.function.trf-upd-intake-updates-all-drug-components">trf_upd_intake_updates_all_drug_components()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        <p>If a drug component substance intake is updated all sibling components must receive some values thereof.</p>
+        <pre>
+DECLARE
+	_pk_brand integer;
+	_component_count integer;
+	_pk_patient integer;
+BEGIN
+	-- which drug ?
+	select fk_brand into _pk_brand
+	from ref.lnk_substance2brand
+	where pk = NEW.fk_drug_component;
+	-- how many components therein ?
+	select count(1) into _component_count
+	from ref.lnk_substance2brand
+	where fk_brand = _pk_brand;
+	-- only one component ?
+	if _component_count = 1 then
+		return NEW;
+	end if;
+	-- which patient ?
+	select fk_patient into _pk_patient
+	from clin.encounter
+	where pk = NEW.fk_encounter;
+	-- update all substance instake fields shared by drug components ...
+	update clin.substance_intake set
+		clin_when = NEW.clin_when,				-- started
+		fk_encounter = NEW.fk_encounter,
+		soap_cat = NEW.soap_cat,
+		schedule = NEW.schedule,
+		duration = NEW.duration,
+		intake_is_approved_of = NEW.intake_is_approved_of,
+		is_long_term = NEW.is_long_term,
+		discontinued = NEW.discontinued
+	where
+		-- ... which belong to this drug ...
+		fk_drug_component in (
+			select pk from ref.lnk_substance2brand where fk_brand = _pk_brand
+		)
+			AND
+		-- ... but are not THIS component ...
+		fk_drug_component != NEW.fk_drug_component
+			AND
+		-- ... this patient ...
+		fk_encounter in (
+			select pk from clin.encounter where fk_patient = _pk_patient
+		)
+			AND
+		-- ... are different in value (this will stop recursion as soon as all are equal)
+		(
+			clin_when is distinct from NEW.clin_when
+				OR
+			fk_encounter is distinct from NEW.fk_encounter
+				OR
+			soap_cat is distinct from NEW.soap_cat
+				OR
+			schedule is distinct from NEW.schedule
+				OR
+			duration is distinct from NEW.duration
+				OR
+			intake_is_approved_of is distinct from NEW.intake_is_approved_of
+				OR
+			is_long_term is distinct from NEW.is_long_term
+				OR
+			discontinued is distinct from NEW.discontinued
+		)
+	;
+	return NEW;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
 			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.function.trf-upd-lc2sth-fk-generic-code">trf_upd_lc2sth_fk_generic_code()</a>
 		</h2>
 <h3>Returns: trigger</h3>
@@ -89457,85 +107121,6 @@ END;</pre>
 	
 		<hr>
 		<h2>Function:
-			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.function.trf-update-intake-updates-all-drug-components">trf_update_intake_updates_all_drug_components()</a>
-		</h2>
-<h3>Returns: trigger</h3>
-<h3>Language: PLPGSQL</h3>
-        <p>If a drug component substance intake is updated all sibling components must receive some values thereof.</p>
-        <pre>
-DECLARE
-	_pk_brand integer;
-	_component_count integer;
-	_pk_patient integer;
-BEGIN
-	-- does it at all relate to a drug (rather than substance) ?
-	if NEW.fk_drug_component is null then
-		return NEW;
-	end if;
-	-- which drug ?
-	select fk_brand into _pk_brand
-	from ref.lnk_substance2brand
-	where pk = NEW.fk_drug_component;
-	-- how many components therein ?
-	select count(1) into _component_count
-	from ref.lnk_substance2brand
-	where fk_brand = _pk_brand;
-	-- only one component ?
-	if _component_count = 1 then
-		return NEW;
-	end if;
-	-- which patient ?
-	select fk_patient into _pk_patient
-	from clin.encounter
-	where pk = NEW.fk_encounter;
-	-- update all substance instakes ...
-	update clin.substance_intake set
-		clin_when = NEW.clin_when,				-- started
-		fk_encounter = NEW.fk_encounter,
-		soap_cat = NEW.soap_cat,
-		schedule = NEW.schedule,
-		duration = NEW.duration,
-		intake_is_approved_of = NEW.intake_is_approved_of,
-		is_long_term = NEW.is_long_term,
-		discontinued = NEW.discontinued
-	where
-		-- ... which belong to this drug ...
-		fk_drug_component in (
-			select pk from ref.lnk_substance2brand where fk_brand = _pk_brand
-		)
-			AND
-		-- ... but are not THIS component ...
-		fk_drug_component != NEW.fk_drug_component
-			AND
-		-- ... this patient ...
-		fk_encounter in (
-			select pk from clin.encounter where fk_patient = _pk_patient
-		)
-			AND
-		-- ... are different in value (this will stop recursion as soon as all are equal)
-		(
-			clin_when is distinct from NEW.clin_when
-				OR
-			fk_encounter is distinct from NEW.fk_encounter
-				OR
-			soap_cat is distinct from NEW.soap_cat
-				OR
-			schedule is distinct from NEW.schedule
-				OR
-			duration is distinct from NEW.duration
-				OR
-			intake_is_approved_of is distinct from NEW.intake_is_approved_of
-				OR
-			is_long_term is distinct from NEW.is_long_term
-				OR
-			discontinued is distinct from NEW.discontinued
-		)
-	;
-	return NEW;
-END;</pre>
-	
-		<hr>
-		<h2>Function:
 			<a href="gnumed-entire_schema.html#clin.schema">clin</a>.<a name="clin.function.trf-warn-on-duplicate-vaccinations">trf_warn_on_duplicate_vaccinations()</a>
 		</h2>
 <h3>Returns: trigger</h3>
@@ -89721,11 +107306,19 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -89847,172 +107440,24 @@ END;</pre>
 
         <!-- Constraint List -->
 		
-
-        <!-- Foreign Key Discovery -->
-		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#de-de.table.behandlungsfall">de_de.behandlungsfall</a></li>
-			</ul>
-		
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#de-de.schema">Schema de_de</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>de_de.beh_fall_typ Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
 			
-			<a href="gnumed-entire_schema.html#de-de.schema">de_de</a>.<a name="de-de.table.behandlungsfall">behandlungsfall</a>
-		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>de_de.behandlungsfall Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
-				<td>
-                
-                  
-                
-                </td>
-            	<td>pk</td>
-            	<td>serial</td>
-                <td><i>
-				
-					PRIMARY KEY
-					
-
-					
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.identity">dem.identity.pk</a>
-                  
-                
-                </td>
-            	<td>fk_patient</td>
-            	<td>integer</td>
-                <td><i>
-				
-					
-
-					
-				
-
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                  
-                  <a href="gnumed-entire_schema.html#de-de.table.beh-fall-typ">de_de.beh_fall_typ.pk</a>
-                  
-                
-                </td>
-            	<td>fk_falltyp</td>
-            	<td>integer</td>
-                <td><i>
-				
-					
-
-					
-				
-
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>started</td>
-            	<td>date</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT ('now'::text)::date
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>must_pay_prax_geb</td>
-            	<td>boolean</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT true
-				</i>
-				
-				</td>
-			 </tr>
-            
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
 		
 
         <!-- Foreign Key Discovery -->
 		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#de-de.table.prax-geb-paid">de_de.prax_geb_paid</a></li>
-			</ul>
-		
-		
 
     <!-- Indexes -->
     
@@ -90537,11 +107982,19 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -90615,6 +108068,21 @@ END;</pre>
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>de_de.lab_test_gnr Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
@@ -90801,11 +108269,19 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -90840,19 +108316,11 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#de-de.table.behandlungsfall">de_de.behandlungsfall.pk</a>
-                  
-                
                 </td>
             	<td>fk_fall</td>
             	<td>integer</td>
                 <td><i>
 				
-					
-
-					
-				
 
 				NOT NULL
 				
@@ -90935,6 +108403,21 @@ END;</pre>
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>de_de.prax_geb_paid Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
@@ -91193,11 +108676,19 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -91399,6 +108890,21 @@ END;</pre>
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>dem.address Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
@@ -91673,7 +109179,7 @@ END;</pre>
 			<p>Tables referencing this one via Foreign Key Constraints:</p>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#dem.table.state">dem.state</a></li>
+				<li><a href="gnumed-entire_schema.html#dem.table.region">dem.region</a></li>
 			</ul>
 		
 		
@@ -91997,254 +109503,275 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
-                </td>
-            	<td>modified_by</td>
-            	<td>name</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT "current_user"()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                  
-                
-                </td>
-            	<td>pk</td>
-            	<td>serial</td>
-                <td><i>
-				
-					PRIMARY KEY
-					
-
-					
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
                   
-                
-                </td>
-            	<td>tag</td>
-            	<td>text</td>
-                <td><i>
-				
-					
-
-					
-                       UNIQUE
-                    
-				
-
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				DEFAULT "current_user"()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>tag</td>
+            	<td>text</td>
+                <td><i>
+				
+					
+
+					
+                       UNIQUE
+                    
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>label</td>
+            	<td>text</td>
+                <td><i>
+				
+					
+
+					
+                       UNIQUE
+                    
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>sort_weight</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>comment</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table dem.gender_label Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>dem.gender_label Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>gender_label_tag_check</td>
+                <td>CHECK ((tag = ANY (ARRAY['m'::text, 'f'::text, 'h'::text, 'tm'::text, 'tf'::text])))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.identity">dem.identity</a></li>
+			</ul>
+		
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#dem.schema">Schema dem</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.identity">identity</a>
+		</h2>
+        
+         <p>represents the unique identity of a person</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>dem.identity Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
                   
                 
                 </td>
-            	<td>label</td>
-            	<td>text</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 					
 
 					
-                       UNIQUE
-                    
-				
-
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>sort_weight</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>comment</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table dem.gender_label Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>dem.gender_label Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>gender_label_tag_check</td>
-                <td>CHECK ((tag = ANY (ARRAY['m'::text, 'f'::text, 'h'::text, 'tm'::text, 'tf'::text])))</td>
-            </tr>
-			
-		</table>
-		
-
-        <!-- Foreign Key Discovery -->
-		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#dem.table.identity">dem.identity</a></li>
-			</ul>
-		
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#dem.schema">Schema dem</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.identity">identity</a>
-		</h2>
-        
-         <p>represents the unique identity of a person</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>dem.identity Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>row_version</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT now()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>modified_by</td>
-            	<td>name</td>
-                <td><i>
 				
 
 				NOT NULL
@@ -92296,22 +109823,6 @@ END;</pre>
             <tr class="tr0">
 				<td>
                 
-                </td>
-            	<td>pupic</td>
-            	<td>character(24)</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				<br><br>Portable Unique Person Identification Code as per gnumed white papers
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
                   
                   <a href="gnumed-entire_schema.html#dem.table.gender-label">dem.gender_label.tag</a>
                   
@@ -92333,7 +109844,7 @@ END;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -92349,7 +109860,7 @@ END;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                   
@@ -92373,7 +109884,7 @@ END;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -92389,7 +109900,7 @@ END;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -92405,7 +109916,7 @@ END;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -92422,7 +109933,7 @@ END;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -92438,7 +109949,7 @@ END;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -92454,7 +109965,7 @@ END;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                   
@@ -92478,7 +109989,7 @@ END;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -92490,11 +110001,26 @@ END;</pre>
 				
 				
 				</i>
-				<br><br>A free-text comment on this identity.
+				<br><br>A free-text comment on this identity.\n
+\n
+Can be used to to discriminate patients which are otherwise\n
+identical regarding name and date of birth.\n
+Should be something non-ephemereal and unique to the person\n
+itself across time, place and database instance.\n
+Good: place of birth\n
+Good: maiden name of mother\n
+Good: mother of <name>\n
+Good: hash of DNA\n
+Good (?): hair color of first pet\n
+Bad: current address (will change)\n
+Bad: primary provider in this praxis (can change, invalid in another GNUmed instance)\n
+Bad: nickname (will change, can dupe as well)\n
+Bad: favourite food\n
+not-quite-so-bad: occupation
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                   
@@ -92518,7 +110044,7 @@ END;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -92561,26 +110087,31 @@ END;</pre>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>dem_identity_sane_dob</td>
                 <td>CHECK (((dob IS NULL) OR (dob <= now())))</td>
             </tr>
 			
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>dem_identity_sane_dod</td>
                 <td>CHECK ((((deceased IS NULL) OR (dob IS NULL)) OR (deceased >= dob)))</td>
             </tr>
 			
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>identity_title_check</td>
                 <td>CHECK ((btrim(COALESCE(title, 'NULL'::text)) <> ''::text))</td>
             </tr>
 			
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>sane_comment</td>
                 <td>CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE))</td>
             </tr>
 			
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>sane_emergency_contact</td>
                 <td>CHECK ((gm.is_null_or_non_empty_string(emergency_contact) IS TRUE))</td>
             </tr>
@@ -92617,10 +110148,6 @@ END;</pre>
 			</ul>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#de-de.table.behandlungsfall">de_de.behandlungsfall</a></li>
-			</ul>
-		
-			<ul>
 				<li><a href="gnumed-entire_schema.html#de-de.table.kvk">de_de.kvk</a></li>
 			</ul>
 		
@@ -92756,11 +110283,19 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -92899,6 +110434,11 @@ END;</pre>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>dem_identity_tag_sane_comment</td>
                 <td>CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE))</td>
             </tr>
@@ -92994,11 +110534,19 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -93105,6 +110653,11 @@ END;</pre>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>inbox_item_category_description_check</td>
                 <td>CHECK ((btrim(COALESCE(description, 'xxxDEFAULTxxx'::text)) <> ''::text))</td>
             </tr>
@@ -93207,11 +110760,19 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -93343,6 +110904,11 @@ END;</pre>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>inbox_item_type_description_check</td>
                 <td>CHECK ((btrim(COALESCE(description, 'xxxDEFAULTxxx'::text)) <> ''::text))</td>
             </tr>
@@ -93669,11 +111235,19 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -93829,6 +111403,21 @@ END;</pre>
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>dem.lnk_identity2ext_id Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
@@ -93917,234 +111506,265 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
-                </td>
-            	<td>modified_by</td>
-            	<td>name</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT "current_user"()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                  
-                
-                </td>
-            	<td>pk</td>
-            	<td>serial</td>
-                <td><i>
-				
-					PRIMARY KEY
-					
-
-					
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.identity">dem.identity.pk</a>
-                  
-                
-                  
-                
-                </td>
-            	<td>fk_identity</td>
-            	<td>integer</td>
-                <td><i>
-				
-					
-
-					
-				
-					
-
-					
-                       UNIQUE#1
-                    
-				
-
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
                   
-                  <a href="gnumed-entire_schema.html#dem.table.occupation">dem.occupation.id</a>
-                  
-                
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				DEFAULT "current_user"()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.identity">dem.identity.pk</a>
+                  
+                
+                  
+                
+                </td>
+            	<td>fk_identity</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+					
+
+					
+                       UNIQUE#1
+                    
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.occupation">dem.occupation.id</a>
+                  
+                
+                  
+                
+                </td>
+            	<td>fk_occupation</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+					
+
+					
+                       UNIQUE#1
+                    
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>activities</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>describes activities the person is usually
+	 carrying out when working at this job
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table dem.lnk_job2person Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>dem.lnk_job2person Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#dem.schema">Schema dem</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.lnk-org-unit2comm">lnk_org_unit2comm</a>
+		</h2>
+        
+         <p>Comm channels per org unit.</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>dem.lnk_org_unit2comm Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
                   
                 
                 </td>
-            	<td>fk_occupation</td>
-            	<td>integer</td>
+            	<td>modified_by</td>
+            	<td>name</td>
                 <td><i>
 				
 					
 
 					
 				
-					
-
-					
-                       UNIQUE#1
-                    
-				
-
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>activities</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				<br><br>describes activities the person is usually
-	 carrying out when working at this job
-				</td>
-			 </tr>
-            
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table dem.lnk_job2person Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#dem.schema">Schema dem</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.lnk-org-unit2comm">lnk_org_unit2comm</a>
-		</h2>
-        
-         <p>Comm channels per org unit.</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>dem.lnk_org_unit2comm Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>row_version</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
-                <td><i>
-				
-
-				NOT NULL
-				DEFAULT now()
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>modified_by</td>
-            	<td>name</td>
-                <td><i>
-				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -94323,11 +111943,16 @@ END;</pre>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>dem_lnk_unit2comm_sane_comment</td>
                 <td>CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE))</td>
             </tr>
 			
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>lnk_org_unit2comm_sane_url</td>
                 <td>CHECK ((gm.is_null_or_blank_string(url) IS FALSE))</td>
             </tr>
@@ -94422,11 +112047,19 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -94589,11 +112222,16 @@ END;</pre>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>lnk_org_unit2ext_id_sane_comment</td>
                 <td>CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE))</td>
             </tr>
 			
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>lnk_org_unit2ext_id_sane_id</td>
                 <td>CHECK ((gm.is_null_or_blank_string(external_id) IS FALSE))</td>
             </tr>
@@ -94703,8 +112341,11 @@ END;</pre>
 	
 	<pre>
 SELECT lnk_person_org_address.id_identity
-, lnk_person_org_address.id_address
-, lnk_person_org_address.id_type 
+,
+    lnk_person_org_address.id_address
+,
+    lnk_person_org_address.id_type
+   
 FROM dem.lnk_person_org_address;</pre>
 	
 
@@ -94786,11 +112427,19 @@ FROM dem.lnk_person_org_address;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -94947,6 +112596,21 @@ FROM dem.lnk_person_org_address;</pre>
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>dem.lnk_person2relative Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
@@ -95354,11 +113018,19 @@ FROM dem.lnk_person_org_address;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -95595,21 +113267,26 @@ FROM dem.lnk_person_org_address;</pre>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>dem_inbox_sane_expiry_date</td>
                 <td>CHECK ((((expiry_date IS NULL) OR (due_date IS NULL)) OR (expiry_date > due_date)))</td>
             </tr>
 			
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>message_must_have_recipient</td>
                 <td>CHECK ((((fk_staff IS NULL) AND (fk_patient IS NULL)) IS FALSE))</td>
             </tr>
 			
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>provider_inbox_comment_check</td>
                 <td>CHECK ((btrim(COALESCE(comment, 'xxxDEFAULTxxx'::text)) <> ''::text))</td>
             </tr>
 			
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>provider_inbox_importance_check</td>
                 <td>CHECK ((((importance = (-1)) OR (importance = 0)) OR (importance = 1)))</td>
             </tr>
@@ -96053,11 +113730,19 @@ FROM dem.lnk_person_org_address;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -96132,6 +113817,11 @@ FROM dem.lnk_person_org_address;</pre>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>occupation_name_check</td>
                 <td>CHECK ((btrim(name) <> ''::text))</td>
             </tr>
@@ -96233,11 +113923,368 @@ FROM dem.lnk_person_org_address;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				DEFAULT "current_user"()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>description</td>
+            	<td>text</td>
+                <td><i>
+				
+					
+
+					
+                       UNIQUE
+                    
+				
+
+				
+				
+				</i>
+				<br><br>High-level, conceptual description (= name) of organization, such as "University of Manchester".
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.org-category">dem.org_category.pk</a>
+                  
+                
+                </td>
+            	<td>fk_category</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#ref.table.data-source">ref.data_source.pk</a>
+                  
+                
+                </td>
+            	<td>fk_data_source</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				
+				
+				</i>
+				<br><br>Source of the organization data.
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+        <p>Table dem.org Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>dem.org Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>org_sane_description</td>
+                <td>CHECK ((gm.is_null_or_blank_string(description) IS FALSE))</td>
+            </tr>
+			
+		</table>
+		
+
+        <!-- Foreign Key Discovery -->
+		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.org-unit">dem.org_unit</a></li>
+			</ul>
+		
+		
+
+    <!-- Indexes -->
+    
+       idx_dem_org_fk_category fk_category
+    
+       idx_trgm_dem_org_desc description pgtrgm.gin_trgm_ops
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#dem.schema">Schema dem</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.org-category">org_category</a>
+		</h2>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>dem.org_category Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
+            	<td>pk</td>
+            	<td>serial</td>
+                <td><i>
+				
+					PRIMARY KEY
+					
+
+					
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>description</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+		
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.org">dem.org</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.org-unit">dem.org_unit</a></li>
+			</ul>
+		
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#dem.schema">Schema dem</a>
+    </p>
+	
+        <hr>
+		<h2>Table:
+			
+			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.org-unit">org_unit</a>
+		</h2>
+        
+         <p>Actual branches/departments/offices/... of organizations.</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>dem.org_unit Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -96282,14 +114329,14 @@ FROM dem.lnk_person_org_address;</pre>
 					
 
 					
-                       UNIQUE
+                       UNIQUE#1
                     
 				
 
 				
 				
 				</i>
-				<br><br>High-level, conceptual description (= name) of organization, such as "University of Manchester".
+				<br><br>Description (= name) of branch of organization, such as "Elms Street office of Jim Busser Praxis".
 				</td>
 			 </tr>
             
@@ -96297,11 +114344,13 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#dem.table.org-category">dem.org_category.pk</a>
+                  <a href="gnumed-entire_schema.html#dem.table.org">dem.org.pk</a>
+                  
+                
                   
                 
                 </td>
-            	<td>fk_category</td>
+            	<td>fk_org</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -96309,8 +114358,14 @@ FROM dem.lnk_person_org_address;</pre>
 
 					
 				
+					
 
+					
+                       UNIQUE#1
+                    
 				
+
+				NOT NULL
 				
 				</i>
 				
@@ -96321,11 +114376,11 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#ref.table.data-source">ref.data_source.pk</a>
+                  <a href="gnumed-entire_schema.html#dem.table.address">dem.address.id</a>
                   
                 
                 </td>
-            	<td>fk_data_source</td>
+            	<td>fk_address</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -96337,7 +114392,31 @@ FROM dem.lnk_person_org_address;</pre>
 				
 				
 				</i>
-				<br><br>Source of the organization data.
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.org-category">dem.org_category.pk</a>
+                  
+                
+                </td>
+            	<td>fk_category</td>
+            	<td>integer</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				
+				
+				</i>
+				
 				</td>
 			 </tr>
             
@@ -96345,7 +114424,7 @@ FROM dem.lnk_person_org_address;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table dem.org Inherits
+        <p>Table dem.org_unit Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
@@ -96361,14 +114440,19 @@ FROM dem.lnk_person_org_address;</pre>
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>dem.org Constraints</caption>
+            <caption>dem.org_unit Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
-				<td>org_sane_description</td>
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>org_unit_sane_description</td>
                 <td>CHECK ((gm.is_null_or_blank_string(description) IS FALSE))</td>
             </tr>
 			
@@ -96380,16 +114464,46 @@ FROM dem.lnk_person_org_address;</pre>
 			<p>Tables referencing this one via Foreign Key Constraints:</p>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#dem.table.org-unit">dem.org_unit</a></li>
+				<li><a href="gnumed-entire_schema.html#blobs.table.doc-med">blobs.doc_med</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.external-care">clin.external_care</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.hospital-stay">clin.hospital_stay</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.procedure">clin.procedure</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.test-org">clin.test_org</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.lnk-org-unit2comm">dem.lnk_org_unit2comm</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.lnk-org-unit2ext-id">dem.lnk_org_unit2ext_id</a></li>
 			</ul>
 		
 		
 
     <!-- Indexes -->
     
-       idx_dem_org_fk_category fk_category
+       idx_dem_org_unit_fk_address fk_address
     
-       idx_trgm_dem_org_desc description gin_trgm_ops
+       idx_dem_org_unit_fk_category fk_category
+    
+       idx_trgm_dem_org_unit_desc description pgtrgm.gin_trgm_ops
     
 
 	<!-- View Definition -->
@@ -96406,13 +114520,15 @@ FROM dem.lnk_person_org_address;</pre>
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.org-category">org_category</a>
+			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.praxis-branch">praxis_branch</a>
 		</h2>
         
+         <p>Defines one branch of a praxis (which itself is a dem.org)</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>dem.org_category Structure</caption>
+                <caption>dem.praxis_branch Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -96423,6 +114539,78 @@ FROM dem.lnk_person_org_address;</pre>
             <tr class="tr0">
 				<td>
                 
+                </td>
+            	<td>pk_audit</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>row_version</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				NOT NULL
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>modified_when</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT now()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
+                </td>
+            	<td>modified_by</td>
+            	<td>name</td>
+                <td><i>
+				
+					
+
+					
+				
+
+				NOT NULL
+				DEFAULT "current_user"()
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
                   
                 
                 </td>
@@ -96446,11 +114634,19 @@ FROM dem.lnk_person_org_address;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>description</td>
-            	<td>text</td>
+            	<td>fk_org_unit</td>
+            	<td>integer</td>
                 <td><i>
 				
+					
+
+					
+                       UNIQUE
+                    
+				
 
 				NOT NULL
 				
@@ -96463,6 +114659,13 @@ FROM dem.lnk_person_org_address;</pre>
 
         <!-- Inherits -->
 		
+        <p>Table dem.praxis_branch Inherits
+        
+            
+           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
+        
+        </p>
+		
 
 		
 		
@@ -96470,20 +114673,24 @@ FROM dem.lnk_person_org_address;</pre>
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>dem.praxis_branch Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#dem.table.org">dem.org</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#dem.table.org-unit">dem.org_unit</a></li>
-			</ul>
-		
-		
 
     <!-- Indexes -->
     
@@ -96502,15 +114709,17 @@ FROM dem.lnk_person_org_address;</pre>
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.org-unit">org_unit</a>
+			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.region">region</a>
 		</h2>
         
-         <p>Actual branches/departments/offices/... of organizations.</p>
+         <p>region codes (country specific);
+	 Richard agreed we should require pre-existence,
+	 allow user to mail details for adding a state to developers</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>dem.org_unit Structure</caption>
+                <caption>dem.region Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -96569,11 +114778,19 @@ FROM dem.lnk_person_org_address;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -96611,7 +114828,7 @@ FROM dem.lnk_person_org_address;</pre>
                   
                 
                 </td>
-            	<td>description</td>
+            	<td>code</td>
             	<td>text</td>
                 <td><i>
 				
@@ -96622,10 +114839,10 @@ FROM dem.lnk_person_org_address;</pre>
                     
 				
 
-				
+				NOT NULL
 				
 				</i>
-				<br><br>Description (= name) of branch of organization, such as "Elms Street office of Jim Busser Praxis".
+				<br><br>region code
 				</td>
 			 </tr>
             
@@ -96633,76 +114850,44 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#dem.table.org">dem.org.pk</a>
-                  
                 
                   
+                  <a href="gnumed-entire_schema.html#dem.table.country">dem.country.code</a>
+                  
                 
                 </td>
-            	<td>fk_org</td>
-            	<td>integer</td>
+            	<td>country</td>
+            	<td>character(2)</td>
                 <td><i>
 				
 					
 
 					
-				
-					
-
-					
                        UNIQUE#1
                     
 				
-
-				NOT NULL
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.address">dem.address.id</a>
-                  
-                
-                </td>
-            	<td>fk_address</td>
-            	<td>integer</td>
-                <td><i>
-				
 					
 
 					
 				
 
-				
+				NOT NULL
 				
 				</i>
-				
+				<br><br>2 character ISO 3166-1 country code
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.org-category">dem.org_category.pk</a>
-                  
-                
                 </td>
-            	<td>fk_category</td>
-            	<td>integer</td>
+            	<td>name</td>
+            	<td>text</td>
                 <td><i>
 				
-					
 
-					
-				
-
-				
+				NOT NULL
 				
 				</i>
 				
@@ -96713,7 +114898,7 @@ FROM dem.lnk_person_org_address;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table dem.org_unit Inherits
+        <p>Table dem.region Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
@@ -96729,15 +114914,21 @@ FROM dem.lnk_person_org_address;</pre>
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>dem.org_unit Constraints</caption>
+            <caption>dem.region Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
-				<td>org_unit_sane_description</td>
-                <td>CHECK ((gm.is_null_or_blank_string(description) IS FALSE))</td>
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>no_linebreaks</td>
+                <td>CHECK ((((("position"(((COALESCE(code, ''::text) || (COALESCE(country, ''::bpchar))::text) || COALESCE(name, ''::text)), '
'::text) = 0) AND ("position"(((COALESCE(code, ''::text) || (COALESCE(country, ''::bpchar))::text) || COALESCE(name, ''::text)), '
+'::text) = 0)) AND ("position"(((COALESCE(code, ''::text) || (COALESCE(country, ''::bpchar))::text) || COALESCE(name, ''::text)), '
'::text) = 0)) AND ("position"(((COALESCE(code, ''::text) || (COALESCE(country, ''::bpchar))::text) || COALESCE(name, ''::text)), '
'::text) = 0)))</td>
             </tr>
 			
 		</table>
@@ -96748,42 +114939,16 @@ FROM dem.lnk_person_org_address;</pre>
 			<p>Tables referencing this one via Foreign Key Constraints:</p>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.external-care">clin.external_care</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.hospital-stay">clin.hospital_stay</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.procedure">clin.procedure</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.test-org">clin.test_org</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#dem.table.lnk-org-unit2comm">dem.lnk_org_unit2comm</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#dem.table.lnk-org-unit2ext-id">dem.lnk_org_unit2ext_id</a></li>
+				<li><a href="gnumed-entire_schema.html#dem.table.urb">dem.urb</a></li>
 			</ul>
 		
 		
 
     <!-- Indexes -->
     
-       idx_dem_org_unit_fk_address fk_address
-    
-       idx_dem_org_unit_fk_category fk_category
+       idx_dem_state_country_code country
     
-       idx_trgm_dem_org_unit_desc description gin_trgm_ops
+       idx_state_names name
     
 
 	<!-- View Definition -->
@@ -96800,15 +114965,15 @@ FROM dem.lnk_person_org_address;</pre>
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.praxis-branch">praxis_branch</a>
+			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.relation-types">relation_types</a>
 		</h2>
         
-         <p>Defines one branch of a praxis (which itself is a dem.org)</p>
+         <p>types of biological/social relationships between identities</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>dem.praxis_branch Structure</caption>
+                <caption>dem.relation_types Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -96867,11 +115032,19 @@ FROM dem.lnk_person_org_address;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -96886,7 +115059,7 @@ FROM dem.lnk_person_org_address;</pre>
                   
                 
                 </td>
-            	<td>pk</td>
+            	<td>id</td>
             	<td>serial</td>
                 <td><i>
 				
@@ -96907,23 +115080,72 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                   
+                  <a href="gnumed-entire_schema.html#dem.table.relation-types">dem.relation_types.id</a>
+                  
                 
                 </td>
-            	<td>fk_org_unit</td>
+            	<td>inverse</td>
             	<td>integer</td>
                 <td><i>
 				
 					
 
 					
-                       UNIQUE
-                    
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>biological</td>
+            	<td>boolean</td>
+                <td><i>
 				
 
 				NOT NULL
 				
 				</i>
+				<br><br>true if relationship is biological (proven or
+	 reasonable assumption), else false
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>biol_verified</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				DEFAULT false
+				</i>
+				<br><br>ONLY true if there is genetic proof for this relationship
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>description</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
 				
+				</i>
+				<br><br>plain text description of relationship
 				</td>
 			 </tr>
             
@@ -96931,7 +115153,7 @@ FROM dem.lnk_person_org_address;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table dem.praxis_branch Inherits
+        <p>Table dem.relation_types Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
@@ -96945,9 +115167,35 @@ FROM dem.lnk_person_org_address;</pre>
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>dem.relation_types Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
+			<p>Tables referencing this one via Foreign Key Constraints:</p>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.lnk-person2relative">dem.lnk_person2relative</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.relation-types">dem.relation_types</a></li>
+			</ul>
+		
+		
 
     <!-- Indexes -->
     
@@ -96966,15 +115214,16 @@ FROM dem.lnk_person_org_address;</pre>
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.relation-types">relation_types</a>
+			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.staff">staff</a>
 		</h2>
         
-         <p>types of biological/social relationships between identities</p>
+         <p>one-to-one mapping of database user accounts
+	 (db_user) to staff identities (fk_identity)</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>dem.relation_types Structure</caption>
+                <caption>dem.staff Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -97052,7 +115301,7 @@ FROM dem.lnk_person_org_address;</pre>
                   
                 
                 </td>
-            	<td>id</td>
+            	<td>pk</td>
             	<td>serial</td>
                 <td><i>
 				
@@ -97073,11 +115322,11 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#dem.table.relation-types">dem.relation_types.id</a>
+                  <a href="gnumed-entire_schema.html#dem.table.identity">dem.identity.pk</a>
                   
                 
                 </td>
-            	<td>inverse</td>
+            	<td>fk_identity</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -97086,7 +115335,7 @@ FROM dem.lnk_person_org_address;</pre>
 					
 				
 
-				
+				NOT NULL
 				
 				</i>
 				
@@ -97096,33 +115345,50 @@ FROM dem.lnk_person_org_address;</pre>
             <tr class="tr0">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>biological</td>
-            	<td>boolean</td>
+            	<td>db_user</td>
+            	<td>name</td>
                 <td><i>
 				
+					
 
-				NOT NULL
+					
+                       UNIQUE
+                    
 				
+
+				NOT NULL
+				DEFAULT "current_user"()
 				</i>
-				<br><br>true if relationship is biological (proven or
-	 reasonable assumption), else false
+				
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
+                  
+                
                 </td>
-            	<td>biol_verified</td>
-            	<td>boolean</td>
+            	<td>short_alias</td>
+            	<td>text</td>
                 <td><i>
 				
+					
 
+					
+                       UNIQUE
+                    
+				
+
+				NOT NULL
 				
-				DEFAULT false
 				</i>
-				<br><br>ONLY true if there is genetic proof for this relationship
+				<br><br>a short signature unique to this staff member
+	 to be used in the GUI, actually this is somewhat
+	 redundant with ext_person_id...
 				</td>
 			 </tr>
             
@@ -97130,7 +115396,7 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                 </td>
-            	<td>description</td>
+            	<td>comment</td>
             	<td>text</td>
                 <td><i>
 				
@@ -97138,7 +115404,23 @@ FROM dem.lnk_person_org_address;</pre>
 				
 				
 				</i>
-				<br><br>plain text description of relationship
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>is_active</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				NOT NULL
+				DEFAULT true
+				</i>
+				
 				</td>
 			 </tr>
             
@@ -97146,7 +115428,7 @@ FROM dem.lnk_person_org_address;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table dem.relation_types Inherits
+        <p>Table dem.staff Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
@@ -97160,19 +115442,390 @@ FROM dem.lnk_person_org_address;</pre>
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>dem.staff Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
 			<p>Tables referencing this one via Foreign Key Constraints:</p>
 		
 			<ul>
+				<li><a href="gnumed-entire_schema.html#au.table.referral">au.referral</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#bill.table.bill">bill.bill</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#bill.table.bill-item">bill.bill_item</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#blobs.table.doc-desc">blobs.doc_desc</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#blobs.table.doc-med">blobs.doc_med</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#blobs.table.doc-obj">blobs.doc_obj</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#cfg.table.report-query">cfg.report_query</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.allergy">clin.allergy</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.allergy-state">clin.allergy_state</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.clin-aux-note">clin.clin_aux_note</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.clin-diag">clin.clin_diag</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.clin-item-type">clin.clin_item_type</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.clin-narrative">clin.clin_narrative</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.encounter">clin.encounter</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.episode">clin.episode</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.external-care">clin.external_care</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.family-history">clin.family_history</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.fhx-relation-type">clin.fhx_relation_type</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.form-data">clin.form_data</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.form-instances">clin.form_instances</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.health-issue">clin.health_issue</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.hospital-stay">clin.hospital_stay</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.incoming-data-unmatchable">clin.incoming_data_unmatchable</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.incoming-data-unmatched">clin.incoming_data_unmatched</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lab-request">clin.lab_request</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2aoe">clin.lnk_code2aoe</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2episode">clin.lnk_code2episode</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2fhx">clin.lnk_code2fhx</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2h-issue">clin.lnk_code2h_issue</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2narrative">clin.lnk_code2narrative</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2procedure">clin.lnk_code2procedure</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2rfe">clin.lnk_code2rfe</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-code2tst-pnl">clin.lnk_code2tst_pnl</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-constraint2vacc-course">clin.lnk_constraint2vacc_course</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-pat2vaccination-course">clin.lnk_pat2vaccination_course</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-tst2norm">clin.lnk_tst2norm</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-type2item">clin.lnk_type2item</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-vaccination-course2schedule">clin.lnk_vaccination_course2schedule</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.lnk-vaccine2inds">clin.lnk_vaccine2inds</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.patient">clin.patient</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.procedure">clin.procedure</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.review-root">clin.review_root</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.reviewed-test-results">clin.reviewed_test_results</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.substance-intake">clin.substance_intake</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.suppressed-hint">clin.suppressed_hint</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.test-org">clin.test_org</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.test-panel">clin.test_panel</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.test-result">clin.test_result</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.test-type">clin.test_type</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.vacc-indication">clin.vacc_indication</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.vacc-route">clin.vacc_route</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.vaccination">clin.vaccination</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.vaccination-course">clin.vaccination_course</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.vaccination-course-constraint">clin.vaccination_course_constraint</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.vaccination-definition">clin.vaccination_definition</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.vaccination-schedule">clin.vaccination_schedule</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.vaccine">clin.vaccine</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.vaccine-batches">clin.vaccine_batches</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#clin.table.waiting-list">clin.waiting_list</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#de-de.table.beh-fall-typ">de_de.beh_fall_typ</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#de-de.table.lab-test-gnr">de_de.lab_test_gnr</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#de-de.table.prax-geb-paid">de_de.prax_geb_paid</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.address">dem.address</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.gender-label">dem.gender_label</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.identity">dem.identity</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.identity-tag">dem.identity_tag</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.inbox-item-category">dem.inbox_item_category</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.inbox-item-type">dem.inbox_item_type</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.lnk-identity2ext-id">dem.lnk_identity2ext_id</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.lnk-job2person">dem.lnk_job2person</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.lnk-org-unit2comm">dem.lnk_org_unit2comm</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.lnk-org-unit2ext-id">dem.lnk_org_unit2ext_id</a></li>
+			</ul>
+		
+			<ul>
 				<li><a href="gnumed-entire_schema.html#dem.table.lnk-person2relative">dem.lnk_person2relative</a></li>
 			</ul>
 		
 			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.message-inbox">dem.message_inbox</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.occupation">dem.occupation</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.org">dem.org</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.org-unit">dem.org_unit</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.praxis-branch">dem.praxis_branch</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.region">dem.region</a></li>
+			</ul>
+		
+			<ul>
 				<li><a href="gnumed-entire_schema.html#dem.table.relation-types">dem.relation_types</a></li>
 			</ul>
 		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.street">dem.street</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#dem.table.urb">dem.urb</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#gm.table.access-log">gm.access_log</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#ref.table.auto-hint">ref.auto_hint</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#ref.table.branded-drug">ref.branded_drug</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#ref.table.consumable-substance">ref.consumable_substance</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#ref.table.data-source">ref.data_source</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#ref.table.keyword-expansion">ref.keyword_expansion</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#ref.table.lnk-substance2brand">ref.lnk_substance2brand</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#ref.table.paperwork-templates">ref.paperwork_templates</a></li>
+			</ul>
+		
+			<ul>
+				<li><a href="gnumed-entire_schema.html#ref.table.tag-image">ref.tag_image</a></li>
+			</ul>
+		
 		
 
     <!-- Indexes -->
@@ -97192,16 +115845,15 @@ FROM dem.lnk_person_org_address;</pre>
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.staff">staff</a>
+			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.street">street</a>
 		</h2>
         
-         <p>one-to-one mapping of database user accounts
-	 (db_user) to staff identities (fk_identity)</p>
+         <p>street names, specific for distinct "urbs"</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>dem.staff Structure</caption>
+                <caption>dem.street Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -97260,11 +115912,19 @@ FROM dem.lnk_person_org_address;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -97279,7 +115939,7 @@ FROM dem.lnk_person_org_address;</pre>
                   
                 
                 </td>
-            	<td>pk</td>
+            	<td>id</td>
             	<td>serial</td>
                 <td><i>
 				
@@ -97300,11 +115960,13 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                   
-                  <a href="gnumed-entire_schema.html#dem.table.identity">dem.identity.pk</a>
+                  <a href="gnumed-entire_schema.html#dem.table.urb">dem.urb.id</a>
+                  
+                
                   
                 
                 </td>
-            	<td>fk_identity</td>
+            	<td>id_urb</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -97312,11 +115974,17 @@ FROM dem.lnk_person_org_address;</pre>
 
 					
 				
+					
+
+					
+                       UNIQUE#1
+                    
+				
 
 				NOT NULL
 				
 				</i>
-				
+				<br><br>reference to information postcode, city, country and region
 				</td>
 			 </tr>
             
@@ -97326,21 +115994,21 @@ FROM dem.lnk_person_org_address;</pre>
                   
                 
                 </td>
-            	<td>db_user</td>
             	<td>name</td>
+            	<td>text</td>
                 <td><i>
 				
 					
 
 					
-                       UNIQUE
+                       UNIQUE#1
                     
 				
 
 				NOT NULL
-				DEFAULT "current_user"()
-				</i>
 				
+				</i>
+				<br><br>name of this street
 				</td>
 			 </tr>
             
@@ -97350,23 +116018,21 @@ FROM dem.lnk_person_org_address;</pre>
                   
                 
                 </td>
-            	<td>short_alias</td>
+            	<td>postcode</td>
             	<td>text</td>
                 <td><i>
 				
 					
 
 					
-                       UNIQUE
+                       UNIQUE#1
                     
 				
 
-				NOT NULL
+				
 				
 				</i>
-				<br><br>a short signature unique to this staff member
-	 to be used in the GUI, actually this is somewhat
-	 redundant with ext_person_id...
+				<br><br>postcode for systems (such as UK Royal Mail) which specify the street
 				</td>
 			 </tr>
             
@@ -97374,7 +116040,7 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                 </td>
-            	<td>comment</td>
+            	<td>suburb</td>
             	<td>text</td>
                 <td><i>
 				
@@ -97382,7 +116048,7 @@ FROM dem.lnk_person_org_address;</pre>
 				
 				
 				</i>
-				
+				<br><br>the suburb this street is in (if any)
 				</td>
 			 </tr>
             
@@ -97390,15 +116056,15 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                 </td>
-            	<td>is_active</td>
-            	<td>boolean</td>
+            	<td>lat_lon</td>
+            	<td>point</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT true
-				</i>
 				
+				
+				</i>
+				<br><br>the approximate location of the street, as lat/long co-ordinates
 				</td>
 			 </tr>
             
@@ -97406,7 +116072,7 @@ FROM dem.lnk_person_org_address;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table dem.staff Inherits
+        <p>Table dem.street Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
@@ -97420,55 +116086,46 @@ FROM dem.lnk_person_org_address;</pre>
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>dem.street Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
+				<td>no_linebreaks</td>
+                <td>CHECK ((((("position"(((COALESCE(postcode, ''::text) || COALESCE(suburb, ''::text)) || COALESCE(name, ''::text)), '
'::text) = 0) AND ("position"(((COALESCE(postcode, ''::text) || COALESCE(suburb, ''::text)) || COALESCE(name, ''::text)), '
+'::text) = 0)) AND ("position"(((COALESCE(postcode, ''::text) || COALESCE(suburb, ''::text)) || COALESCE(name, ''::text)), '
'::text) = 0)) AND ("position"(((COALESCE(postcode, ''::text) || COALESCE(suburb, ''::text)) || COALESCE(name, ''::text)), '
'::text) = 0)))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
 			<p>Tables referencing this one via Foreign Key Constraints:</p>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#bill.table.bill-item">bill.bill_item</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#blobs.table.doc-obj">blobs.doc_obj</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.incoming-data-unmatched">clin.incoming_data_unmatched</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.review-root">clin.review_root</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.reviewed-test-results">clin.reviewed_test_results</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.test-result">clin.test_result</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#clin.table.vaccination">clin.vaccination</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#dem.table.identity">dem.identity</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#dem.table.message-inbox">dem.message_inbox</a></li>
-			</ul>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#ref.table.keyword-expansion">ref.keyword_expansion</a></li>
+				<li><a href="gnumed-entire_schema.html#dem.table.address">dem.address</a></li>
 			</ul>
 		
 		
 
     <!-- Indexes -->
     
+       idx_dem_street_id_urb id_urb
+    
+       idx_street_names name
+    
+       idx_street_zips postcode
+    
 
 	<!-- View Definition -->
 	
@@ -97484,17 +116141,15 @@ FROM dem.lnk_person_org_address;</pre>
         <hr>
 		<h2>Table:
 			
-			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.state">state</a>
+			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.urb">urb</a>
 		</h2>
         
-         <p>state codes (country specific);
-	 Richard agreed we should require pre-existence,
-	 allow user to mail details for adding a state to developers</p>
+         <p>cities, towns, dwellings ..., eg. "official" places of residence</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>dem.state Structure</caption>
+                <caption>dem.urb Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -97553,11 +116208,19 @@ FROM dem.lnk_person_org_address;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -97593,15 +116256,23 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                   
+                  <a href="gnumed-entire_schema.html#dem.table.region">dem.region.pk</a>
+                  
+                
+                  
                 
                 </td>
-            	<td>code</td>
-            	<td>text</td>
+            	<td>fk_region</td>
+            	<td>integer</td>
                 <td><i>
 				
 					
 
 					
+				
+					
+
+					
                        UNIQUE#1
                     
 				
@@ -97609,7 +116280,7 @@ FROM dem.lnk_person_org_address;</pre>
 				NOT NULL
 				
 				</i>
-				<br><br>state code
+				<br><br>reference to information about country and region
 				</td>
 			 </tr>
             
@@ -97618,13 +116289,9 @@ FROM dem.lnk_person_org_address;</pre>
                 
                   
                 
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.country">dem.country.code</a>
-                  
-                
                 </td>
-            	<td>country</td>
-            	<td>character(2)</td>
+            	<td>postcode</td>
+            	<td>text</td>
                 <td><i>
 				
 					
@@ -97633,15 +116300,13 @@ FROM dem.lnk_person_org_address;</pre>
                        UNIQUE#1
                     
 				
-					
-
-					
-				
 
 				NOT NULL
 				
 				</i>
-				<br><br>2 character ISO 3166-1 country code
+				<br><br>default postcode for urb.name,
+	 useful for all the smaller urbs that only have one postcode,
+	 also useful as a default when adding new streets to an urb
 				</td>
 			 </tr>
             
@@ -97649,15 +116314,39 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                 </td>
+            	<td>lat_lon</td>
+            	<td>point</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				<br><br>the location of the urb, as lat/long co-ordinates. Ideally this would be NOT NULL
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                  
+                
+                </td>
             	<td>name</td>
             	<td>text</td>
                 <td><i>
 				
+					
+
+					
+                       UNIQUE#1
+                    
+				
 
 				NOT NULL
 				
 				</i>
-				
+				<br><br>the name of the city/town/dwelling
 				</td>
 			 </tr>
             
@@ -97665,7 +116354,7 @@ FROM dem.lnk_person_org_address;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table dem.state Inherits
+        <p>Table dem.urb Inherits
         
             
            <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
@@ -97681,16 +116370,21 @@ FROM dem.lnk_person_org_address;</pre>
 		
         <p> </p>
 		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>dem.state Constraints</caption>
+            <caption>dem.urb Constraints</caption>
             <tr>
             	<th>Name</th>
             	<th>Constraint</th>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>no_linebreaks</td>
-                <td>CHECK ((((("position"(((COALESCE(code, ''::text) || (COALESCE(country, ''::bpchar))::text) || COALESCE(name, ''::text)), '
'::text) = 0) AND ("position"(((COALESCE(code, ''::text) || (COALESCE(country, ''::bpchar))::text) || COALESCE(name, ''::text)), '
-'::text) = 0)) AND ("position"(((COALESCE(code, ''::text) || (COALESCE(country, ''::bpchar))::text) || COALESCE(name, ''::text)), '
'::text) = 0)) AND ("position"(((COALESCE(code, ''::text) || (COALESCE(country, ''::bpchar))::text) || COALESCE(name, ''::text)), '
'::text) = 0)))</td>
+                <td>CHECK ((((("position"((COALESCE(postcode, ''::text) || COALESCE(name, ''::text)), '
'::text) = 0) AND ("position"((COALESCE(postcode, ''::text) || COALESCE(name, ''::text)), '
+'::text) = 0)) AND ("position"((COALESCE(postcode, ''::text) || COALESCE(name, ''::text)), '
'::text) = 0)) AND ("position"((COALESCE(postcode, ''::text) || COALESCE(name, ''::text)), '
'::text) = 0)))</td>
             </tr>
 			
 		</table>
@@ -97701,16 +116395,18 @@ FROM dem.lnk_person_org_address;</pre>
 			<p>Tables referencing this one via Foreign Key Constraints:</p>
 		
 			<ul>
-				<li><a href="gnumed-entire_schema.html#dem.table.urb">dem.urb</a></li>
+				<li><a href="gnumed-entire_schema.html#dem.table.street">dem.street</a></li>
 			</ul>
 		
 		
 
     <!-- Indexes -->
     
-       idx_dem_state_country_code country
+       idx_dem_urb_id_state fk_region
     
-       idx_state_names name
+       idx_urb_names name
+    
+       idx_urb_zips postcode
     
 
 	<!-- View Definition -->
@@ -97725,17 +116421,17 @@ FROM dem.lnk_person_org_address;</pre>
     </p>
 	
         <hr>
-		<h2>Table:
+		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.street">street</a>
+			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.view.v-active-persons">v_active_persons</a>
 		</h2>
         
-         <p>street names, specific for distinct "urbs"</p>
+         <p>This view denormalizes non-deleted persons with their active name.</p>
         
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>dem.street Structure</caption>
+                <caption>dem.v_active_persons Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -97747,13 +116443,13 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
+            	<td>pk_identity</td>
             	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -97763,12 +116459,12 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>title</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -97779,13 +116475,77 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>firstnames</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>preferred</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>lastnames</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>gender</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>l10n_gender</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -97795,13 +116555,13 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>dob_only</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -97810,18 +116570,11 @@ FROM dem.lnk_person_org_address;</pre>
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>id</td>
-            	<td>serial</td>
+            	<td>dob</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -97833,80 +116586,48 @@ FROM dem.lnk_person_org_address;</pre>
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.urb">dem.urb.id</a>
-                  
-                
-                  
-                
                 </td>
-            	<td>id_urb</td>
-            	<td>integer</td>
+            	<td>tob</td>
+            	<td>time without time zone</td>
                 <td><i>
 				
-					
-
-					
-				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>reference to information postcode, city, country and state
+				
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>name</td>
-            	<td>text</td>
+            	<td>deceased</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>name of this street
+				
 				</td>
 			 </tr>
             
             <tr class="tr1">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>postcode</td>
+            	<td>marital_status</td>
             	<td>text</td>
                 <td><i>
 				
-					
-
-					
-                       UNIQUE#1
-                    
-				
 
 				
 				
 				</i>
-				<br><br>postcode for systems (such as UK Royal Mail) which specify the street
+				
 				</td>
 			 </tr>
             
@@ -97914,7 +116635,7 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                 </td>
-            	<td>suburb</td>
+            	<td>l10n_marital_status</td>
             	<td>text</td>
                 <td><i>
 				
@@ -97922,7 +116643,7 @@ FROM dem.lnk_person_org_address;</pre>
 				
 				
 				</i>
-				<br><br>the suburb this street is in (if any)
+				
 				</td>
 			 </tr>
             
@@ -97930,113 +116651,29 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                 </td>
-            	<td>lat_lon</td>
-            	<td>point</td>
+            	<td>emergency_contact</td>
+            	<td>text</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>the approximate location of the street, as lat/long co-ordinates
+				
 				</td>
 			 </tr>
             
-        </table>
-
-        <!-- Inherits -->
-		
-        <p>Table dem.street Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
-
-		
-		
-		
-
-        <!-- Constraint List -->
-		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>dem.street Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>no_linebreaks</td>
-                <td>CHECK ((((("position"(((COALESCE(postcode, ''::text) || COALESCE(suburb, ''::text)) || COALESCE(name, ''::text)), '
'::text) = 0) AND ("position"(((COALESCE(postcode, ''::text) || COALESCE(suburb, ''::text)) || COALESCE(name, ''::text)), '
-'::text) = 0)) AND ("position"(((COALESCE(postcode, ''::text) || COALESCE(suburb, ''::text)) || COALESCE(name, ''::text)), '
'::text) = 0)) AND ("position"(((COALESCE(postcode, ''::text) || COALESCE(suburb, ''::text)) || COALESCE(name, ''::text)), '
'::text) = 0)))</td>
-            </tr>
-			
-		</table>
-		
-
-        <!-- Foreign Key Discovery -->
-		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#dem.table.address">dem.address</a></li>
-			</ul>
-		
-		
-
-    <!-- Indexes -->
-    
-       idx_dem_street_id_urb id_urb
-    
-       idx_street_names name
-    
-       idx_street_zips postcode
-    
-
-	<!-- View Definition -->
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#dem.schema">Schema dem</a>
-    </p>
-	
-        <hr>
-		<h2>Table:
-			
-			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.table.urb">urb</a>
-		</h2>
-        
-         <p>cities, towns, dwellings ..., eg. "official" places of residence</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>dem.urb Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
             <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>pk_audit</td>
-            	<td>integer</td>
+            	<td>comment</td>
+            	<td>text</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
+				
+				
 				</i>
 				
 				</td>
@@ -98046,12 +116683,12 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                 </td>
-            	<td>row_version</td>
-            	<td>integer</td>
+            	<td>is_deleted</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
-				NOT NULL
+				
 				
 				</i>
 				
@@ -98062,13 +116699,13 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                 </td>
-            	<td>modified_when</td>
-            	<td>timestamp with time zone</td>
+            	<td>pk_marital_status</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT now()
+				
+				
 				</i>
 				
 				</td>
@@ -98078,13 +116715,13 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                 </td>
-            	<td>modified_by</td>
-            	<td>name</td>
+            	<td>pk_active_name</td>
+            	<td>integer</td>
                 <td><i>
 				
 
-				NOT NULL
-				DEFAULT "current_user"()
+				
+				
 				</i>
 				
 				</td>
@@ -98093,18 +116730,11 @@ FROM dem.lnk_person_org_address;</pre>
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>id</td>
-            	<td>serial</td>
+            	<td>pk_emergency_contact</td>
+            	<td>integer</td>
                 <td><i>
 				
-					PRIMARY KEY
-					
-
-					
-				
 
 				
 				
@@ -98116,58 +116746,32 @@ FROM dem.lnk_person_org_address;</pre>
             <tr class="tr1">
 				<td>
                 
-                  
-                  <a href="gnumed-entire_schema.html#dem.table.state">dem.state.id</a>
-                  
-                
-                  
-                
                 </td>
-            	<td>id_state</td>
+            	<td>pk_primary_provider</td>
             	<td>integer</td>
                 <td><i>
 				
-					
-
-					
-				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>reference to information about country and state
+				
 				</td>
 			 </tr>
             
             <tr class="tr0">
 				<td>
                 
-                  
-                
                 </td>
-            	<td>postcode</td>
-            	<td>text</td>
+            	<td>xmin_identity</td>
+            	<td>xid</td>
                 <td><i>
 				
-					
 
-					
-                       UNIQUE#1
-                    
 				
-
-				NOT NULL
 				
 				</i>
-				<br><br>default postcode for urb.name,
-	 useful for all the smaller urbs that only have one postcode,
-	 also useful as a default when adding new streets to an urb
+				
 				</td>
 			 </tr>
             
@@ -98175,39 +116779,15 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                 </td>
-            	<td>lat_lon</td>
-            	<td>point</td>
+            	<td>dob_is_estimated</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
 				
 				
 				</i>
-				<br><br>the location of the urb, as lat/long co-ordinates. Ideally this would be NOT NULL
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                  
-                
-                </td>
-            	<td>name</td>
-            	<td>text</td>
-                <td><i>
 				
-					
-
-					
-                       UNIQUE#1
-                    
-				
-
-				NOT NULL
-				
-				</i>
-				<br><br>the name of the city/town/dwelling
 				</td>
 			 </tr>
             
@@ -98215,58 +116795,69 @@ FROM dem.lnk_person_org_address;</pre>
 
         <!-- Inherits -->
 		
-        <p>Table dem.urb Inherits
-        
-            
-           <a href="gnumed-entire_schema.html#audit.table.audit-fields">audit_fields</a>, 
-        
-        </p>
-		
 
 		
-		
-		
 
         <!-- Constraint List -->
 		
-        <p> </p>
-		<table width="100%" cellspacing="0" cellpadding="3">
-            <caption>dem.urb Constraints</caption>
-            <tr>
-            	<th>Name</th>
-            	<th>Constraint</th>
-            </tr>
-			
-            <tr class="tr0">
-				<td>no_linebreaks</td>
-                <td>CHECK ((((("position"((COALESCE(postcode, ''::text) || COALESCE(name, ''::text)), '
'::text) = 0) AND ("position"((COALESCE(postcode, ''::text) || COALESCE(name, ''::text)), '
-'::text) = 0)) AND ("position"((COALESCE(postcode, ''::text) || COALESCE(name, ''::text)), '
'::text) = 0)) AND ("position"((COALESCE(postcode, ''::text) || COALESCE(name, ''::text)), '
'::text) = 0)))</td>
-            </tr>
-			
-		</table>
-		
 
         <!-- Foreign Key Discovery -->
 		
-			<p>Tables referencing this one via Foreign Key Constraints:</p>
-		
-			<ul>
-				<li><a href="gnumed-entire_schema.html#dem.table.street">dem.street</a></li>
-			</ul>
-		
-		
 
     <!-- Indexes -->
     
-       idx_dem_urb_id_state id_state
-    
-       idx_urb_names name
-    
-       idx_urb_zips postcode
-    
 
 	<!-- View Definition -->
 	
+	<pre>
+SELECT d_vp.pk_identity
+,
+    d_vp.title
+,
+    d_vp.firstnames
+,
+    d_vp.preferred
+,
+    d_vp.lastnames
+,
+    d_vp.gender
+,
+    d_vp.l10n_gender
+,
+    d_vp.dob_only
+,
+    d_vp.dob
+,
+    d_vp.tob
+,
+    d_vp.deceased
+,
+    d_vp.marital_status
+,
+    d_vp.l10n_marital_status
+,
+    d_vp.emergency_contact
+,
+    d_vp.comment
+,
+    d_vp.is_deleted
+,
+    d_vp.pk_marital_status
+,
+    d_vp.pk_active_name
+,
+    d_vp.pk_emergency_contact
+,
+    d_vp.pk_primary_provider
+,
+    d_vp.xmin_identity
+,
+    d_vp.dob_is_estimated
+   
+FROM dem.v_all_persons d_vp
+  
+WHERE (d_vp.is_deleted IS FALSE);</pre>
+	
 
 	<!-- List off permissions -->
 	
@@ -98523,7 +117114,7 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                 </td>
-            	<td>code_state</td>
+            	<td>code_region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -98539,7 +117130,7 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                 </td>
-            	<td>state</td>
+            	<td>region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -98555,7 +117146,7 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                 </td>
-            	<td>l10n_state</td>
+            	<td>l10n_region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -98667,7 +117258,7 @@ FROM dem.lnk_person_org_address;</pre>
 				<td>
                 
                 </td>
-            	<td>pk_state</td>
+            	<td>pk_region</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -98714,58 +117305,87 @@ FROM dem.lnk_person_org_address;</pre>
 	<!-- View Definition -->
 	
 	<pre>
-SELECT adr.id AS pk_address
-, str.name AS street
-, COALESCE
-(str.postcode
-     , u.postcode
+SELECT d_adr.id AS pk_address
+,
+    d_str.name AS street
+,
+    COALESCE
+(d_str.postcode
+     , d_u.postcode
 ) AS postcode
-, adr.aux_street AS notes_street
-, adr.number
-, adr.subunit
-, adr.addendum AS notes_subunit
-, adr.lat_lon AS lat_lon_address
-, str.postcode AS postcode_street
-, str.lat_lon AS lat_lon_street
-, str.suburb
-, u.name AS urb
-, u.postcode AS postcode_urb
-, u.lat_lon AS lat_lon_urb
-, dst.code AS code_state
-, dst.name AS state
-, _
-(dst.name) AS l10n_state
-, dst.country AS code_country
-, c.name AS country
-, _
-(c.name) AS l10n_country
-, c.deprecated AS country_deprecated
-, adr.id_street AS pk_street
-, u.id AS pk_urb
-, dst.id AS pk_state
-, adr.xmin AS xmin_address 
+,
+    d_adr.aux_street AS notes_street
+,
+    d_adr.number
+,
+    d_adr.subunit
+,
+    d_adr.addendum AS notes_subunit
+,
+    d_adr.lat_lon AS lat_lon_address
+,
+    d_str.postcode AS postcode_street
+,
+    d_str.lat_lon AS lat_lon_street
+,
+    d_str.suburb
+,
+    d_u.name AS urb
+,
+    d_u.postcode AS postcode_urb
+,
+    d_u.lat_lon AS lat_lon_urb
+,
+    d_r.code AS code_region
+,
+    d_r.name AS region
+,
+    _
+(d_r.name) AS l10n_region
+,
+    d_r.country AS code_country
+,
+    d_c.name AS country
+,
+    _
+(d_c.name) AS l10n_country
+,
+    d_c.deprecated AS country_deprecated
+,
+    d_adr.id_street AS pk_street
+,
+    d_u.id AS pk_urb
+,
+    d_r.pk AS pk_region
+,
+    d_adr.xmin AS xmin_address
+   
 FROM (
      (
            (
-                 (dem.address adr 
-               LEFT JOIN dem.street str 
+                 (dem.address d_adr
+     
+               LEFT JOIN dem.street d_str 
                       ON (
-                             (adr.id_street = str.id)
+                             (d_adr.id_street = d_str.id)
                        )
                  )
-         LEFT JOIN dem.urb u 
+     
+         LEFT JOIN dem.urb d_u 
                 ON (
-                       (str.id_urb = u.id)
+                       (d_str.id_urb = d_u.id)
                  )
            )
-   LEFT JOIN dem.state dst 
+     
+   LEFT JOIN dem.region d_r 
           ON (
-                 (u.id_state = dst.id)
+                 (d_u.fk_region = d_r.pk)
            )
      )
-LEFT JOIN dem.country c 
+     
+LEFT JOIN dem.country d_c 
     ON (
-           (c.code = dst.country)
+           (d_c.code = d_r.country)
      )
 );</pre>
 	
@@ -98781,13 +117401,15 @@ LEFT JOIN dem.country c
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.view.v-basic-address">v_basic_address</a>
+			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.view.v-all-persons">v_all_persons</a>
 		</h2>
         
+         <p>This view denormalizes persons with their active name.</p>
+        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>dem.v_basic_address Structure</caption>
+                <caption>dem.v_all_persons Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -98799,7 +117421,7 @@ LEFT JOIN dem.country c
 				<td>
                 
                 </td>
-            	<td>id</td>
+            	<td>pk_identity</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -98815,8 +117437,8 @@ LEFT JOIN dem.country c
 				<td>
                 
                 </td>
-            	<td>country_code</td>
-            	<td>character(2)</td>
+            	<td>title</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -98831,7 +117453,7 @@ LEFT JOIN dem.country c
 				<td>
                 
                 </td>
-            	<td>state_code</td>
+            	<td>firstnames</td>
             	<td>text</td>
                 <td><i>
 				
@@ -98847,7 +117469,7 @@ LEFT JOIN dem.country c
 				<td>
                 
                 </td>
-            	<td>state</td>
+            	<td>preferred</td>
             	<td>text</td>
                 <td><i>
 				
@@ -98863,7 +117485,7 @@ LEFT JOIN dem.country c
 				<td>
                 
                 </td>
-            	<td>country</td>
+            	<td>lastnames</td>
             	<td>text</td>
                 <td><i>
 				
@@ -98879,7 +117501,7 @@ LEFT JOIN dem.country c
 				<td>
                 
                 </td>
-            	<td>postcode</td>
+            	<td>gender</td>
             	<td>text</td>
                 <td><i>
 				
@@ -98895,7 +117517,7 @@ LEFT JOIN dem.country c
 				<td>
                 
                 </td>
-            	<td>urb</td>
+            	<td>l10n_gender</td>
             	<td>text</td>
                 <td><i>
 				
@@ -98911,7 +117533,71 @@ LEFT JOIN dem.country c
 				<td>
                 
                 </td>
-            	<td>number</td>
+            	<td>dob_only</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>dob</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>tob</td>
+            	<td>time without time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>deceased</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>marital_status</td>
             	<td>text</td>
                 <td><i>
 				
@@ -98927,7 +117613,7 @@ LEFT JOIN dem.country c
 				<td>
                 
                 </td>
-            	<td>street</td>
+            	<td>l10n_marital_status</td>
             	<td>text</td>
                 <td><i>
 				
@@ -98943,7 +117629,7 @@ LEFT JOIN dem.country c
 				<td>
                 
                 </td>
-            	<td>addendum</td>
+            	<td>emergency_contact</td>
             	<td>text</td>
                 <td><i>
 				
@@ -98959,8 +117645,120 @@ LEFT JOIN dem.country c
 				<td>
                 
                 </td>
-            	<td>lat_lon</td>
-            	<td>point</td>
+            	<td>comment</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>is_deleted</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_marital_status</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_active_name</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_emergency_contact</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_primary_provider</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>xmin_identity</td>
+            	<td>xid</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>dob_is_estimated</td>
+            	<td>boolean</td>
                 <td><i>
 				
 
@@ -98990,38 +117788,85 @@ LEFT JOIN dem.country c
 	<!-- View Definition -->
 	
 	<pre>
-SELECT adr.id
-, s.country AS country_code
-, s.code AS state_code
-, s.name AS state
-, c.name AS country
-, COALESCE
-(str.postcode
-     , urb.postcode
-) AS postcode
-, urb.name AS urb
-, adr.number
-, str.name AS street
-, adr.addendum
-, COALESCE
-(adr.lat_lon
-     , str.lat_lon
-     , urb.lat_lon
-) AS lat_lon 
-FROM dem.address adr
-, dem.state s
-, dem.country c
-, dem.urb
-, dem.street str 
-WHERE (
-     (
-           (
-                 (s.country = c.code)
-               AND (adr.id_street = str.id)
+SELECT d_i.pk AS pk_identity
+,
+    d_i.title
+,
+    d_n.firstnames
+,
+    d_n.preferred
+,
+    d_n.lastnames
+,
+    d_i.gender
+,
+    _
+(d_i.gender) AS l10n_gender
+,
+    d_i.dob AS dob_only
+,
+    
+(date_trunc
+     ('day'::text
+           , d_i.dob
+     ) + 
+     (COALESCE
+           (d_i.tob
+                 , (d_i.dob)::time without time zone
            )
-         AND (str.id_urb = urb.id)
+     )::interval
+) AS dob
+,
+    d_i.tob
+,
+    d_i.deceased
+,
+    COALESCE
+(d_ms.name
+     ,'unknown'::text
+) AS marital_status
+,
+    _
+(COALESCE
+     (d_ms.name
+           ,'unknown'::text
+     )
+) AS l10n_marital_status
+,
+    d_i.emergency_contact
+,
+    d_i.comment
+,
+    d_i.deleted AS is_deleted
+,
+    d_i.fk_marital_status AS pk_marital_status
+,
+    d_n.id AS pk_active_name
+,
+    d_i.fk_emergency_contact AS pk_emergency_contact
+,
+    d_i.fk_primary_provider AS pk_primary_provider
+,
+    d_i.xmin AS xmin_identity
+,
+    d_i.dob_is_estimated
+   
+FROM (
+     (dem.identity d_i
+     
+        JOIN dem.names d_n 
+          ON (
+                 (
+                       (d_n.id_identity = d_i.pk)
+                     AND (d_n.active IS TRUE)
+                 )
+           )
+     )
+     
+LEFT JOIN dem.marital_status d_ms 
+    ON (
+           (d_i.fk_marital_status = d_ms.pk)
      )
-   AND (urb.id_state = s.id)
 );</pre>
 	
 
@@ -99036,15 +117881,13 @@ WHERE (
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.view.v-basic-person">v_basic_person</a>
+			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.view.v-basic-address">v_basic_address</a>
 		</h2>
         
-         <p>This view denormalizes non-deleted persons with their active name.</p>
-        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>dem.v_basic_person Structure</caption>
+                <caption>dem.v_basic_address Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -99056,7 +117899,7 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_identity</td>
+            	<td>id</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -99072,7 +117915,39 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>title</td>
+            	<td>country_code</td>
+            	<td>character(2)</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>region_code</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -99088,7 +117963,7 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>firstnames</td>
+            	<td>country</td>
             	<td>text</td>
                 <td><i>
 				
@@ -99104,7 +117979,7 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>preferred</td>
+            	<td>postcode</td>
             	<td>text</td>
                 <td><i>
 				
@@ -99120,7 +117995,7 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>lastnames</td>
+            	<td>urb</td>
             	<td>text</td>
                 <td><i>
 				
@@ -99136,7 +118011,7 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>gender</td>
+            	<td>number</td>
             	<td>text</td>
                 <td><i>
 				
@@ -99152,7 +118027,7 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>l10n_gender</td>
+            	<td>street</td>
             	<td>text</td>
                 <td><i>
 				
@@ -99168,8 +118043,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>dob_only</td>
-            	<td>timestamp with time zone</td>
+            	<td>addendum</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -99184,8 +118059,121 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>dob</td>
-            	<td>timestamp with time zone</td>
+            	<td>lat_lon</td>
+            	<td>point</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT d_adr.id
+,
+    d_r.country AS country_code
+,
+    d_r.code AS region_code
+,
+    d_r.name AS region
+,
+    d_c.name AS country
+,
+    COALESCE
+(d_str.postcode
+     , d_u.postcode
+) AS postcode
+,
+    d_u.name AS urb
+,
+    d_adr.number
+,
+    d_str.name AS street
+,
+    d_adr.addendum
+,
+    COALESCE
+(d_adr.lat_lon
+     , d_str.lat_lon
+     , d_u.lat_lon
+) AS lat_lon
+   
+FROM dem.address d_adr
+,
+    dem.region d_r
+,
+    dem.country d_c
+,
+    dem.urb d_u
+,
+    dem.street d_str
+  
+WHERE (
+     (
+           (
+                 (d_r.country = d_c.code)
+               AND (d_adr.id_street = d_str.id)
+           )
+         AND (d_str.id_urb = d_u.id)
+     )
+   AND (d_u.fk_region = d_r.pk)
+);</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#dem.schema">Schema dem</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.view.v-deleted-persons">v_deleted_persons</a>
+		</h2>
+        
+         <p>This view denormalizes "deleted" persons with their active name.</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>dem.v_deleted_persons Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_identity</td>
+            	<td>integer</td>
                 <td><i>
 				
 
@@ -99200,8 +118188,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>tob</td>
-            	<td>time without time zone</td>
+            	<td>title</td>
+            	<td>text</td>
                 <td><i>
 				
 
@@ -99216,7 +118204,103 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>deceased</td>
+            	<td>firstnames</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>preferred</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>lastnames</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>gender</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>l10n_gender</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>dob_only</td>
+            	<td>timestamp with time zone</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>dob</td>
             	<td>timestamp with time zone</td>
                 <td><i>
 				
@@ -99232,8 +118316,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>cob</td>
-            	<td>character(2)</td>
+            	<td>tob</td>
+            	<td>time without time zone</td>
                 <td><i>
 				
 
@@ -99248,8 +118332,8 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pupic</td>
-            	<td>character(24)</td>
+            	<td>deceased</td>
+            	<td>timestamp with time zone</td>
                 <td><i>
 				
 
@@ -99328,6 +118412,22 @@ WHERE (
 				<td>
                 
                 </td>
+            	<td>is_deleted</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
             	<td>pk_marital_status</td>
             	<td>integer</td>
                 <td><i>
@@ -99340,7 +118440,7 @@ WHERE (
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -99356,7 +118456,7 @@ WHERE (
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -99372,7 +118472,7 @@ WHERE (
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -99388,7 +118488,7 @@ WHERE (
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -99404,7 +118504,7 @@ WHERE (
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -99439,70 +118539,53 @@ WHERE (
 	<!-- View Definition -->
 	
 	<pre>
-SELECT i.pk AS pk_identity
-, i.title
-, n.firstnames
-, n.preferred
-, n.lastnames
-, i.gender
-, _
-(i.gender) AS l10n_gender
-, i.dob AS dob_only
-, (date_trunc
-     ('day'::text
-           , i.dob
-     ) + 
-     (COALESCE
-           (i.tob
-                 , (i.dob)::time without time zone
-           )
-     )::interval
-) AS dob
-, i.tob
-, i.deceased
-, i.cob
-, i.pupic
-, CASE WHEN 
-(i.fk_marital_status IS NULL) THEN 'unknown'::text ELSE 
-(
-SELECT ms.name 
-  FROM dem.marital_status ms
-     , dem.identity i1 
- WHERE (
-           (ms.pk = i.fk_marital_status)
-         AND (i1.pk = i.pk)
-     )
-) END AS marital_status
-, CASE WHEN 
-(i.fk_marital_status IS NULL) THEN _
-('unknown'::text) ELSE 
-(
-SELECT _
-     (ms1.name) AS _ 
-  FROM dem.marital_status ms1
-     , dem.identity i1 
- WHERE (
-           (ms1.pk = i.fk_marital_status)
-         AND (i1.pk = i.pk)
-     )
-) END AS l10n_marital_status
-, i.emergency_contact
-, i.comment
-, i.fk_marital_status AS pk_marital_status
-, n.id AS pk_active_name
-, i.fk_emergency_contact AS pk_emergency_contact
-, i.fk_primary_provider AS pk_primary_provider
-, i.xmin AS xmin_identity
-, i.dob_is_estimated 
-FROM dem.identity i
-, dem.names n 
-WHERE (
-     (
-           (i.deleted IS FALSE)
-         AND (n.active IS TRUE)
-     )
-   AND (n.id_identity = i.pk)
-);</pre>
+SELECT d_vp.pk_identity
+,
+    d_vp.title
+,
+    d_vp.firstnames
+,
+    d_vp.preferred
+,
+    d_vp.lastnames
+,
+    d_vp.gender
+,
+    d_vp.l10n_gender
+,
+    d_vp.dob_only
+,
+    d_vp.dob
+,
+    d_vp.tob
+,
+    d_vp.deceased
+,
+    d_vp.marital_status
+,
+    d_vp.l10n_marital_status
+,
+    d_vp.emergency_contact
+,
+    d_vp.comment
+,
+    d_vp.is_deleted
+,
+    d_vp.pk_marital_status
+,
+    d_vp.pk_active_name
+,
+    d_vp.pk_emergency_contact
+,
+    d_vp.pk_primary_provider
+,
+    d_vp.xmin_identity
+,
+    d_vp.dob_is_estimated
+   
+FROM dem.v_all_persons d_vp
+  
+WHERE (d_vp.is_deleted IS TRUE);</pre>
 	
 
 	<!-- List off permissions -->
@@ -99662,14 +118745,23 @@ WHERE (
 	
 	<pre>
 SELECT li2ei.id_identity AS pk_identity
-, li2ei.id AS pk_id
-, eit.name
-, li2ei.external_id AS value
-, eit.issuer
-, li2ei.comment
-, li2ei.fk_origin AS pk_type 
+,
+    li2ei.id AS pk_id
+,
+    eit.name
+,
+    li2ei.external_id AS value
+,
+    eit.issuer
+,
+    li2ei.comment
+,
+    li2ei.fk_origin AS pk_type
+   
 FROM dem.lnk_identity2ext_id li2ei
-, dem.enum_ext_id_types eit 
+,
+    dem.enum_ext_id_types eit
+  
 WHERE (li2ei.fk_origin = eit.pk);</pre>
 	
 
@@ -99830,13 +118922,21 @@ WHERE (li2ei.fk_origin = eit.pk);</pre>
 	
 	<pre>
 SELECT d_lou2ei.fk_org_unit AS pk_org_unit
-, d_lou2ei.pk AS pk_id
-, d_eit.name
-, d_lou2ei.external_id AS value
-, d_eit.issuer
-, d_lou2ei.comment
-, d_lou2ei.fk_type AS pk_type 
-FROM (dem.lnk_org_unit2ext_id d_lou2ei 
+,
+    d_lou2ei.pk AS pk_id
+,
+    d_eit.name
+,
+    d_lou2ei.external_id AS value
+,
+    d_eit.issuer
+,
+    d_lou2ei.comment
+,
+    d_lou2ei.fk_type AS pk_type
+   
+FROM (dem.lnk_org_unit2ext_id d_lou2ei
+     
   JOIN dem.enum_ext_id_types d_eit 
     ON (
            (d_lou2ei.fk_type = d_eit.pk)
@@ -100001,14 +119101,21 @@ FROM (dem.lnk_org_unit2ext_id d_lou2ei
 	
 	<pre>
 SELECT gl.tag
-, _
+,
+    _
 (gl.tag) AS l10n_tag
-, gl.label
-, _
+,
+    gl.label
+,
+    _
 (gl.label) AS l10n_label
-, gl.comment
-, gl.sort_weight
-, gl.pk AS pk_gender_label 
+,
+    gl.comment
+,
+    gl.sort_weight
+,
+    gl.pk AS pk_gender_label
+   
 FROM dem.gender_label gl;</pre>
 	
 
@@ -100201,21 +119308,31 @@ FROM dem.gender_label gl;</pre>
 	
 	<pre>
 SELECT dit.fk_identity AS pk_identity
-, rti.description
-, _
+,
+    rti.description
+,
+    _
 (rti.description) AS l10n_description
-, dit.comment
-, rti.filename
-, octet_length
+,
+    dit.comment
+,
+    rti.filename
+,
+    octet_length
 (COALESCE
      (rti.image
            ,'\x'::bytea
      )
 ) AS image_size
-, dit.pk AS pk_identity_tag
-, rti.pk AS pk_tag_image
-, dit.xmin AS xmin_identity_tag 
-FROM (dem.identity_tag dit 
+,
+    dit.pk AS pk_identity_tag
+,
+    rti.pk AS pk_tag_image
+,
+    dit.xmin AS xmin_identity_tag
+   
+FROM (dem.identity_tag dit
+     
 LEFT JOIN ref.tag_image rti 
     ON (
            (dit.fk_tag = rti.pk)
@@ -100396,17 +119513,27 @@ LEFT JOIN ref.tag_image rti
 	
 	<pre>
 SELECT it.description AS type
-, _
+,
+    _
 (it.description) AS l10n_type
-, ic.description AS category
-, _
+,
+    ic.description AS category
+,
+    _
 (ic.description) AS l10n_category
-, it.is_user AS is_user_type
-, ic.is_user AS is_user_category
-, it.pk AS pk_type
-, it.fk_inbox_item_category AS pk_category 
+,
+    it.is_user AS is_user_type
+,
+    ic.is_user AS is_user_category
+,
+    it.pk AS pk_type
+,
+    it.fk_inbox_item_category AS pk_category
+   
 FROM dem.inbox_item_type it
-, dem.inbox_item_category ic 
+,
+    dem.inbox_item_category ic
+  
 WHERE (it.fk_inbox_item_category = ic.pk);</pre>
 	
 
@@ -100826,186 +119953,309 @@ Using UNION makes sure we get the right level of uniqueness.</p>
 	
 	<pre>
 (
+         
+SELECT mi.modified_when AS received_when
+     ,
+            COALESCE
      (
-      SELECT mi.modified_when AS received_when
-           , COALESCE
            (
-                 (
-                  SELECT staff.short_alias 
-                    FROM dem.staff 
-                   WHERE (staff.db_user = mi.modified_by)
-                 )
-                 , (
-                       ('<'::text || 
-                             (mi.modified_by)::text
-                       ) || '>'::text
-                 )
-           ) AS modified_by
+            SELECT staff.short_alias
+                   
+              FROM dem.staff
+                  
+             WHERE (staff.db_user = mi.modified_by)
+           )
            , (
-            SELECT staff.short_alias 
-              FROM dem.staff 
-             WHERE (staff.pk = mi.fk_staff)
-           ) AS provider
-           , mi.importance
-           , vit.category
-           , vit.l10n_category
-           , vit.type
-           , vit.l10n_type
-           , mi.comment
-           , mi.ufk_context AS pk_context
-           , mi.data
-           , mi.pk AS pk_inbox_message
-           , mi.fk_staff AS pk_staff
-           , vit.pk_category
-           , mi.fk_inbox_item_type AS pk_type
-           , mi.fk_patient AS pk_patient
-           , false AS is_virtual
-           , mi.due_date
-           , mi.expiry_date
-           , CASE WHEN 
-           (mi.due_date IS NULL) THEN false WHEN 
-           (mi.due_date > now
-                 ()
-           ) THEN false WHEN 
-           (mi.expiry_date IS NULL) THEN true WHEN 
-           (mi.expiry_date < now
-                 ()
-           ) THEN false ELSE true END AS is_overdue
-           , CASE WHEN 
-           (mi.expiry_date IS NULL) THEN false WHEN 
-           (mi.expiry_date > now
-                 ()
-           ) THEN false ELSE true END AS is_expired
-           , CASE WHEN 
-           (mi.due_date IS NULL) THEN NULL::interval WHEN 
-           (mi.due_date > now
-                 ()
-           ) THEN 
-           (
-                 (mi.due_date)::timestamp with time zone - now
-                 ()
-           ) ELSE 
-           (now
-                 () - 
-                 (mi.due_date)::timestamp with time zone
-           ) END AS interval_due
-           , gm.xid2int
-           (mi.xmin) AS xmin_message_inbox 
-        FROM dem.message_inbox mi
-           , dem.v_inbox_item_type vit 
-       WHERE (mi.fk_inbox_item_type = vit.pk_type)
-   UNION ALLSELECT v_unreviewed_docs_inbox.received_when
-           , v_unreviewed_docs_inbox.modified_by
-           , v_unreviewed_docs_inbox.provider
-           , v_unreviewed_docs_inbox.importance
-           , v_unreviewed_docs_inbox.category
-           , v_unreviewed_docs_inbox.l10n_category
-           , v_unreviewed_docs_inbox.type
-           , v_unreviewed_docs_inbox.l10n_type
-           , v_unreviewed_docs_inbox.comment
-           , v_unreviewed_docs_inbox.pk_context
-           , v_unreviewed_docs_inbox.data
-           , v_unreviewed_docs_inbox.pk_inbox_message
-           , v_unreviewed_docs_inbox.pk_staff
-           , v_unreviewed_docs_inbox.pk_category
-           , v_unreviewed_docs_inbox.pk_type
-           , v_unreviewed_docs_inbox.pk_patient
-           , v_unreviewed_docs_inbox.is_virtual
-           , v_unreviewed_docs_inbox.due_date
-           , v_unreviewed_docs_inbox.expiry_date
-           , v_unreviewed_docs_inbox.is_overdue
-           , v_unreviewed_docs_inbox.is_expired
-           , v_unreviewed_docs_inbox.interval_due
-           , v_unreviewed_docs_inbox.xmin_message_inbox 
-        FROM blobs.v_unreviewed_docs_inbox
-     )
- UNIONSELECT now
-     () AS received_when
-     , vtr.modified_by
-     , (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.pk = vtr.pk_intended_reviewer)
+                 ('<'::text || 
+                       (mi.modified_by)::text
+                 ) || '>'::text
+           )
+     ) AS modified_by
+     ,
+            
+     (
+      SELECT staff.short_alias
+                   
+        FROM dem.staff
+                  
+       WHERE (staff.pk = mi.fk_staff)
      ) AS provider
-     , 0 AS importance
-     ,'clinical'::text AS category
-     , _
-     ('clinical'::text) AS l10n_category
-     ,'review results'::text AS type
-     , _
-     ('review results'::text) AS l10n_type
-     , (
-      SELECT (
-                 (
-                       (
-                             (
-                                   (_
-                                         ('unreviewed (normal) results for patient'::text
-                                   ) || ' ['::text
-                             ) || dn.lastnames
-                       ) || 
-                    ', '::text
-                 ) || dn.firstnames
-           ) || ']'::text
+     ,
+            mi.importance
+     ,
+            vit.category
+     ,
+            vit.l10n_category
+     ,
+            vit.type
+     ,
+            vit.l10n_type
+     ,
+            mi.comment
+     ,
+            mi.ufk_context AS pk_context
+     ,
+            mi.data
+     ,
+            mi.pk AS pk_inbox_message
+     ,
+            mi.fk_staff AS pk_staff
+     ,
+            vit.pk_category
+     ,
+            mi.fk_inbox_item_type AS pk_type
+     ,
+            mi.fk_patient AS pk_patient
+     ,
+            false AS is_virtual
+     ,
+            mi.due_date
+     ,
+            mi.expiry_date
+     ,
+                CASE
+                    WHEN 
+     (mi.due_date IS NULL) THEN false
+                    WHEN 
+     (mi.due_date > now
+           ()
+     ) THEN false
+                    WHEN 
+     (mi.expiry_date IS NULL) THEN true
+                    WHEN 
+     (mi.expiry_date < now
+           ()
+     ) THEN false
+                    ELSE true
+                END AS is_overdue
+     ,
+                CASE
+                    WHEN 
+     (mi.expiry_date IS NULL) THEN false
+                    WHEN 
+     (mi.expiry_date > now
+           ()
+     ) THEN false
+                    ELSE true
+                END AS is_expired
+     ,
+                CASE
+                    WHEN 
+     (mi.due_date IS NULL) THEN NULL::interval
+                    WHEN 
+     (mi.due_date > now
+           ()
+     ) THEN 
+     (
+           (mi.due_date)::timestamp with time zone - now
+           ()
      )
-  FROM dem.names dn 
- WHERE (
-           (dn.id_identity = vtr.pk_patient)
-         AND (dn.active IS TRUE)
+                    ELSE 
+     (now
+           () - 
+           (mi.due_date)::timestamp with time zone
      )
-) AS comment
-, NULL::integer[] AS pk_context
-, NULL::text AS data
-, NULL::integer AS pk_inbox_message
-, vtr.pk_intended_reviewer AS pk_staff
-, (
-SELECT v_inbox_item_type.pk_category 
-  FROM dem.v_inbox_item_type 
- WHERE (v_inbox_item_type.type = 'review results'::text)
-) AS pk_category
-, (
-SELECT v_inbox_item_type.pk_type 
-  FROM dem.v_inbox_item_type 
- WHERE (v_inbox_item_type.type = 'review results'::text)
-) AS pk_type
-, vtr.pk_patient
-, true AS is_virtual
-, (now
-     () - '01:00:00'::interval
-) AS due_date
-, NULL::timestamp with time zone AS expiry_date
-, true AS is_overdue
-, false AS is_expired
-,'01:00:00'::interval AS interval_due
-, NULL::integer AS xmin_message_inbox 
-FROM clin.v_test_results vtr 
+                END AS interval_due
+     ,
+            gm.xid2int
+     (mi.xmin) AS xmin_message_inbox
+           
+  FROM dem.message_inbox mi
+     ,
+            dem.v_inbox_item_type vit
+          
+ WHERE (mi.fk_inbox_item_type = vit.pk_type)
+        
+UNION ALL
+         
+SELECT v_unreviewed_docs_inbox.received_when
+     ,
+            v_unreviewed_docs_inbox.modified_by
+     ,
+            v_unreviewed_docs_inbox.provider
+     ,
+            v_unreviewed_docs_inbox.importance
+     ,
+            v_unreviewed_docs_inbox.category
+     ,
+            v_unreviewed_docs_inbox.l10n_category
+     ,
+            v_unreviewed_docs_inbox.type
+     ,
+            v_unreviewed_docs_inbox.l10n_type
+     ,
+            v_unreviewed_docs_inbox.comment
+     ,
+            v_unreviewed_docs_inbox.pk_context
+     ,
+            v_unreviewed_docs_inbox.data
+     ,
+            v_unreviewed_docs_inbox.pk_inbox_message
+     ,
+            v_unreviewed_docs_inbox.pk_staff
+     ,
+            v_unreviewed_docs_inbox.pk_category
+     ,
+            v_unreviewed_docs_inbox.pk_type
+     ,
+            v_unreviewed_docs_inbox.pk_patient
+     ,
+            v_unreviewed_docs_inbox.is_virtual
+     ,
+            v_unreviewed_docs_inbox.due_date
+     ,
+            v_unreviewed_docs_inbox.expiry_date
+     ,
+            v_unreviewed_docs_inbox.is_overdue
+     ,
+            v_unreviewed_docs_inbox.is_expired
+     ,
+            v_unreviewed_docs_inbox.interval_due
+     ,
+            v_unreviewed_docs_inbox.xmin_message_inbox
+           
+  FROM blobs.v_unreviewed_docs_inbox
+
+)
+UNION
+ 
+SELECT now
+() AS received_when
+,
+    vtr.modified_by
+,
+    
+(
+SELECT staff.short_alias
+           
+  FROM dem.staff
+          
+ WHERE (staff.pk = vtr.pk_intended_reviewer)
+) AS provider
+,
+    0 AS importance
+,
+    'clinical'::text AS category
+,
+    _
+('clinical'::text) AS l10n_category
+,
+    'review results'::text AS type
+,
+    _
+('review results'::text) AS l10n_type
+,
+    
+(
+SELECT (
+           (
+                 (
+                       (
+                             (_
+                                   ('unreviewed (normal) results for patient'::text
+                             ) || ' ['::text
+                       ) || dn.lastnames
+                 ) || 
+              ', '::text
+           ) || dn.firstnames
+     ) || ']'::text
+)
+           
+FROM dem.names dn
+          
 WHERE (
-     (vtr.reviewed IS FALSE)
-   AND (
-           (vtr.is_technically_abnormal IS FALSE)
-          OR (
-                 (vtr.is_technically_abnormal IS NULL)
-               AND (vtr.abnormality_indicator IS NULL)
-           )
+     (dn.id_identity = vtr.pk_patient)
+   AND (dn.active IS TRUE)
+)
+)      AS comment
+,     
+    NULL::integer[] AS pk_context
+,     
+    NULL::text AS data
+,     
+    NULL::integer AS pk_inbox_message
+,     
+    vtr.pk_intended_reviewer AS pk_staff
+,     
+    
+(     
+SELECT v_inbox_item_type.pk_category
+           
+FROM dem.v_inbox_item_type
+          
+WHERE (v_inbox_item_type.type = 'review results'::text)
+)      AS pk_category
+,     
+    
+(     
+SELECT v_inbox_item_type.pk_type
+           
+FROM dem.v_inbox_item_type
+          
+WHERE (v_inbox_item_type.type = 'review results'::text)
+)      AS pk_type
+,     
+    vtr.pk_patient
+,     
+    true AS is_virtual
+,     
+    
+(     now
+() - '01:00:00'::interval
+)      AS due_date
+,     
+    NULL::timestamp with time zone AS expiry_date
+,     
+    true AS is_overdue
+,     
+    false AS is_expired
+,     
+    '01:00:00'::interval AS interval_due
+,     
+    NULL::integer AS xmin_message_inbox
+   
+FROM   clin.v_test_results vtr
+  
+WHERE  (
+(vtr.reviewed IS FALSE)
+AND (
+     (vtr.is_technically_abnormal IS FALSE)
+    OR (
+           (vtr.is_technically_abnormal IS NULL)
+         AND (vtr.abnormality_indicator IS NULL)
      )
 )
 )     
-UNION SELECT now
+UNION 
+ 
+SELECT now
 (     ) AS received_when
-,      vtr.modified_by
-,      (
-SELECT staff.short_alias 
-FROM dem.staff 
+,     
+    vtr.modified_by
+,     
+    
+(     
+SELECT staff.short_alias
+           
+FROM dem.staff
+          
 WHERE (staff.pk = vtr.pk_intended_reviewer)
 )      AS provider
-,      1 AS importance
-,     'clinical'::text AS category
-,      _
+,     
+    1 AS importance
+,     
+    'clinical'::text AS category
+,     
+    _
 (     'clinical'::text) AS l10n_category
-,     'review results'::text AS type
-,      _
+,     
+    'review results'::text AS type
+,     
+    _
 (     'review results'::text) AS l10n_type
-,      (
+,     
+    
+(     
 SELECT (
      (
            (
@@ -101019,37 +120269,62 @@ SELECT (
      ) || dn.firstnames
 ) || ']'::text
 )     
-FROM   dem.names dn 
+           
+FROM   dem.names dn
+          
 WHERE  (
 (dn.id_identity = vtr.pk_patient)
 AND (dn.active IS TRUE)
 )     
 )            AS comment
-,            NULL::integer[] AS pk_context
-,            NULL::text AS data
-,            NULL::integer AS pk_inbox_message
-,            vtr.pk_intended_reviewer AS pk_staff
-,            (
-SELECT v_inbox_item_type.pk_category 
-FROM   dem.v_inbox_item_type 
+,           
+    NULL::integer[] AS pk_context
+,           
+    NULL::text AS data
+,           
+    NULL::integer AS pk_inbox_message
+,           
+    vtr.pk_intended_reviewer AS pk_staff
+,           
+    
+(           
+SELECT v_inbox_item_type.pk_category
+           
+FROM   dem.v_inbox_item_type
+          
 WHERE  (v_inbox_item_type.type = 'review results'::text)
 )            AS pk_category
-,            (
-SELECT v_inbox_item_type.pk_type 
-FROM   dem.v_inbox_item_type 
+,           
+    
+(           
+SELECT v_inbox_item_type.pk_type
+           
+FROM   dem.v_inbox_item_type
+          
 WHERE  (v_inbox_item_type.type = 'review results'::text)
 )            AS pk_type
-,            vtr.pk_patient
-,            true AS is_virtual
-,            (now
+,           
+    vtr.pk_patient
+,           
+    true AS is_virtual
+,           
+    
+(           now
 (     ) - '01:00:00'::interval
 )            AS due_date
-,            NULL::timestamp with time zone AS expiry_date
-,            true AS is_overdue
-,            false AS is_expired
-,           '01:00:00'::interval AS interval_due
-,            NULL::integer AS xmin_message_inbox 
-FROM         clin.v_test_results vtr 
+,           
+    NULL::timestamp with time zone AS expiry_date
+,           
+    true AS is_overdue
+,           
+    false AS is_expired
+,           
+    '01:00:00'::interval AS interval_due
+,           
+    NULL::integer AS xmin_message_inbox
+   
+FROM         clin.v_test_results vtr
+  
 WHERE        (
 (     vtr.reviewed IS FALSE)
 AND    (
@@ -101253,16 +120528,26 @@ OR (
 	
 	<pre>
 SELECT d_lo2c.fk_org_unit AS pk_org_unit
-, ect.description AS comm_type
-, _
+,
+    ect.description AS comm_type
+,
+    _
 (ect.description) AS l10n_comm_type
-, d_lo2c.url
-, d_lo2c.comment
-, d_lo2c.is_confidential
-, d_lo2c.pk AS pk_lnk_org_unit2comm
-, d_lo2c.fk_type AS pk_type
-, d_lo2c.xmin AS xmin_lnk_org_unit2comm 
-FROM (dem.lnk_org_unit2comm d_lo2c 
+,
+    d_lo2c.url
+,
+    d_lo2c.comment
+,
+    d_lo2c.is_confidential
+,
+    d_lo2c.pk AS pk_lnk_org_unit2comm
+,
+    d_lo2c.fk_type AS pk_type
+,
+    d_lo2c.xmin AS xmin_lnk_org_unit2comm
+   
+FROM (dem.lnk_org_unit2comm d_lo2c
+     
   JOIN dem.enum_comm_types ect 
     ON (
            (d_lo2c.fk_type = ect.pk)
@@ -101523,39 +120808,58 @@ FROM (dem.lnk_org_unit2comm d_lo2c
 	
 	<pre>
 SELECT d_ou.pk AS pk_org_unit
-, d_o.description AS organization
-, d_ou.description AS unit
-, d_oc_o.description AS organization_category
-, _
+,
+    d_o.description AS organization
+,
+    d_ou.description AS unit
+,
+    d_oc_o.description AS organization_category
+,
+    _
 (d_oc_o.description) AS l10n_organization_category
-, d_oc_u.description AS unit_category
-, _
+,
+    d_oc_u.description AS unit_category
+,
+    _
 (d_oc_u.description) AS l10n_unit_category
-, (EXISTS 
+,
+    
+(EXISTS 
      (
-      SELECT 1 
-        FROM dem.praxis_branch d_pb 
+      SELECT 1
+           
+        FROM dem.praxis_branch d_pb
+          
        WHERE (d_pb.fk_org_unit = d_ou.pk)
      )
 ) AS is_praxis_branch
-, d_o.pk AS pk_org
-, d_o.fk_category AS pk_category_org
-, d_ou.fk_category AS pk_category_unit
-, d_ou.fk_address AS pk_address
-, d_ou.xmin AS xmin_org_unit 
+,
+    d_o.pk AS pk_org
+,
+    d_o.fk_category AS pk_category_org
+,
+    d_ou.fk_category AS pk_category_unit
+,
+    d_ou.fk_address AS pk_address
+,
+    d_ou.xmin AS xmin_org_unit
+   
 FROM (
      (
-           (dem.org_unit d_ou 
+           (dem.org_unit d_ou
+     
               JOIN dem.org d_o 
                 ON (
                        (d_o.pk = d_ou.fk_org)
                  )
            )
+     
    LEFT JOIN dem.org_category d_oc_u 
           ON (
                  (d_ou.fk_category = d_oc_u.pk)
            )
      )
+     
 LEFT JOIN dem.org_category d_oc_o 
     ON (
            (d_o.fk_category = d_oc_o.pk)
@@ -101800,32 +121104,47 @@ LEFT JOIN dem.org_category d_oc_o
 	
 	<pre>
 SELECT d_ou.pk AS pk_org_unit
-, d_o.description AS organization
-, d_ou.description AS unit
-, d_oc_o.description AS organization_category
-, _
+,
+    d_o.description AS organization
+,
+    d_ou.description AS unit
+,
+    d_oc_o.description AS organization_category
+,
+    _
 (d_oc_o.description) AS l10n_organization_category
-, d_oc_u.description AS unit_category
-, _
+,
+    d_oc_u.description AS unit_category
+,
+    _
 (d_oc_u.description) AS l10n_unit_category
-, d_o.pk AS pk_org
-, d_o.fk_category AS pk_category_org
-, d_ou.fk_category AS pk_category_unit
-, d_ou.fk_address AS pk_address
-, d_ou.xmin AS xmin_org_unit 
+,
+    d_o.pk AS pk_org
+,
+    d_o.fk_category AS pk_category_org
+,
+    d_ou.fk_category AS pk_category_unit
+,
+    d_ou.fk_address AS pk_address
+,
+    d_ou.xmin AS xmin_org_unit
+   
 FROM (
      (
-           (dem.org_unit d_ou 
+           (dem.org_unit d_ou
+     
               JOIN dem.org d_o 
                 ON (
                        (d_o.pk = d_ou.fk_org)
                  )
            )
+     
    LEFT JOIN dem.org_category d_oc_u 
           ON (
                  (d_ou.fk_category = d_oc_u.pk)
            )
      )
+     
 LEFT JOIN dem.org_category d_oc_o 
     ON (
            (d_o.fk_category = d_oc_o.pk)
@@ -101990,26 +121309,39 @@ LEFT JOIN dem.org_category d_oc_o
 	
 	<pre>
 SELECT d_o.pk AS pk_org
-, d_o.description AS organization
-, d_oc.description AS category
-, _
+,
+    d_o.description AS organization
+,
+    d_oc.description AS category
+,
+    _
 (d_oc.description) AS l10n_category
-, (EXISTS 
+,
+    
+(EXISTS 
      (
-      SELECT 1 
-        FROM dem.praxis_branch d_pb 
+      SELECT 1
+           
+        FROM dem.praxis_branch d_pb
+          
        WHERE (d_pb.fk_org_unit IN 
                  (
-                  SELECT d_ou.pk 
-                    FROM dem.org_unit d_ou 
+                  SELECT d_ou.pk
+                   
+                    FROM dem.org_unit d_ou
+                  
                    WHERE (d_ou.fk_org = d_o.pk)
                  )
            )
      )
 ) AS is_praxis
-, d_o.fk_category AS pk_category_org
-, d_o.xmin AS xmin_org 
-FROM (dem.org d_o 
+,
+    d_o.fk_category AS pk_category_org
+,
+    d_o.xmin AS xmin_org
+   
+FROM (dem.org d_o
+     
 LEFT JOIN dem.org_category d_oc 
     ON (
            (d_o.fk_category = d_oc.pk)
@@ -102031,7 +121363,7 @@ LEFT JOIN dem.org_category d_oc
 			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.view.v-pat-addresses">v_pat_addresses</a>
 		</h2>
         
-         <p>denormalized addresses per patient</p>
+         <p>denormalized addresses per person</p>
         
 
 
@@ -102176,22 +121508,6 @@ LEFT JOIN dem.org_category d_oc
 				<td>
                 
                 </td>
-            	<td>cob</td>
-            	<td>character(2)</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
             	<td>gender</td>
             	<td>text</td>
                 <td><i>
@@ -102204,7 +121520,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -102220,7 +121536,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -102236,7 +121552,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -102252,7 +121568,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -102268,7 +121584,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -102284,7 +121600,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -102300,7 +121616,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -102316,7 +121632,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -102332,7 +121648,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -102348,7 +121664,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -102364,7 +121680,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -102380,7 +121696,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -102396,7 +121712,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -102412,7 +121728,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -102428,7 +121744,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -102444,11 +121760,11 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>code_state</td>
+            	<td>code_region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -102460,11 +121776,11 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>state</td>
+            	<td>region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -102476,11 +121792,11 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
-            	<td>l10n_state</td>
+            	<td>l10n_region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -102492,7 +121808,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -102508,7 +121824,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -102524,7 +121840,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -102540,7 +121856,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -102556,7 +121872,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -102572,7 +121888,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -102588,11 +121904,11 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>pk_state</td>
+            	<td>pk_region</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -102604,7 +121920,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -102620,7 +121936,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -102636,7 +121952,7 @@ LEFT JOIN dem.org_category d_oc
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -102671,55 +121987,95 @@ LEFT JOIN dem.org_category d_oc
 	<!-- View Definition -->
 	
 	<pre>
-SELECT vbp.pk_identity
-, va.pk_address
-, at.name AS address_type
-, _
-(at.name) AS l10n_address_type
-, vbp.title
-, vbp.firstnames
-, vbp.lastnames
-, vbp.dob
-, vbp.cob
-, vbp.gender
-, vbp.l10n_gender
-, vbp.preferred
-, va.street
-, va.postcode
-, va.notes_street
-, va.number
-, va.subunit
-, va.notes_subunit
-, va.lat_lon_address
-, va.postcode_street
-, va.lat_lon_street
-, va.suburb
-, va.urb
-, va.postcode_urb
-, va.lat_lon_urb
-, va.code_state
-, va.state
-, va.l10n_state
-, va.code_country
-, va.country
-, va.l10n_country
-, va.country_deprecated
-, va.pk_street
-, va.pk_urb
-, va.pk_state
-, lpoa.id AS pk_lnk_person_org_address
-, lpoa.id_type AS pk_address_type
-, lpoa.xmin AS xmin_lnk_person_org_address 
-FROM dem.v_address va
-, dem.lnk_person_org_address lpoa
-, dem.v_basic_person vbp
-, dem.address_type at 
+SELECT d_vp.pk_identity
+,
+    d_va.pk_address
+,
+    d_at.name AS address_type
+,
+    _
+(d_at.name) AS l10n_address_type
+,
+    d_vp.title
+,
+    d_vp.firstnames
+,
+    d_vp.lastnames
+,
+    d_vp.dob
+,
+    d_vp.gender
+,
+    d_vp.l10n_gender
+,
+    d_vp.preferred
+,
+    d_va.street
+,
+    d_va.postcode
+,
+    d_va.notes_street
+,
+    d_va.number
+,
+    d_va.subunit
+,
+    d_va.notes_subunit
+,
+    d_va.lat_lon_address
+,
+    d_va.postcode_street
+,
+    d_va.lat_lon_street
+,
+    d_va.suburb
+,
+    d_va.urb
+,
+    d_va.postcode_urb
+,
+    d_va.lat_lon_urb
+,
+    d_va.code_region
+,
+    d_va.region
+,
+    d_va.l10n_region
+,
+    d_va.code_country
+,
+    d_va.country
+,
+    d_va.l10n_country
+,
+    d_va.country_deprecated
+,
+    d_va.pk_street
+,
+    d_va.pk_urb
+,
+    d_va.pk_region
+,
+    d_lpoa.id AS pk_lnk_person_org_address
+,
+    d_lpoa.id_type AS pk_address_type
+,
+    d_lpoa.xmin AS xmin_lnk_person_org_address
+   
+FROM dem.v_address d_va
+,
+    dem.lnk_person_org_address d_lpoa
+,
+    dem.v_all_persons d_vp
+,
+    dem.address_type d_at
+  
 WHERE (
      (
-           (lpoa.id_identity = vbp.pk_identity)
-         AND (lpoa.id_address = va.pk_address)
+           (d_lpoa.id_identity = d_vp.pk_identity)
+         AND (d_lpoa.id_address = d_va.pk_address)
      )
-   AND (lpoa.id_type = at.id)
+   AND (d_lpoa.id_type = d_at.id)
 );</pre>
 	
 
@@ -102930,18 +122286,30 @@ WHERE (
 	
 	<pre>
 SELECT li2c.fk_identity AS pk_identity
-, ect.description AS comm_type
-, _
+,
+    ect.description AS comm_type
+,
+    _
 (ect.description) AS l10n_comm_type
-, li2c.url
-, li2c.is_confidential
-, li2c.comment
-, li2c.pk AS pk_lnk_identity2comm
-, li2c.fk_address AS pk_address
-, li2c.fk_type AS pk_type
-, li2c.xmin AS xmin_lnk_identity2comm 
+,
+    li2c.url
+,
+    li2c.is_confidential
+,
+    li2c.comment
+,
+    li2c.pk AS pk_lnk_identity2comm
+,
+    li2c.fk_address AS pk_address
+,
+    li2c.fk_type AS pk_type
+,
+    li2c.xmin AS xmin_lnk_identity2comm
+   
 FROM dem.lnk_identity2comm li2c
-, dem.enum_comm_types ect 
+,
+    dem.enum_comm_types ect
+  
 WHERE (li2c.fk_type = ect.pk);</pre>
 	
 
@@ -103120,15 +122488,24 @@ WHERE (li2c.fk_type = ect.pk);</pre>
 	
 	<pre>
 SELECT lj2p.fk_identity AS pk_identity
-, o.name AS occupation
-, _
+,
+    o.name AS occupation
+,
+    _
 (o.name) AS l10n_occupation
-, lj2p.activities
-, lj2p.modified_when
-, lj2p.fk_occupation AS pk_occupation
-, lj2p.pk AS pk_lnk_job2person
-, lj2p.xmin AS xmin_lnk_job2person 
-FROM (dem.lnk_job2person lj2p 
+,
+    lj2p.activities
+,
+    lj2p.modified_when
+,
+    lj2p.fk_occupation AS pk_occupation
+,
+    lj2p.pk AS pk_lnk_job2person
+,
+    lj2p.xmin AS xmin_lnk_job2person
+   
+FROM (dem.lnk_job2person lj2p
+     
   JOIN dem.occupation o 
     ON (
            (lj2p.fk_occupation = o.id)
@@ -103421,22 +122798,40 @@ FROM (dem.lnk_job2person lj2p
 	
 	<pre>
 SELECT dn.id_identity AS pk_identity
-, dn.active AS active_name
-, di.title
-, dn.firstnames
-, dn.lastnames
-, dn.preferred
-, dn.comment
-, di.gender
-, di.dob
-, di.tob
-, di.deceased AS dod
-, di.deleted AS identity_deleted
-, (di.deceased IS NOT NULL) AS deceased
-, dn.id AS pk_name
-, dn.xmin AS xmin_name 
+,
+    dn.active AS active_name
+,
+    di.title
+,
+    dn.firstnames
+,
+    dn.lastnames
+,
+    dn.preferred
+,
+    dn.comment
+,
+    di.gender
+,
+    di.dob
+,
+    di.tob
+,
+    di.deceased AS dod
+,
+    di.deleted AS identity_deleted
+,
+    
+(di.deceased IS NOT NULL) AS deceased
+,
+    dn.id AS pk_name
+,
+    dn.xmin AS xmin_name
+   
 FROM dem.names dn
-, dem.identity di 
+,
+    dem.identity di
+  
 WHERE (di.pk = dn.id_identity);</pre>
 	
 
@@ -103839,15 +123234,24 @@ WHERE (di.pk = dn.id_identity);</pre>
 	
 	<pre>
 SELECT i.pk AS pk_identity
-, i.title
-, n.firstnames
-, n.preferred
-, n.lastnames
-, i.gender
-, _
+,
+    i.title
+,
+    n.firstnames
+,
+    n.preferred
+,
+    n.lastnames
+,
+    i.gender
+,
+    _
 (i.gender) AS l10n_gender
-, i.dob AS dob_only
-, (date_trunc
+,
+    i.dob AS dob_only
+,
+    
+(date_trunc
      ('day'::text
            , i.dob
      ) + 
@@ -103857,43 +123261,71 @@ SELECT i.pk AS pk_identity
            )
      )::interval
 ) AS dob
-, i.tob
-, i.deceased
-, CASE WHEN 
-(i.fk_marital_status IS NULL) THEN 'unknown'::text ELSE 
+,
+    i.tob
+,
+    i.deceased
+,
+        CASE
+            WHEN 
+(i.fk_marital_status IS NULL) THEN 'unknown'::text
+            ELSE 
 (
-SELECT ms.name 
+SELECT ms.name
+               
   FROM dem.marital_status ms
-     , dem.identity i1 
+     ,
+                dem.identity i1
+              
  WHERE (
            (ms.pk = i.fk_marital_status)
          AND (i1.pk = i.pk)
      )
-) END AS marital_status
-, CASE WHEN 
+)
+        END AS marital_status
+,
+        CASE
+            WHEN 
 (i.fk_marital_status IS NULL) THEN _
-('unknown'::text) ELSE 
+('unknown'::text)
+            ELSE 
 (
 SELECT _
-     (ms1.name) AS _ 
+     (ms1.name) AS _
+               
   FROM dem.marital_status ms1
-     , dem.identity i1 
+     ,
+                dem.identity i1
+              
  WHERE (
            (ms1.pk = i.fk_marital_status)
          AND (i1.pk = i.pk)
      )
-) END AS l10n_marital_status
-, i.emergency_contact
-, i.comment
-, i.deleted AS is_deleted
-, i.fk_marital_status AS pk_marital_status
-, n.id AS pk_active_name
-, i.fk_emergency_contact AS pk_emergency_contact
-, i.fk_primary_provider AS pk_primary_provider
-, i.xmin AS xmin_identity
-, i.dob_is_estimated 
+)
+        END AS l10n_marital_status
+,
+    i.emergency_contact
+,
+    i.comment
+,
+    i.deleted AS is_deleted
+,
+    i.fk_marital_status AS pk_marital_status
+,
+    n.id AS pk_active_name
+,
+    i.fk_emergency_contact AS pk_emergency_contact
+,
+    i.fk_primary_provider AS pk_primary_provider
+,
+    i.xmin AS xmin_identity
+,
+    i.dob_is_estimated
+   
 FROM dem.identity i
-, dem.names n 
+,
+    dem.names n
+  
 WHERE (
      (n.active IS TRUE)
    AND (n.id_identity = i.pk)
@@ -104171,62 +123603,98 @@ WHERE (
 	
 	<pre>
 SELECT branches_w_orgs.pk_praxis_branch
-, branches_w_orgs.branch
-, branches_w_orgs.pk_org_unit
-, branches_w_orgs.pk_category_unit
-, branches_w_orgs.pk_address
-, branches_w_orgs.pk_org
-, branches_w_orgs.xmin_praxis_branch
-, branches_w_orgs.xmin_org_unit
-, branches_w_orgs.praxis
-, branches_w_orgs.pk_category_org
-, d_ocat.description AS organization_category
-, _
+,
+    branches_w_orgs.branch
+,
+    branches_w_orgs.pk_org_unit
+,
+    branches_w_orgs.pk_category_unit
+,
+    branches_w_orgs.pk_address
+,
+    branches_w_orgs.pk_org
+,
+    branches_w_orgs.xmin_praxis_branch
+,
+    branches_w_orgs.xmin_org_unit
+,
+    branches_w_orgs.praxis
+,
+    branches_w_orgs.pk_category_org
+,
+    d_ocat.description AS organization_category
+,
+    _
 (d_ocat.description) AS l10n_organization_category
-, d_ucat.description AS unit_category
-, _
-(d_ucat.description) AS l10n_unit_category 
+,
+    d_ucat.description AS unit_category
+,
+    _
+(d_ucat.description) AS l10n_unit_category
+   
 FROM (
      (
            (
             SELECT branches_w_units.pk_praxis_branch
-                 , branches_w_units.branch
-                 , branches_w_units.pk_org_unit
-                 , branches_w_units.pk_category_unit
-                 , branches_w_units.pk_address
-                 , branches_w_units.pk_org
-                 , branches_w_units.xmin_praxis_branch
-                 , branches_w_units.xmin_org_unit
-                 , d_o.description AS praxis
-                 , d_o.fk_category AS pk_category_org 
+                 ,
+            branches_w_units.branch
+                 ,
+            branches_w_units.pk_org_unit
+                 ,
+            branches_w_units.pk_category_unit
+                 ,
+            branches_w_units.pk_address
+                 ,
+            branches_w_units.pk_org
+                 ,
+            branches_w_units.xmin_praxis_branch
+                 ,
+            branches_w_units.xmin_org_unit
+                 ,
+            d_o.description AS praxis
+                 ,
+            d_o.fk_category AS pk_category_org
+           
               FROM (
                        (
                         SELECT d_pb.pk AS pk_praxis_branch
-                             , d_ou.description AS branch
-                             , d_pb.fk_org_unit AS pk_org_unit
-                             , d_ou.fk_category AS pk_category_unit
-                             , d_ou.fk_address AS pk_address
-                             , d_ou.fk_org AS pk_org
-                             , d_pb.xmin AS xmin_praxis_branch
-                             , d_ou.xmin AS xmin_org_unit 
-                          FROM (dem.praxis_branch d_pb 
+                             ,
+                    d_ou.description AS branch
+                             ,
+                    d_pb.fk_org_unit AS pk_org_unit
+                             ,
+                    d_ou.fk_category AS pk_category_unit
+                             ,
+                    d_ou.fk_address AS pk_address
+                             ,
+                    d_ou.fk_org AS pk_org
+                             ,
+                    d_pb.xmin AS xmin_praxis_branch
+                             ,
+                    d_ou.xmin AS xmin_org_unit
+                   
+                          FROM (dem.praxis_branch d_pb
+                     
                                 JOIN dem.org_unit d_ou 
                                   ON (
                                          (d_pb.fk_org_unit = d_ou.pk)
                                    )
                              )
-                       ) branches_w_units 
+                       ) branches_w_units
+             
                     JOIN dem.org d_o 
                       ON (
                              (d_o.pk = branches_w_units.pk_org)
                        )
                  )
-           ) branches_w_orgs 
+           ) branches_w_orgs
+     
    LEFT JOIN dem.org_category d_ucat 
           ON (
                  (branches_w_orgs.pk_category_unit = d_ucat.pk)
            )
      )
+     
 LEFT JOIN dem.org_category d_ocat 
     ON (
            (branches_w_orgs.pk_category_org = d_ocat.pk)
@@ -104245,6 +123713,225 @@ LEFT JOIN dem.org_category d_ocat
         <hr>
 		<h2>View:
 			
+			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.view.v-region">v_region</a>
+		</h2>
+        
+         <p>denormalizes region information</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>dem.v_region Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_region</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>code_region</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>region</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>l10n_region</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>code_country</td>
+            	<td>character(2)</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>country</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>l10n_country</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>country_deprecated</td>
+            	<td>date</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>xmin_region</td>
+            	<td>xid</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT d_r.pk AS pk_region
+,
+    d_r.code AS code_region
+,
+    d_r.name AS region
+,
+    _
+(d_r.name) AS l10n_region
+,
+    d_r.country AS code_country
+,
+    c.name AS country
+,
+    _
+(c.name) AS l10n_country
+,
+    c.deprecated AS country_deprecated
+,
+    d_r.xmin AS xmin_region
+   
+FROM (dem.region d_r
+     
+LEFT JOIN dem.country c 
+    ON (
+           (d_r.country = c.code)
+     )
+);</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#dem.schema">Schema dem</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
 			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.view.v-staff">v_staff</a>
 		</h2>
         
@@ -104457,7 +124144,7 @@ LEFT JOIN dem.org_category d_ocat
 				<td>
                 
                 </td>
-            	<td>can_login</td>
+            	<td>person_is_deleted</td>
             	<td>boolean</td>
                 <td><i>
 				
@@ -104473,6 +124160,22 @@ LEFT JOIN dem.org_category d_ocat
 				<td>
                 
                 </td>
+            	<td>can_login</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
             	<td>xmin_staff</td>
             	<td>xid</td>
                 <td><i>
@@ -104504,107 +124207,148 @@ LEFT JOIN dem.org_category d_ocat
 	<!-- View Definition -->
 	
 	<pre>
-SELECT vbp.pk_identity
-, s.pk AS pk_staff
-, vbp.title
-, vbp.firstnames
-, vbp.lastnames
-, s.short_alias
-, CASE WHEN 
+SELECT d_vp.pk_identity
+,
+    d_s.pk AS pk_staff
+,
+    d_vp.title
+,
+    d_vp.firstnames
+,
+    d_vp.lastnames
+,
+    d_s.short_alias
+,
+        CASE
+            WHEN 
 (
 SELECT (EXISTS 
            (
-            SELECT 1 
-              FROM pg_group 
+            SELECT 1
+                       
+              FROM pg_group
+                      
              WHERE (
                        (pg_group.groname = 'gm-doctors'::name)
                      AND (
                              (
-                              SELECT pg_user.usesysid 
-                                FROM pg_user 
-                               WHERE (pg_user.usename = s.db_user)
+                              SELECT pg_user.usesysid
+                               
+                                FROM pg_user
+                              
+                               WHERE (pg_user.usename = d_s.db_user)
                              ) = ANY 
                              (pg_group.grolist)
                        )
                  )
            )
-     )
-) THEN 'full clinical access'::text WHEN 
+     ) AS "exists"
+) THEN 'full clinical access'::text
+            WHEN 
 (
 SELECT (EXISTS 
            (
-            SELECT 1 
-              FROM pg_group 
+            SELECT 1
+                       
+              FROM pg_group
+                      
              WHERE (
                        (pg_group.groname = 'gm-nurses'::name)
                      AND (
                              (
-                              SELECT pg_user.usesysid 
-                                FROM pg_user 
-                               WHERE (pg_user.usename = s.db_user)
+                              SELECT pg_user.usesysid
+                               
+                                FROM pg_user
+                              
+                               WHERE (pg_user.usename = d_s.db_user)
                              ) = ANY 
                              (pg_group.grolist)
                        )
                  )
            )
-     )
-) THEN 'limited clinical access'::text WHEN 
+     ) AS "exists"
+) THEN 'limited clinical access'::text
+            WHEN 
 (
 SELECT (EXISTS 
            (
-            SELECT 1 
-              FROM pg_group 
+            SELECT 1
+                       
+              FROM pg_group
+                      
              WHERE (
                        (pg_group.groname = 'gm-staff'::name)
                      AND (
                              (
-                              SELECT pg_user.usesysid 
-                                FROM pg_user 
-                               WHERE (pg_user.usename = s.db_user)
+                              SELECT pg_user.usesysid
+                               
+                                FROM pg_user
+                              
+                               WHERE (pg_user.usename = d_s.db_user)
                              ) = ANY 
                              (pg_group.grolist)
                        )
                  )
            )
-     )
-) THEN 'non-clinical access'::text WHEN 
+     ) AS "exists"
+) THEN 'non-clinical access'::text
+            WHEN 
 (
 SELECT (EXISTS 
            (
-            SELECT 1 
-              FROM pg_group 
+            SELECT 1
+                       
+              FROM pg_group
+                      
              WHERE (
                        (pg_group.groname = 'gm-public'::name)
                      AND (
                              (
-                              SELECT pg_user.usesysid 
-                                FROM pg_user 
-                               WHERE (pg_user.usename = s.db_user)
+                              SELECT pg_user.usesysid
+                               
+                                FROM pg_user
+                              
+                               WHERE (pg_user.usename = d_s.db_user)
                              ) = ANY 
                              (pg_group.grolist)
                        )
                  )
            )
-     )
-) THEN 'public access'::text ELSE NULL::text END AS role
-, vbp.dob
-, vbp.gender
-, s.db_user
-, s.comment
-, s.is_active
-, (
+     ) AS "exists"
+) THEN 'public access'::text
+            ELSE NULL::text
+        END AS role
+,
+    d_vp.dob
+,
+    d_vp.gender
+,
+    d_s.db_user
+,
+    d_s.comment
+,
+    d_s.is_active
+,
+    d_vp.is_deleted AS person_is_deleted
+,
+    
+(
 SELECT (
            (
             SELECT (EXISTS 
                        (
-                        SELECT 1 
-                          FROM pg_group 
+                        SELECT 1
+                           
+                          FROM pg_group
+                          
                          WHERE (
                                    (
                                          (
-                                          SELECT pg_user.usesysid 
-                                            FROM pg_user 
-                                           WHERE (pg_user.usename = s.db_user)
+                                          SELECT pg_user.usesysid
+                                   
+                                            FROM pg_user
+                                  
+                                           WHERE (pg_user.usename = d_s.db_user)
                                          ) = ANY 
                                          (pg_group.grolist)
                                    )
@@ -104613,243 +124357,41 @@ SELECT (
                                    )
                              )
                        )
-                 )
+                 ) AS "exists"
            )
          AND (
             SELECT (EXISTS 
                        (
-                        SELECT 1 
-                          FROM pg_group 
+                        SELECT 1
+                           
+                          FROM pg_group
+                          
                          WHERE (
                                    (
                                          (
-                                          SELECT pg_user.usesysid 
-                                            FROM pg_user 
-                                           WHERE (pg_user.usename = s.db_user)
+                                          SELECT pg_user.usesysid
+                                   
+                                            FROM pg_user
+                                  
+                                           WHERE (pg_user.usename = d_s.db_user)
                                          ) = ANY 
                                          (pg_group.grolist)
                                    )
                                  AND (pg_group.groname = 'gm-logins'::name)
                              )
                        )
-                 )
+                 ) AS "exists"
            )
      )
 ) AS can_login
-, s.xmin AS xmin_staff 
-FROM (dem.staff s 
-  JOIN dem.v_basic_person vbp 
+,
+    d_s.xmin AS xmin_staff
+   
+FROM (dem.staff d_s
+     
+  JOIN dem.v_all_persons d_vp 
     ON (
-           (s.fk_identity = vbp.pk_identity)
-     )
-);</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#dem.schema">Schema dem</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.view.v-state">v_state</a>
-		</h2>
-        
-         <p>denormalizes state information</p>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>dem.v_state Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_state</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>code_state</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>state</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>l10n_state</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>code_country</td>
-            	<td>character(2)</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>country</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>l10n_country</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>country_deprecated</td>
-            	<td>date</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>xmin_state</td>
-            	<td>xid</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT s.id AS pk_state
-, s.code AS code_state
-, s.name AS state
-, _
-(s.name) AS l10n_state
-, s.country AS code_country
-, c.name AS country
-, _
-(c.name) AS l10n_country
-, c.deprecated AS country_deprecated
-, s.xmin AS xmin_state 
-FROM (dem.state s 
-LEFT JOIN dem.country c 
-    ON (
-           (s.country = c.code)
+           (d_s.fk_identity = d_vp.pk_identity)
      )
 );</pre>
 	
@@ -105029,7 +124571,7 @@ LEFT JOIN dem.country c
 				<td>
                 
                 </td>
-            	<td>code_state</td>
+            	<td>code_region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -105045,7 +124587,7 @@ LEFT JOIN dem.country c
 				<td>
                 
                 </td>
-            	<td>state</td>
+            	<td>region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -105061,7 +124603,7 @@ LEFT JOIN dem.country c
 				<td>
                 
                 </td>
-            	<td>l10n_state</td>
+            	<td>l10n_region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -105157,7 +124699,7 @@ LEFT JOIN dem.country c
 				<td>
                 
                 </td>
-            	<td>pk_state</td>
+            	<td>pk_region</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -105204,32 +124746,52 @@ LEFT JOIN dem.country c
 	<!-- View Definition -->
 	
 	<pre>
-SELECT st.id AS pk_street
-, st.name AS street
-, COALESCE
-(st.postcode
-     , vu.postcode_urb
+SELECT d_st.id AS pk_street
+,
+    d_st.name AS street
+,
+    COALESCE
+(d_st.postcode
+     , d_vu.postcode_urb
 ) AS postcode
-, st.postcode AS postcode_street
-, st.lat_lon AS lat_lon_street
-, st.suburb
-, vu.urb
-, vu.postcode_urb
-, vu.lat_lon_urb
-, vu.code_state
-, vu.state
-, vu.l10n_state
-, vu.code_country
-, vu.country
-, vu.l10n_country
-, vu.country_deprecated
-, st.id_urb AS pk_urb
-, vu.pk_state
-, st.xmin AS xmin_street 
-FROM (dem.street st 
-LEFT JOIN dem.v_urb vu 
+,
+    d_st.postcode AS postcode_street
+,
+    d_st.lat_lon AS lat_lon_street
+,
+    d_st.suburb
+,
+    d_vu.urb
+,
+    d_vu.postcode_urb
+,
+    d_vu.lat_lon_urb
+,
+    d_vu.code_region
+,
+    d_vu.region
+,
+    d_vu.l10n_region
+,
+    d_vu.code_country
+,
+    d_vu.country
+,
+    d_vu.l10n_country
+,
+    d_vu.country_deprecated
+,
+    d_st.id_urb AS pk_urb
+,
+    d_vu.pk_region
+,
+    d_st.xmin AS xmin_street
+   
+FROM (dem.street d_st
+     
+LEFT JOIN dem.v_urb d_vu 
     ON (
-           (st.id_urb = vu.pk_urb)
+           (d_st.id_urb = d_vu.pk_urb)
      )
 );</pre>
 	
@@ -105299,7 +124861,7 @@ LEFT JOIN dem.v_urb vu
 				<td>
                 
                 </td>
-            	<td>state</td>
+            	<td>region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -105315,7 +124877,7 @@ LEFT JOIN dem.v_urb vu
 				<td>
                 
                 </td>
-            	<td>code_state</td>
+            	<td>code_region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -105394,38 +124956,49 @@ LEFT JOIN dem.v_urb vu
 	<!-- View Definition -->
 	
 	<pre>
-SELECT urb.postcode
-, urb.name
-, stt.name AS state
-, stt.code AS code_state
-, c.name AS country
-, _
-(c.name) AS l10n_country
-, stt.country AS code_country 
-FROM dem.urb
-, dem.state stt
-, dem.country c 
+SELECT d_u.postcode
+,
+    d_u.name
+,
+    d_r.name AS region
+,
+    d_r.code AS code_region
+,
+    d_c.name AS country
+,
+    _
+(d_c.name) AS l10n_country
+,
+    d_r.country AS code_country
+   
+FROM dem.urb d_u
+,
+    dem.region d_r
+,
+    dem.country d_c
+  
 WHERE (
      (
            (
-                 (urb.postcode IS NOT NULL)
+                 (d_u.postcode IS NOT NULL)
                AND (NOT 
                        (EXISTS 
                              (
-                              SELECT 1 
-                                FROM dem.v_zip2street vz2str
-                                   , dem.urb 
+                              SELECT 1
+           
+                                FROM dem.v_zip2street d_vz2str
+          
                                WHERE (
-                                         (vz2str.postcode = urb.postcode)
-                                       AND (vz2str.urb = urb.name)
+                                         (d_vz2str.postcode = d_u.postcode)
+                                       AND (d_vz2str.urb = d_u.name)
                                    )
                              )
                        )
                  )
            )
-         AND (urb.id_state = stt.id)
+         AND (d_u.fk_region = d_r.pk)
      )
-   AND (stt.country = c.code)
+   AND (d_r.country = d_c.code)
 );</pre>
 	
 
@@ -105524,7 +125097,7 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>code_state</td>
+            	<td>code_region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -105540,7 +125113,7 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>state</td>
+            	<td>region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -105556,7 +125129,7 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>l10n_state</td>
+            	<td>l10n_region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -105636,7 +125209,7 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>pk_state</td>
+            	<td>pk_region</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -105683,23 +125256,37 @@ WHERE (
 	<!-- View Definition -->
 	
 	<pre>
-SELECT u.id AS pk_urb
-, u.name AS urb
-, u.postcode AS postcode_urb
-, u.lat_lon AS lat_lon_urb
-, vs.code_state
-, vs.state
-, vs.l10n_state
-, vs.code_country
-, vs.country
-, vs.l10n_country
-, vs.country_deprecated
-, u.id_state AS pk_state
-, u.xmin AS xmin_urb 
-FROM (dem.urb u 
-LEFT JOIN dem.v_state vs 
+SELECT d_u.id AS pk_urb
+,
+    d_u.name AS urb
+,
+    d_u.postcode AS postcode_urb
+,
+    d_u.lat_lon AS lat_lon_urb
+,
+    d_vr.code_region
+,
+    d_vr.region
+,
+    d_vr.l10n_region
+,
+    d_vr.code_country
+,
+    d_vr.country
+,
+    d_vr.l10n_country
+,
+    d_vr.country_deprecated
+,
+    d_u.fk_region AS pk_region
+,
+    d_u.xmin AS xmin_urb
+   
+FROM (dem.urb d_u
+     
+LEFT JOIN dem.v_region d_vr 
     ON (
-           (vs.pk_state = u.id_state)
+           (d_vr.pk_region = d_u.fk_region)
      )
 );</pre>
 	
@@ -105799,7 +125386,7 @@ LEFT JOIN dem.v_state vs
 				<td>
                 
                 </td>
-            	<td>state</td>
+            	<td>region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -105815,7 +125402,7 @@ LEFT JOIN dem.v_state vs
 				<td>
                 
                 </td>
-            	<td>code_state</td>
+            	<td>code_region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -105894,26 +125481,47 @@ LEFT JOIN dem.v_state vs
 	<!-- View Definition -->
 	
 	<pre>
-SELECT vz2s.postcode AS zip
-, vz2s.street
-, vz2s.suburb
-, vz2s.urb
-, vz2s.state
-, vz2s.code_state
-, vz2s.country
-, vz2s.l10n_country
-, vz2s.code_country 
-FROM dem.v_zip2street vz2s 
-UNIONSELECT vuzu.postcode AS zip
-, NULL::text AS street
-, NULL::text AS suburb
-, vuzu.name AS urb
-, vuzu.state
-, vuzu.code_state
-, vuzu.country
-, vuzu.l10n_country
-, vuzu.code_country 
-FROM dem.v_uniq_zipped_urbs vuzu;</pre>
+SELECT d_vz2s.postcode AS zip
+,
+    d_vz2s.street
+,
+    d_vz2s.suburb
+,
+    d_vz2s.urb
+,
+    d_vz2s.region
+,
+    d_vz2s.code_region
+,
+    d_vz2s.country
+,
+    d_vz2s.l10n_country
+,
+    d_vz2s.code_country
+   
+FROM dem.v_zip2street d_vz2s
+
+UNION
+ 
+SELECT d_vuzu.postcode AS zip
+,
+    NULL::text AS street
+,
+    NULL::text AS suburb
+,
+    d_vuzu.name AS urb
+,
+    d_vuzu.region
+,
+    d_vuzu.code_region
+,
+    d_vuzu.country
+,
+    d_vuzu.l10n_country
+,
+    d_vuzu.code_country
+   
+FROM dem.v_uniq_zipped_urbs d_vuzu;</pre>
 	
 
 	<!-- List off permissions -->
@@ -105995,7 +125603,7 @@ FROM dem.v_uniq_zipped_urbs vuzu;</pre>
 				<td>
                 
                 </td>
-            	<td>state</td>
+            	<td>region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -106011,7 +125619,7 @@ FROM dem.v_uniq_zipped_urbs vuzu;</pre>
 				<td>
                 
                 </td>
-            	<td>code_state</td>
+            	<td>code_region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -106107,31 +125715,44 @@ FROM dem.v_uniq_zipped_urbs vuzu;</pre>
 	
 	<pre>
 SELECT COALESCE
-(str.postcode
-     , urb.postcode
+(d_str.postcode
+     , d_u.postcode
 ) AS postcode
-, str.name AS street
-, str.suburb
-, stt.name AS state
-, stt.code AS code_state
-, urb.name AS urb
-, c.name AS country
-, _
-(c.name) AS l10n_country
-, stt.country AS code_country 
-FROM dem.street str
-, dem.urb
-, dem.state stt
-, dem.country c 
+,
+    d_str.name AS street
+,
+    d_str.suburb
+,
+    d_r.name AS region
+,
+    d_r.code AS code_region
+,
+    d_u.name AS urb
+,
+    d_c.name AS country
+,
+    _
+(d_c.name) AS l10n_country
+,
+    d_r.country AS code_country
+   
+FROM dem.street d_str
+,
+    dem.urb d_u
+,
+    dem.region d_r
+,
+    dem.country d_c
+  
 WHERE (
      (
            (
-                 (str.postcode IS NOT NULL)
-               AND (str.id_urb = urb.id)
+                 (d_str.postcode IS NOT NULL)
+               AND (d_str.id_urb = d_u.id)
            )
-         AND (urb.id_state = stt.id)
+         AND (d_u.fk_region = d_r.pk)
      )
-   AND (stt.country = c.code)
+   AND (d_r.country = d_c.code)
 );</pre>
 	
 
@@ -106198,7 +125819,7 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>state</td>
+            	<td>region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -106214,7 +125835,7 @@ WHERE (
 				<td>
                 
                 </td>
-            	<td>code_state</td>
+            	<td>code_region</td>
             	<td>text</td>
                 <td><i>
 				
@@ -106277,22 +125898,31 @@ WHERE (
 	<!-- View Definition -->
 	
 	<pre>
-SELECT urb.postcode
-, urb.name AS urb
-, stt.name AS state
-, stt.code AS code_state
-, _
-(c.name) AS country
-, stt.country AS code_country 
-FROM dem.urb
-, dem.state stt
-, dem.country c 
+SELECT d_u.postcode
+,
+    d_u.name AS urb
+,
+    d_r.name AS region
+,
+    d_r.code AS code_region
+,
+    _
+(d_c.name) AS country
+,
+    d_r.country AS code_country
+   
+FROM dem.urb d_u
+,
+    dem.region d_r
+,
+    dem.country d_c
+  
 WHERE (
      (
-           (urb.postcode IS NOT NULL)
-         AND (urb.id_state = stt.id)
+           (d_u.postcode IS NOT NULL)
+         AND (d_u.fk_region = d_r.pk)
      )
-   AND (stt.country = c.code)
+   AND (d_r.country = d_c.code)
 );</pre>
 	
 
@@ -106373,7 +126003,7 @@ END;</pre>
 the database and returns the primary key if found.
 It takes the following parameters:
 	country code,
-	state code,
+	region code,
 	urb (location),
 	postcode,
 	street,
@@ -106383,7 +126013,7 @@ It takes the following parameters:
         <pre>
 DECLARE
 	_code_country alias for $1;
-	_code_state alias for $2;
+	_code_region alias for $2;
 	_urb alias for $3;
 	_postcode alias for $4;
 	_street alias for $5;
@@ -106393,10 +126023,10 @@ DECLARE
 	_pk_address integer;
 	msg text;
 BEGIN
-	if (_code_country || _code_state || _urb || _postcode || _street || _number) is NULL then
+	if (_code_country || _code_region || _urb || _postcode || _street || _number) is NULL then
 		msg := '[dem.address_exists]: insufficient or invalid address definition: '
 			|| 'country code <' || coalesce(_code_country, 'NULL') || '>, '
-			|| 'state code <' || coalesce(_code_state, 'NULL') || '>, '
+			|| 'region code <' || coalesce(_code_region, 'NULL') || '>, '
 			|| 'urb <' || coalesce(_urb, 'NULL') || '>, '
 			|| 'zip <' || coalesce(_postcode, 'NULL') || '>, '
 			|| 'street <' || coalesce(_street, 'NULL') || '>, '
@@ -106413,7 +126043,7 @@ BEGIN
 		where
 			code_country = trim(_code_country)
 				and
-			code_state = trim(_code_state)
+			code_region = trim(_code_region)
 				and
 			urb = trim(_urb)
 				and
@@ -106432,7 +126062,7 @@ BEGIN
 		where
 			code_country = trim(_code_country)
 				and
-			code_state = trim(_code_state)
+			code_region = trim(_code_region)
 				and
 			urb = trim(_urb)
 				and
@@ -106460,10 +126090,10 @@ It takes the following parameters:
 	street,
 	postcode,
 	urb (location),
-	state code,
+	region code,
 	country code,
 	subunit (can be NULL)
-If the country or the state do not exist
+If the country or the region do not exist
 in the database, the function fails.
 </p>
         <pre>
@@ -106472,7 +126102,7 @@ DECLARE
 	_street ALIAS FOR $2;
 	_postcode ALIAS FOR $3;
 	_urb ALIAS FOR $4;
-	_state_code ALIAS FOR $5;
+	_region_code ALIAS FOR $5;
 	_country_code ALIAS FOR $6;
 	_subunit alias for $7;
 	_street_id integer;
@@ -106482,7 +126112,7 @@ DECLARE
 BEGIN
 	select into _pk_address dem.address_exists (
 		_country_code,
-		_state_code,
+		_region_code,
 		_urb,
 		_postcode,
 		_street,
@@ -106493,8 +126123,8 @@ BEGIN
 		return _pk_address;
 	end if;
 	-- this either creates dem.street and possible dem.urb rows or
-	-- or else it fails (because state and/or country do not exist)
-	select into _street_id dem.create_street(_street, _postcode, _urb, _state_code, _country_code);
+	-- or else it fails (because region and/or country do not exist)
+	select into _street_id dem.create_street(_street, _postcode, _urb, _region_code, _country_code);
 	-- create address
 	__subunit := nullif(trim(_subunit), '');
 	insert into dem.address (
@@ -106607,48 +126237,41 @@ END;</pre>
 		</h2>
 <h3>Returns: integer</h3>
 <h3>Language: PLPGSQL</h3>
-        <p>This function takes a parameters the name of the urb,
-
-	the postcode of the urb, the name of the state and the
-
-	name of the country.
-
-	If the country or the state does not exists in the tables,
-
-	the function fails.
-
-	At first, the urb is tried to be retrieved according to the
-
-	supplied information. If the fields do not match exactly an
-
+        <p>This function takes a parameters the name of the urb,\n
+	the postcode of the urb, the name of the region and the\n
+	name of the country.\n
+	If the country or the region does not exists in the tables,\n
+	the function fails.\n
+	At first, the urb is tried to be retrieved according to the\n
+	supplied information. If the fields do not match exactly an\n
 	existing row, a new urb is created and returned.</p>
         <pre>
 DECLARE
 	_urb ALIAS FOR $1;
 	_urb_postcode ALIAS FOR $2;	
-	_state_code ALIAS FOR $3;
+	_region_code ALIAS FOR $3;
 	_country_code ALIAS FOR $4;
- 	_state_id integer;
+ 	_region_pk integer;
 	_urb_id integer;
 	msg text;
 BEGIN
- 	-- get state
- 	SELECT INTO _state_id s.id from dem.state s WHERE s.code = _state_code and s.country = _country_code;
+ 	-- get region
+ 	SELECT INTO _region_pk d_r.pk from dem.region d_r WHERE d_r.code = _region_code and d_r.country = _country_code;
  	IF NOT FOUND THEN
-		msg := 'combination of state + country not registered ['
+		msg := 'combination of region + country not registered ['
 			||   'country:' || coalesce(_country_code, 'NULL')
-			||   ', state:' || coalesce(_state_code, 'NULL')
+			||  ', region:' || coalesce(_region_code, 'NULL')
 			||     ', urb:' || coalesce(_urb, 'NULL')
 			|| ', urb_zip:' || coalesce(_urb_postcode, 'NULL')
 			|| ']';
 		RAISE EXCEPTION '=> %', msg;
  	END IF;
 	-- get/create and return urb
-	SELECT INTO _urb_id u.id from dem.urb u WHERE u.name ILIKE _urb AND u.id_state = _state_id;
+	SELECT INTO _urb_id u.id from dem.urb u WHERE u.name ILIKE _urb AND u.fk_region = _region_pk;
 	IF FOUND THEN
 		RETURN _urb_id;
 	END IF;
-	INSERT INTO dem.urb (name, postcode, id_state) VALUES (_urb, _urb_postcode, _state_id);
+	INSERT INTO dem.urb (name, postcode, fk_region) VALUES (_urb, _urb_postcode, _region_pk);
 	RETURN currval('dem.urb_id_seq');
 END;</pre>
 	
@@ -106733,31 +126356,31 @@ END;</pre>
 	
 		<hr>
 		<h2>Function:
-			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.function.gm-upd-default-states">gm_upd_default_states()</a>
+			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.function.gm-upd-default-regions">gm_upd_default_regions()</a>
 		</h2>
 <h3>Returns: boolean</h3>
 <h3>Language: PLPGSQL</h3>
         
         <pre>
 declare
-	_state_code text;
-	_state_name text;
+	_region_code text;
+	_region_name text;
 	_country_row record;
 begin
-	_state_code := '??';
-	_state_name := 'state/territory/province/region not available';
-	-- add default state to countries needing one
+	_region_code := '??';
+	_region_name := 'state/territory/province/region not available';
+	-- add default region to countries needing one
 	for _country_row in
 		select distinct code from dem.country
 		where code not in (
-			select country from dem.state where code = _state_code
+			select country from dem.region where code = _region_code
 		)
 	loop
-		raise notice 'adding default state for [%]', _country_row.code;
-		execute 'insert into dem.state (code, country, name) values ('
-				|| quote_literal(_state_code) || ', '
+		raise notice 'adding default region for [%]', _country_row.code;
+		execute 'insert into dem.region (code, country, name) values ('
+				|| quote_literal(_region_code) || ', '
 				|| quote_literal(_country_row.code) || ', '
-				|| quote_literal(_state_name) || ');';
+				|| quote_literal(_region_name) || ');';
 	end loop;
 	return true;
 end;
@@ -106765,20 +126388,6 @@ end;
 	
 		<hr>
 		<h2>Function:
-			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.function.new-pupic">new_pupic()</a>
-		</h2>
-<h3>Returns: bpchar</h3>
-<h3>Language: PLPGSQL</h3>
-        
-        <pre>
-DECLARE
-BEGIN
-   -- how does this work? How do we get new 'unique' numbers?
-   RETURN '0000000000';
-END;</pre>
-	
-		<hr>
-		<h2>Function:
 			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.function.remove-person-integer">remove_person(integer)</a>
 		</h2>
 <h3>Returns: boolean</h3>
@@ -106928,6 +126537,37 @@ end;</pre>
 	
 		<hr>
 		<h2>Function:
+			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.function.trf-prevent-deletion-of-in-use-staff">trf_prevent_deletion_of_in_use_staff()</a>
+		</h2>
+<h3>Returns: trigger</h3>
+<h3>Language: PLPGSQL</h3>
+        <p>this function is used to prevent DELETEs of staff members which had been used to store data</p>
+        <pre>
+BEGIN
+	-- does any audited table contain the dem.staff.db_user we are about to delete ?
+	PERFORM 1 FROM audit.audit_fields WHERE modified_by = OLD.db_user LIMIT 1;
+	IF FOUND THEN
+		RAISE EXCEPTION
+			'DELETE from dem.staff: Sanity check failed. User <%> is referenced from <.modified_by> of at least one audited table.', OLD.db_user
+			USING ERRCODE = 'foreign_key_violation'
+		;
+		RETURN NULL;
+	END IF;
+	-- does any audit table contain the dem.staff.db_user we are about to delete ?
+	PERFORM 1 FROM audit.audit_trail WHERE orig_by = OLD.db_user OR audit_by = OLD.db_user LIMIT 1;
+	IF FOUND THEN
+		RAISE EXCEPTION
+			'DELETE from dem.staff: Sanity check failed. User <%> is referenced from <.orig_by> or <.audit_by> of at least one audit table.', OLD.db_user
+			USING ERRCODE = 'foreign_key_violation'
+		;
+		RETURN NULL;
+	END IF;
+	RETURN OLD;
+END;
+</pre>
+	
+		<hr>
+		<h2>Function:
 			<a href="gnumed-entire_schema.html#dem.schema">dem</a>.<a name="dem.function.trf-prevent-multiple-praxi">trf_prevent_multiple_praxi()</a>
 		</h2>
 <h3>Returns: trigger</h3>
@@ -107086,11 +126726,19 @@ END;</pre>
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -107165,6 +126813,11 @@ END;</pre>
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>non_empty_user_action</td>
                 <td>CHECK ((gm.is_null_or_blank_string(user_action) IS FALSE))</td>
             </tr>
@@ -107438,6 +127091,45 @@ END;</pre>
 	
 		<hr>
 		<h2>Function:
+			<a href="gnumed-entire_schema.html#gm.schema">gm</a>.<a name="gm.function.account-is-dbowner-or-staff-account-name">account_is_dbowner_or_staff(_account name)</a>
+		</h2>
+<h3>Returns: boolean</h3>
+<h3>Language: PLPGSQL</h3>
+        
+        <pre>
+DECLARE
+	_is_owner boolean;
+BEGIN
+	-- is _account member of current db group ?
+--	PERFORM 1 FROM pg_auth_members
+--	WHERE
+--		roleid = (SELECT oid FROM pg_roles WHERE rolname = current_database())
+--			AND
+--		member = (SELECT oid FROM pg_roles WHERE rolname = _account)
+--	;
+--	IF FOUND THEN
+--		-- should catch people on staff, gm-dbo, and postgres
+--		RETURN TRUE;
+--	END IF;
+	-- postgres
+	IF _account = 'postgres' THEN
+		RETURN TRUE;
+	END IF;
+	-- on staff list
+	PERFORM 1 FROM dem.staff WHERE db_user = _account;
+	IF FOUND THEN
+		RETURN TRUE;
+	END IF;
+	-- owner
+	SELECT pg_catalog.pg_get_userbyid(datdba) = _account INTO STRICT _is_owner FROM pg_catalog.pg_database WHERE datname = current_database();
+	IF _is_owner IS TRUE THEN
+		RETURN TRUE;
+	END IF;
+	RETURN FALSE;
+END;</pre>
+	
+		<hr>
+		<h2>Function:
 			<a href="gnumed-entire_schema.html#gm.schema">gm</a>.<a name="gm.function.add-missing-array-bits">add_missing_array_bits()</a>
 		</h2>
 <h3>Returns: boolean</h3>
@@ -108222,7 +127914,7 @@ BEGIN
 		raise exception undefined_table;
 		return false;
 	end if;
-	-- verify points to clin.encounter.pk
+	-- verify that it points to clin.encounter.pk
 	if not exists (
 		select 1
 		from
@@ -108250,11 +127942,13 @@ BEGIN
 					col_tbl.attrelid = _qualified_table2check::regclass
 			)
 	) then
-		raise warning 'gm.create_enc_epi_sanity_check_trigger(): <%.%> does not point to clin.encounter.pk', _qualified_table2check, _fk_encounter_col;
-		raise exception invalid_foreign_key;
+		raise exception
+			'gm.create_enc_epi_sanity_check_trigger(): <%.%> does not point to clin.encounter.pk', _qualified_table2check, _fk_encounter_col
+			USING ERRCODE = 'invalid_foreign_key'
+		;
 		return false;
 	end if;
-	-- verify points to clin.episode.pk
+	-- verify that it points to clin.episode.pk
 	if not exists (
 		select 1
 		from
@@ -108282,13 +127976,12 @@ BEGIN
 					col_tbl.attrelid = _qualified_table2check::regclass
 			)
 	) then
-		raise warning 'gm.create_enc_epi_sanity_check_trigger(): <%.%> does not point to clin.episode.pk', _qualified_table2check, _fk_episode_col;
-		raise exception invalid_foreign_key;
+		raise exception
+			'gm.create_enc_epi_sanity_check_trigger(): <%.%> does not point to clin.episode.pk', _qualified_table2check, _fk_episode_col
+			USING ERRCODE = 'invalid_foreign_key'
+		;
 		return false;
 	end if;
-	-- drop old trigger (remove in v21)
-	_cmd := 'drop trigger if exists tr_sanity_check_enc_epi_insert on ' || _qualified_table2check || ' cascade';
-	execute _cmd;
 	-- re-create trigger
 	_cmd := 'drop trigger if exists tr_sanity_check_enc_epi_ins_upd on ' || _qualified_table2check || ' cascade';
 	execute _cmd;
@@ -108805,6 +128498,47 @@ input is not NULL and not empty -> FALSE</p>
 	
 		<hr>
 		<h2>Function:
+			<a href="gnumed-entire_schema.html#gm.schema">gm</a>.<a name="gm.function.lo-chunked-md5-oid-integer">lo_chunked_md5(oid, integer)</a>
+		</h2>
+<h3>Returns: text</h3>
+<h3>Language: PLPGSQL</h3>
+        <p>Function to create a chunked md5 sum on arbitrarily large LARGE OBJECTs.</p>
+        <pre>
+DECLARE
+	lo_id alias for $1;
+	chunk_size alias for $2;
+	_lo_fd integer;
+	_lo_size integer;
+	_chunk_count integer;
+	_remainder integer;
+	_md5_concat text;
+	INV_READ constant integer := x'40000'::integer;
+	SEEK_SET constant integer := 0;
+	SEEK_END constant integer := 2;
+BEGIN
+	-- check for existence of lo_id ?
+	_lo_fd := lo_open(lo_id, INV_READ);
+	-- get size
+	_lo_size := lo_lseek(_lo_fd, 0, SEEK_END);
+	PERFORM lo_close(_lo_fd);						-- move further down if loread() proves faster
+	-- calculate chunks and remainder
+	_chunk_count := _lo_size / chunk_size;
+	_remainder := _lo_size % chunk_size;
+	-- loop over chunks
+	_md5_concat := '';
+	FOR _chunk_id in 1.._chunk_count LOOP
+		_md5_concat := _md5_concat || md5(lo_get(lo_id, (_chunk_id - 1) * chunk_size, chunk_size));
+		-- using loread() may be faster (as it directly accesses the
+		-- existing lo_fd and thusly does not need to re-open the LO
+		-- each round)
+	END LOOP;
+	-- add remainder
+	_md5_concat := _md5_concat || md5(lo_get(lo_id, _chunk_count * chunk_size, _remainder));
+	return md5(_md5_concat);
+END;</pre>
+	
+		<hr>
+		<h2>Function:
 			<a href="gnumed-entire_schema.html#gm.schema">gm</a>.<a name="gm.function.log-access2emr-text">log_access2emr(text)</a>
 		</h2>
 <h3>Returns: void</h3>
@@ -109554,17 +129288,23 @@ END;</pre>
 	
 	<pre>
 SELECT icl.lang
-, ik.orig 
+,
+    ik.orig
+   
 FROM (
 SELECT DISTINCT 
-    ON (curr_lang.lang) curr_lang.lang 
+    ON (curr_lang.lang) curr_lang.lang
+           
   FROM i18n.curr_lang
 ) icl
-, i18n.keys ik 
+,
+    i18n.keys ik
+  
 WHERE (NOT 
      (ik.orig IN 
            (
-            SELECT translations.orig 
+            SELECT translations.orig
+           
               FROM i18n.translations
            )
      )
@@ -109862,6 +129602,190 @@ begin
 end;</pre>
 	
 
+<!-- pgtrgmpgtrgm -->
+
+		
+		<hr>
+		<h1>Schema pgtrgm</h1>
+		
+
+		
+		
+
+	<!-- We've gone through the table structure, now lets take a look at user functions -->
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#pgtrgm.schema">pgtrgm</a>.<a name="pgtrgm.function.gin-extract-query-trgm-text-internal-smallint-internal-internal-internal-internal">gin_extract_query_trgm(text, internal, smallint, internal, internal, internal, internal)</a>
+		</h2>
+<h3>Returns: internal</h3>
+<h3>Language: C</h3>
+        
+        <pre>gin_extract_query_trgm</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#pgtrgm.schema">pgtrgm</a>.<a name="pgtrgm.function.gin-extract-value-trgm-text-internal">gin_extract_value_trgm(text, internal)</a>
+		</h2>
+<h3>Returns: internal</h3>
+<h3>Language: C</h3>
+        
+        <pre>gin_extract_value_trgm</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#pgtrgm.schema">pgtrgm</a>.<a name="pgtrgm.function.gin-trgm-consistent-internal-smallint-text-integer-internal-internal-internal-internal">gin_trgm_consistent(internal, smallint, text, integer, internal, internal, internal, internal)</a>
+		</h2>
+<h3>Returns: boolean</h3>
+<h3>Language: C</h3>
+        
+        <pre>gin_trgm_consistent</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#pgtrgm.schema">pgtrgm</a>.<a name="pgtrgm.function.gtrgm-compress-internal">gtrgm_compress(internal)</a>
+		</h2>
+<h3>Returns: internal</h3>
+<h3>Language: C</h3>
+        
+        <pre>gtrgm_compress</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#pgtrgm.schema">pgtrgm</a>.<a name="pgtrgm.function.gtrgm-consistent-internal-text-integer-oid-internal">gtrgm_consistent(internal, text, integer, oid, internal)</a>
+		</h2>
+<h3>Returns: boolean</h3>
+<h3>Language: C</h3>
+        
+        <pre>gtrgm_consistent</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#pgtrgm.schema">pgtrgm</a>.<a name="pgtrgm.function.gtrgm-decompress-internal">gtrgm_decompress(internal)</a>
+		</h2>
+<h3>Returns: internal</h3>
+<h3>Language: C</h3>
+        
+        <pre>gtrgm_decompress</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#pgtrgm.schema">pgtrgm</a>.<a name="pgtrgm.function.gtrgm-distance-internal-text-integer-oid">gtrgm_distance(internal, text, integer, oid)</a>
+		</h2>
+<h3>Returns: double precision</h3>
+<h3>Language: C</h3>
+        
+        <pre>gtrgm_distance</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#pgtrgm.schema">pgtrgm</a>.<a name="pgtrgm.function.gtrgm-in-cstring">gtrgm_in(cstring)</a>
+		</h2>
+<h3>Returns: gtrgm</h3>
+<h3>Language: C</h3>
+        
+        <pre>gtrgm_in</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#pgtrgm.schema">pgtrgm</a>.<a name="pgtrgm.function.gtrgm-out-pgtrgm.gtrgm">gtrgm_out(pgtrgm.gtrgm)</a>
+		</h2>
+<h3>Returns: cstring</h3>
+<h3>Language: C</h3>
+        
+        <pre>gtrgm_out</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#pgtrgm.schema">pgtrgm</a>.<a name="pgtrgm.function.gtrgm-penalty-internal-internal-internal">gtrgm_penalty(internal, internal, internal)</a>
+		</h2>
+<h3>Returns: internal</h3>
+<h3>Language: C</h3>
+        
+        <pre>gtrgm_penalty</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#pgtrgm.schema">pgtrgm</a>.<a name="pgtrgm.function.gtrgm-picksplit-internal-internal">gtrgm_picksplit(internal, internal)</a>
+		</h2>
+<h3>Returns: internal</h3>
+<h3>Language: C</h3>
+        
+        <pre>gtrgm_picksplit</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#pgtrgm.schema">pgtrgm</a>.<a name="pgtrgm.function.gtrgm-same-pgtrgm.gtrgm-pgtrgm.gtrgm-internal">gtrgm_same(pgtrgm.gtrgm, pgtrgm.gtrgm, internal)</a>
+		</h2>
+<h3>Returns: internal</h3>
+<h3>Language: C</h3>
+        
+        <pre>gtrgm_same</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#pgtrgm.schema">pgtrgm</a>.<a name="pgtrgm.function.gtrgm-union-bytea-internal">gtrgm_union(bytea, internal)</a>
+		</h2>
+<h3>Returns: integer[]</h3>
+<h3>Language: C</h3>
+        
+        <pre>gtrgm_union</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#pgtrgm.schema">pgtrgm</a>.<a name="pgtrgm.function.set-limit-real">set_limit(real)</a>
+		</h2>
+<h3>Returns: real</h3>
+<h3>Language: C</h3>
+        
+        <pre>set_limit</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#pgtrgm.schema">pgtrgm</a>.<a name="pgtrgm.function.show-limit">show_limit()</a>
+		</h2>
+<h3>Returns: real</h3>
+<h3>Language: C</h3>
+        
+        <pre>show_limit</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#pgtrgm.schema">pgtrgm</a>.<a name="pgtrgm.function.show-trgm-text">show_trgm(text)</a>
+		</h2>
+<h3>Returns: text[]</h3>
+<h3>Language: C</h3>
+        
+        <pre>show_trgm</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#pgtrgm.schema">pgtrgm</a>.<a name="pgtrgm.function.similarity-text-text">similarity(text, text)</a>
+		</h2>
+<h3>Returns: real</h3>
+<h3>Language: C</h3>
+        
+        <pre>similarity</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#pgtrgm.schema">pgtrgm</a>.<a name="pgtrgm.function.similarity-dist-text-text">similarity_dist(text, text)</a>
+		</h2>
+<h3>Returns: real</h3>
+<h3>Language: C</h3>
+        
+        <pre>similarity_dist</pre>
+	
+		<hr>
+		<h2>Function:
+			<a href="gnumed-entire_schema.html#pgtrgm.schema">pgtrgm</a>.<a name="pgtrgm.function.similarity-op-text-text">similarity_op(text, text)</a>
+		</h2>
+<h3>Returns: boolean</h3>
+<h3>Language: C</h3>
+        
+        <pre>similarity_op</pre>
+	
+
 <!-- publicpublic -->
 
 		
@@ -112066,11 +131990,19 @@ end;
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -112230,6 +132162,22 @@ end;
 				</td>
 			 </tr>
             
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>recommendation_query</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
         </table>
 
         <!-- Inherits -->
@@ -112257,20 +132205,30 @@ end;
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>ref_auto_hint_sane_hint</td>
                 <td>CHECK ((gm.is_null_or_blank_string(hint) IS FALSE))</td>
             </tr>
 			
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>ref_auto_hint_sane_lang</td>
                 <td>CHECK ((gm.is_null_or_blank_string(lang) IS FALSE))</td>
             </tr>
 			
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>ref_auto_hint_sane_query</td>
                 <td>CHECK ((gm.is_null_or_blank_string(query) IS FALSE))</td>
             </tr>
 			
+            <tr class="tr0">
+				<td>ref_auto_hint_sane_rec_query</td>
+                <td>CHECK (gm.is_null_or_non_empty_string(recommendation_query))</td>
+            </tr>
+			
             <tr class="tr1">
 				<td>ref_auto_hint_sane_source</td>
                 <td>CHECK ((gm.is_null_or_blank_string(source) IS FALSE))</td>
@@ -112669,11 +132627,19 @@ end;
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -112855,26 +132821,31 @@ end;
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>desc_not_empty</td>
                 <td>CHECK ((gm.is_null_or_blank_string(description) IS FALSE))</td>
             </tr>
 			
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>drug_sane_external_code</td>
                 <td>CHECK ((gm.is_null_or_non_empty_string(external_code) IS TRUE))</td>
             </tr>
 			
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>drug_sane_external_code_type</td>
                 <td>CHECK ((((external_code IS NULL) AND (external_code_type IS NULL)) OR ((external_code IS NOT NULL) AND (external_code_type IS NOT NULL))))</td>
             </tr>
 			
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>prep_not_empty</td>
                 <td>CHECK ((gm.is_null_or_blank_string(preparation) IS FALSE))</td>
             </tr>
 			
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>sane_atc</td>
                 <td>CHECK ((gm.is_null_or_non_empty_string(atc_code) IS TRUE))</td>
             </tr>
@@ -113480,11 +133451,19 @@ end;
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -113636,21 +133615,26 @@ not the use/application formulation thereof.
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>ref_consumable_sane_amount</td>
                 <td>CHECK ((amount >= (0)::numeric))</td>
             </tr>
 			
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>ref_consumable_sane_unit</td>
                 <td>CHECK ((gm.is_null_or_blank_string(unit) IS FALSE))</td>
             </tr>
 			
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>ref_subst_sane_atc</td>
                 <td>CHECK ((gm.is_null_or_non_empty_string(atc_code) IS TRUE))</td>
             </tr>
 			
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>ref_subst_sane_desc</td>
                 <td>CHECK ((gm.is_null_or_blank_string(description) IS FALSE))</td>
             </tr>
@@ -113756,11 +133740,19 @@ not the use/application formulation thereof.
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -113939,6 +133931,21 @@ not the use/application formulation thereof.
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>ref.data_source Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
@@ -115761,11 +135768,19 @@ If NULL: applies to all providers.
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -115879,6 +135894,21 @@ If NULL: applies to all providers.
 
         <!-- Constraint List -->
 		
+        <p> </p>
+		<table width="100%" cellspacing="0" cellpadding="3">
+            <caption>ref.lnk_substance2brand Constraints</caption>
+            <tr>
+            	<th>Name</th>
+            	<th>Constraint</th>
+            </tr>
+			
+            <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+		</table>
+		
 
         <!-- Foreign Key Discovery -->
 		
@@ -117334,11 +137364,19 @@ If NULL: applies to all providers.
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -117641,6 +137679,11 @@ If NULL: applies to all providers.
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>ref_templates_engine_range</td>
                 <td>CHECK ((engine = ANY (ARRAY['T'::text, 'L'::text, 'H'::text, 'O'::text, 'I'::text, 'G'::text, 'P'::text, 'A'::text, 'X'::text, 'S'::text])))</td>
             </tr>
@@ -117746,11 +137789,19 @@ If NULL: applies to all providers.
             <tr class="tr1">
 				<td>
                 
+                  
+                  <a href="gnumed-entire_schema.html#dem.table.staff">dem.staff.db_user</a>
+                  
+                
                 </td>
             	<td>modified_by</td>
             	<td>name</td>
                 <td><i>
 				
+					
+
+					
+				
 
 				NOT NULL
 				DEFAULT "current_user"()
@@ -117865,11 +137916,16 @@ If NULL: applies to all providers.
             </tr>
 			
             <tr class="tr0">
+				<td>audit_audit_fields_sane_modified_when</td>
+                <td>CHECK (((modified_when <= clock_timestamp()) IS TRUE))</td>
+            </tr>
+			
+            <tr class="tr1">
 				<td>ref_tag_image_sane_desc</td>
                 <td>CHECK ((gm.is_null_or_blank_string(description) IS FALSE))</td>
             </tr>
 			
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>ref_tag_image_sane_filename</td>
                 <td>CHECK ((gm.is_null_or_non_empty_string(filename) IS TRUE))</td>
             </tr>
@@ -118146,26 +138202,42 @@ If NULL: applies to all providers.
 	
 	<pre>
 SELECT a.pk AS pk_atc
-, a.code AS atc
-, a.term
-, a.administration_route
-, a.comment
-, (octet_length
+,
+    a.code AS atc
+,
+    a.term
+,
+    a.administration_route
+,
+    a.comment
+,
+    
+(octet_length
      (a.code) < 7
 ) AS is_group_code
-, (octet_length
+,
+    
+(octet_length
      (a.code) - 
      (octet_length
            (a.code) / 3
      )
 ) AS atc_level
-, rds.name_long
-, rds.name_short
-, rds.version
-, rds.lang
-, a.pk_coding_system
-, a.fk_data_source AS pk_data_source 
-FROM (ref.atc a 
+,
+    rds.name_long
+,
+    rds.name_short
+,
+    rds.version
+,
+    rds.lang
+,
+    a.pk_coding_system
+,
+    a.fk_data_source AS pk_data_source
+   
+FROM (ref.atc a
+     
   JOIN ref.data_source rds 
     ON (
            (rds.pk = a.fk_data_source)
@@ -118234,7 +138306,7 @@ FROM (ref.atc a
 				<td>
                 
                 </td>
-            	<td>title</td>
+            	<td>recommendation_query</td>
             	<td>text</td>
                 <td><i>
 				
@@ -118250,7 +138322,7 @@ FROM (ref.atc a
 				<td>
                 
                 </td>
-            	<td>hint</td>
+            	<td>title</td>
             	<td>text</td>
                 <td><i>
 				
@@ -118266,7 +138338,7 @@ FROM (ref.atc a
 				<td>
                 
                 </td>
-            	<td>url</td>
+            	<td>hint</td>
             	<td>text</td>
                 <td><i>
 				
@@ -118282,6 +138354,22 @@ FROM (ref.atc a
 				<td>
                 
                 </td>
+            	<td>url</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
             	<td>is_active</td>
             	<td>boolean</td>
                 <td><i>
@@ -118294,7 +138382,7 @@ FROM (ref.atc a
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -118310,7 +138398,7 @@ FROM (ref.atc a
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -118326,7 +138414,7 @@ FROM (ref.atc a
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -118342,6 +138430,22 @@ FROM (ref.atc a
 				</td>
 			 </tr>
             
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>recommendation</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
             <tr class="tr1">
 				<td>
                 
@@ -118394,21 +138498,39 @@ FROM (ref.atc a
 	
 	<pre>
 SELECT auto_hint.pk AS pk_auto_hint
-, auto_hint.query
-, auto_hint.title
-, auto_hint.hint
-, auto_hint.url
-, auto_hint.is_active
-, auto_hint.source
-, auto_hint.lang
-, NULL::text AS rationale4suppression
-, md5
+,
+    auto_hint.query
+,
+    auto_hint.recommendation_query
+,
+    auto_hint.title
+,
+    auto_hint.hint
+,
+    auto_hint.url
+,
+    auto_hint.is_active
+,
+    auto_hint.source
+,
+    auto_hint.lang
+,
+    NULL::text AS rationale4suppression
+,
+    NULL::text AS recommendation
+,
+    md5
 (
      (
            (
-                 (COALESCE
-                       (auto_hint.query
-                             ,''::text
+                 (
+                       (COALESCE
+                             (auto_hint.query
+                                   ,''::text
+                             ) || COALESCE
+                             (auto_hint.recommendation_query
+                                   ,''::text
+                             )
                        ) || COALESCE
                        (auto_hint.title
                              ,''::text
@@ -118423,7 +138545,9 @@ SELECT auto_hint.pk AS pk_auto_hint
            )
      )
 ) AS md5_sum
-, auto_hint.xmin AS xmin_auto_hint 
+,
+    auto_hint.xmin AS xmin_auto_hint
+   
 FROM ref.auto_hint;</pre>
 	
 
@@ -118744,25 +138868,44 @@ FROM ref.auto_hint;</pre>
 	
 	<pre>
 SELECT r_b.pk AS pk_billable
-, r_b.code AS billable_code
-, r_b.term AS billable_description
-, r_b.amount AS raw_amount
-, (r_b.amount + 
+,
+    r_b.code AS billable_code
+,
+    r_b.term AS billable_description
+,
+    r_b.amount AS raw_amount
+,
+    
+(r_b.amount + 
      (r_b.amount * r_b.vat_multiplier)
 ) AS amount_with_vat
-, r_b.currency
-, r_b.comment
-, r_b.vat_multiplier
-, r_b.active
-, r_b.discountable
-, r_ds.name_long AS catalog_long
-, r_ds.name_short AS catalog_short
-, r_ds.version AS catalog_version
-, r_ds.lang AS catalog_language
-, r_b.fk_data_source AS pk_data_source
-, r_b.pk_coding_system AS pk_coding_system_root
-, r_b.xmin AS xmin_billable 
-FROM (ref.billable r_b 
+,
+    r_b.currency
+,
+    r_b.comment
+,
+    r_b.vat_multiplier
+,
+    r_b.active
+,
+    r_b.discountable
+,
+    r_ds.name_long AS catalog_long
+,
+    r_ds.name_short AS catalog_short
+,
+    r_ds.version AS catalog_version
+,
+    r_ds.lang AS catalog_language
+,
+    r_b.fk_data_source AS pk_data_source
+,
+    r_b.pk_coding_system AS pk_coding_system_root
+,
+    r_b.xmin AS xmin_billable
+   
+FROM (ref.billable r_b
+     
 LEFT JOIN ref.data_source r_ds 
     ON (
            (r_b.fk_data_source = r_ds.pk)
@@ -119007,13 +139150,21 @@ LEFT JOIN ref.data_source r_ds
 	
 	<pre>
 SELECT r_bd.pk AS pk_brand
-, r_bd.description AS brand
-, r_bd.preparation
-, r_bd.atc_code AS atc
-, r_bd.external_code
-, r_bd.external_code_type
-, r_bd.is_fake AS is_fake_brand
-, (
+,
+    r_bd.description AS brand
+,
+    r_bd.preparation
+,
+    r_bd.atc_code AS atc
+,
+    r_bd.external_code
+,
+    r_bd.external_code_type
+,
+    r_bd.is_fake AS is_fake_brand
+,
+    
+(
 SELECT array_agg
      (
            (
@@ -119030,29 +139181,43 @@ SELECT array_agg
                        ,''::text
                  )
            )
-     ) AS array_agg 
-  FROM (ref.lnk_substance2brand r_ls2b 
+     ) AS array_agg
+           
+  FROM (ref.lnk_substance2brand r_ls2b
+             
         JOIN ref.consumable_substance r_cs 
           ON (
                  (r_ls2b.fk_substance = r_cs.pk)
            )
      )
+          
  WHERE (r_ls2b.fk_brand = r_bd.pk)
 ) AS components
-, (
+,
+    
+(
 SELECT array_agg
-     (r_ls2b.pk) AS array_agg 
-  FROM ref.lnk_substance2brand r_ls2b 
+     (r_ls2b.pk) AS array_agg
+           
+  FROM ref.lnk_substance2brand r_ls2b
+          
  WHERE (r_ls2b.fk_brand = r_bd.pk)
 ) AS pk_components
-, (
+,
+    
+(
 SELECT array_agg
-     (r_ls2b.fk_substance) AS array_agg 
-  FROM ref.lnk_substance2brand r_ls2b 
+     (r_ls2b.fk_substance) AS array_agg
+           
+  FROM ref.lnk_substance2brand r_ls2b
+          
  WHERE (r_ls2b.fk_brand = r_bd.pk)
 ) AS pk_substances
-, r_bd.fk_data_source AS pk_data_source
-, r_bd.xmin AS xmin_branded_drug 
+,
+    r_bd.fk_data_source AS pk_data_source
+,
+    r_bd.xmin AS xmin_branded_drug
+   
 FROM ref.branded_drug r_bd;</pre>
 	
 
@@ -119215,32 +139380,51 @@ FROM ref.branded_drug r_bd;</pre>
 	
 	<pre>
 SELECT r_csr.code
-, r_csr.term
-, r_ds.name_short AS coding_system
-, r_ds.name_long AS coding_system_long
-, r_ds.version
-, r_ds.lang
-, r_csr.pk_coding_system AS pk_generic_code 
-FROM (ref.coding_system_root r_csr 
+,
+    r_csr.term
+,
+    r_ds.name_short AS coding_system
+,
+    r_ds.name_long AS coding_system_long
+,
+    r_ds.version
+,
+    r_ds.lang
+,
+    r_csr.pk_coding_system AS pk_generic_code
+   
+FROM (ref.coding_system_root r_csr
+     
   JOIN ref.data_source r_ds 
     ON (
            (r_csr.fk_data_source = r_ds.pk)
      )
 )
-UNIONSELECT ri.code
-, r_it.synonym AS term
-, r_ds.name_short AS coding_system
-, r_ds.name_long AS coding_system_long
-, r_ds.version
-, r_ds.lang
-, r_it.fk_code AS pk_generic_code 
+UNION
+ 
+SELECT ri.code
+,
+    r_it.synonym AS term
+,
+    r_ds.name_short AS coding_system
+,
+    r_ds.name_long AS coding_system_long
+,
+    r_ds.version
+,
+    r_ds.lang
+,
+    r_it.fk_code AS pk_generic_code
+   
 FROM (
-     (ref.icpc_thesaurus r_it 
+     (ref.icpc_thesaurus r_it
+     
    LEFT JOIN ref.icpc ri 
           ON (
                  (r_it.fk_code = ri.pk_coding_system)
            )
      )
+     
 LEFT JOIN ref.data_source r_ds 
     ON (
            (ri.fk_data_source = r_ds.pk)
@@ -119549,34 +139733,56 @@ LEFT JOIN ref.data_source r_ds
 	
 	<pre>
 SELECT r_ls2b.pk AS pk_component
-, r_bd.description AS brand
-, r_cs.description AS substance
-, r_cs.amount
-, r_cs.unit
-, r_bd.preparation
-, r_cs.atc_code AS atc_substance
-, r_bd.atc_code AS atc_brand
-, r_bd.external_code AS external_code_brand
-, r_bd.external_code_type AS external_code_type_brand
-, r_bd.is_fake AS is_fake_brand
-, (EXISTS 
+,
+    r_bd.description AS brand
+,
+    r_cs.description AS substance
+,
+    r_cs.amount
+,
+    r_cs.unit
+,
+    r_bd.preparation
+,
+    r_cs.atc_code AS atc_substance
+,
+    r_bd.atc_code AS atc_brand
+,
+    r_bd.external_code AS external_code_brand
+,
+    r_bd.external_code_type AS external_code_type_brand
+,
+    r_bd.is_fake AS is_fake_brand
+,
+    
+(EXISTS 
      (
-      SELECT 1 
-        FROM clin.substance_intake c_si 
-       WHERE (c_si.fk_drug_component = r_ls2b.pk) LIMIT 1
+      SELECT 1
+           
+        FROM clin.substance_intake c_si
+          
+       WHERE (c_si.fk_drug_component = r_ls2b.pk)
+         LIMIT 1
      )
 ) AS is_in_use
-, r_ls2b.fk_brand AS pk_brand
-, r_cs.pk AS pk_consumable_substance
-, r_bd.fk_data_source AS pk_data_source
-, r_ls2b.xmin AS xmin_lnk_substance2brand 
+,
+    r_ls2b.fk_brand AS pk_brand
+,
+    r_cs.pk AS pk_consumable_substance
+,
+    r_bd.fk_data_source AS pk_data_source
+,
+    r_ls2b.xmin AS xmin_lnk_substance2brand
+   
 FROM (
-     (ref.consumable_substance r_cs 
+     (ref.consumable_substance r_cs
+     
         JOIN ref.lnk_substance2brand r_ls2b 
           ON (
                  (r_cs.pk = r_ls2b.fk_substance)
            )
      )
+     
 LEFT JOIN ref.branded_drug r_bd 
     ON (
            (r_ls2b.fk_brand = r_bd.pk)
@@ -119775,15 +139981,26 @@ LEFT JOIN ref.branded_drug r_bd
 	
 	<pre>
 SELECT r_csr.pk_coding_system AS pk_generic_code
-, r_csr.code
-, r_csr.term
-, r_ds.name_long
-, r_ds.name_short
-, r_ds.version
-, r_ds.lang
-, (r_csr.tableoid)::regclass AS code_table
-, r_csr.fk_data_source AS pk_data_source 
-FROM (ref.coding_system_root r_csr 
+,
+    r_csr.code
+,
+    r_csr.term
+,
+    r_ds.name_long
+,
+    r_ds.name_short
+,
+    r_ds.version
+,
+    r_ds.lang
+,
+    
+(r_csr.tableoid)::regclass AS code_table
+,
+    r_csr.fk_data_source AS pk_data_source
+   
+FROM (ref.coding_system_root r_csr
+     
   JOIN ref.data_source r_ds 
     ON (
            (r_ds.pk = r_csr.fk_data_source)
@@ -120222,48 +140439,76 @@ FROM (ref.coding_system_root r_csr
 	
 	<pre>
 SELECT ri.code
-, ri.code_extension
-, (ri.code || COALESCE
+,
+    ri.code_extension
+,
+    
+(ri.code || COALESCE
      (ri.code_extension
            ,''::text
      )
 ) AS extended_code
-, ri.term
-, ri.short_description
-, ri.fk_chapter AS code_chapter
-, rich.description AS chapter
-, _
+,
+    ri.term
+,
+    ri.short_description
+,
+    ri.fk_chapter AS code_chapter
+,
+    rich.description AS chapter
+,
+    _
 (rich.description) AS l10n_chapter
-, ri.fk_component AS code_component
-, rico.description AS component
-, _
+,
+    ri.fk_component AS code_component
+,
+    rico.description AS component
+,
+    _
 (rico.description) AS l10n_component
-, rico.typical_soap_cat
-, ri.icd10
-, ri.criteria
-, ri.inclusions
-, ri.exclusions
-, ri.see_also
-, ri.comment
-, rds.name_short
-, rds.name_long
-, rds.version
-, rds.lang
-, ri.pk AS pk_icpc
-, ri.fk_data_source AS pk_data_source 
+,
+    rico.typical_soap_cat
+,
+    ri.icd10
+,
+    ri.criteria
+,
+    ri.inclusions
+,
+    ri.exclusions
+,
+    ri.see_also
+,
+    ri.comment
+,
+    rds.name_short
+,
+    rds.name_long
+,
+    rds.version
+,
+    rds.lang
+,
+    ri.pk AS pk_icpc
+,
+    ri.fk_data_source AS pk_data_source
+   
 FROM (
      (
-           (ref.icpc ri 
+           (ref.icpc ri
+     
               JOIN ref.data_source rds 
                 ON (
                        (ri.fk_data_source = rds.pk)
                  )
            )
+     
         JOIN ref.icpc_chapter rich 
           ON (
                  (ri.fk_chapter = rich.chapter)
            )
      )
+     
   JOIN ref.icpc_component rico 
     ON (
            (ri.fk_component = rico.component)
@@ -120429,19 +140674,278 @@ FROM (
 	<!-- View Definition -->
 	
 	<pre>
-SELECT rit.pk AS pk_icpc_thesaurus
-, ri.code
-, ri.term
-, rit.synonym
-, rit.pk_thesaurus
-, rit.fk_code AS pk_coding_system
-, ri.pk AS pk_icpc 
-FROM (ref.icpc_thesaurus rit 
-  JOIN ref.icpc ri 
-    ON (
-           (rit.fk_code = ri.pk_coding_system)
-     )
-);</pre>
+SELECT rit.pk AS pk_icpc_thesaurus
+,
+    ri.code
+,
+    ri.term
+,
+    rit.synonym
+,
+    rit.pk_thesaurus
+,
+    rit.fk_code AS pk_coding_system
+,
+    ri.pk AS pk_icpc
+   
+FROM (ref.icpc_thesaurus rit
+     
+  JOIN ref.icpc ri 
+    ON (
+           (rit.fk_code = ri.pk_coding_system)
+     )
+);</pre>
+	
+
+	<!-- List off permissions -->
+	
+
+	<p>
+		<a href="gnumed-entire_schema.html#index">Index</a> -
+		<a href="gnumed-entire_schema.html#ref.schema">Schema ref</a>
+    </p>
+	
+        <hr>
+		<h2>View:
+			
+			<a href="gnumed-entire_schema.html#ref.schema">ref</a>.<a name="ref.view.v-keyword-expansions">v_keyword_expansions</a>
+		</h2>
+        
+         <p>Just a slightly more convenient view over expansions.</p>
+        
+
+
+        <table width="100%" cellspacing="0" cellpadding="3">
+                <caption>ref.v_keyword_expansions Structure</caption>
+                <tr>
+                <th>F-Key</th>
+                <th>Name</th>
+                <th>Type</th>
+                <th>Description</th>
+                </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>pk_expansion</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>pk_staff</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>keyword</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>expansion</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>is_encrypted</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>is_textual</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>data_size</td>
+            	<td>integer</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>public_expansion</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>private_expansion</td>
+            	<td>boolean</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr1">
+				<td>
+                
+                </td>
+            	<td>owner</td>
+            	<td>text</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+            <tr class="tr0">
+				<td>
+                
+                </td>
+            	<td>xmin_expansion</td>
+            	<td>xid</td>
+                <td><i>
+				
+
+				
+				
+				</i>
+				
+				</td>
+			 </tr>
+            
+        </table>
+
+        <!-- Inherits -->
+		
+
+		
+
+        <!-- Constraint List -->
+		
+
+        <!-- Foreign Key Discovery -->
+		
+
+    <!-- Indexes -->
+    
+
+	<!-- View Definition -->
+	
+	<pre>
+SELECT r_ke.pk AS pk_expansion
+,
+    r_ke.fk_staff AS pk_staff
+,
+    r_ke.keyword
+,
+    r_ke.textual_data AS expansion
+,
+    r_ke.encrypted AS is_encrypted
+,
+    
+(r_ke.binary_data IS NULL) AS is_textual
+,
+    octet_length
+(r_ke.binary_data) AS data_size
+,
+    
+(r_ke.fk_staff IS NULL) AS public_expansion
+,
+    
+(r_ke.fk_staff IS NOT NULL) AS private_expansion
+,
+    r_ke.owner
+,
+    r_ke.xmin AS xmin_expansion
+   
+FROM ref.keyword_expansion r_ke;</pre>
 	
 
 	<!-- List off permissions -->
@@ -120455,15 +140959,13 @@ FROM (ref.icpc_thesaurus rit
         <hr>
 		<h2>View:
 			
-			<a href="gnumed-entire_schema.html#ref.schema">ref</a>.<a name="ref.view.v-keyword-expansions">v_keyword_expansions</a>
+			<a href="gnumed-entire_schema.html#ref.schema">ref</a>.<a name="ref.view.v-paperwork-templates">v_paperwork_templates</a>
 		</h2>
         
-         <p>Just a slightly more convenient view over expansions.</p>
-        
 
 
         <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>ref.v_keyword_expansions Structure</caption>
+                <caption>ref.v_paperwork_templates Structure</caption>
                 <tr>
                 <th>F-Key</th>
                 <th>Name</th>
@@ -120475,23 +140977,7 @@ FROM (ref.icpc_thesaurus rit
 				<td>
                 
                 </td>
-            	<td>pk_expansion</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>pk_staff</td>
+            	<td>pk_paperwork_template</td>
             	<td>integer</td>
                 <td><i>
 				
@@ -120503,27 +140989,11 @@ FROM (ref.icpc_thesaurus rit
 				</td>
 			 </tr>
             
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>keyword</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
             <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>expansion</td>
+            	<td>name_short</td>
             	<td>text</td>
                 <td><i>
 				
@@ -120539,87 +141009,7 @@ FROM (ref.icpc_thesaurus rit
 				<td>
                 
                 </td>
-            	<td>is_encrypted</td>
-            	<td>boolean</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>is_textual</td>
-            	<td>boolean</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>data_size</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>public_expansion</td>
-            	<td>boolean</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>private_expansion</td>
-            	<td>boolean</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr1">
-				<td>
-                
-                </td>
-            	<td>owner</td>
+            	<td>name_long</td>
             	<td>text</td>
                 <td><i>
 				
@@ -120631,102 +141021,11 @@ FROM (ref.icpc_thesaurus rit
 				</td>
 			 </tr>
             
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>xmin_expansion</td>
-            	<td>xid</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-        </table>
-
-        <!-- Inherits -->
-		
-
-		
-
-        <!-- Constraint List -->
-		
-
-        <!-- Foreign Key Discovery -->
-		
-
-    <!-- Indexes -->
-    
-
-	<!-- View Definition -->
-	
-	<pre>
-SELECT r_ke.pk AS pk_expansion
-, r_ke.fk_staff AS pk_staff
-, r_ke.keyword
-, r_ke.textual_data AS expansion
-, r_ke.encrypted AS is_encrypted
-, (r_ke.binary_data IS NULL) AS is_textual
-, octet_length
-(r_ke.binary_data) AS data_size
-, (r_ke.fk_staff IS NULL) AS public_expansion
-, (r_ke.fk_staff IS NOT NULL) AS private_expansion
-, r_ke.owner
-, r_ke.xmin AS xmin_expansion 
-FROM ref.keyword_expansion r_ke;</pre>
-	
-
-	<!-- List off permissions -->
-	
-
-	<p>
-		<a href="gnumed-entire_schema.html#index">Index</a> -
-		<a href="gnumed-entire_schema.html#ref.schema">Schema ref</a>
-    </p>
-	
-        <hr>
-		<h2>View:
-			
-			<a href="gnumed-entire_schema.html#ref.schema">ref</a>.<a name="ref.view.v-paperwork-templates">v_paperwork_templates</a>
-		</h2>
-        
-
-
-        <table width="100%" cellspacing="0" cellpadding="3">
-                <caption>ref.v_paperwork_templates Structure</caption>
-                <tr>
-                <th>F-Key</th>
-                <th>Name</th>
-                <th>Type</th>
-                <th>Description</th>
-                </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
-            	<td>pk_paperwork_template</td>
-            	<td>integer</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
             <tr class="tr1">
 				<td>
                 
                 </td>
-            	<td>name_short</td>
+            	<td>external_version</td>
             	<td>text</td>
                 <td><i>
 				
@@ -120742,8 +141041,8 @@ FROM ref.keyword_expansion r_ke;</pre>
 				<td>
                 
                 </td>
-            	<td>name_long</td>
-            	<td>text</td>
+            	<td>gnumed_revision</td>
+            	<td>double precision</td>
                 <td><i>
 				
 
@@ -120758,22 +141057,6 @@ FROM ref.keyword_expansion r_ke;</pre>
 				<td>
                 
                 </td>
-            	<td>external_version</td>
-            	<td>text</td>
-                <td><i>
-				
-
-				
-				
-				</i>
-				
-				</td>
-			 </tr>
-            
-            <tr class="tr0">
-				<td>
-                
-                </td>
             	<td>template_type</td>
             	<td>text</td>
                 <td><i>
@@ -120786,7 +141069,7 @@ FROM ref.keyword_expansion r_ke;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -120802,7 +141085,7 @@ FROM ref.keyword_expansion r_ke;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -120818,7 +141101,7 @@ FROM ref.keyword_expansion r_ke;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -120834,7 +141117,7 @@ FROM ref.keyword_expansion r_ke;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -120850,7 +141133,7 @@ FROM ref.keyword_expansion r_ke;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -120866,7 +141149,7 @@ FROM ref.keyword_expansion r_ke;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -120882,7 +141165,7 @@ FROM ref.keyword_expansion r_ke;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -120898,7 +141181,7 @@ FROM ref.keyword_expansion r_ke;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -120914,7 +141197,7 @@ FROM ref.keyword_expansion r_ke;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -120930,7 +141213,7 @@ FROM ref.keyword_expansion r_ke;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -120946,7 +141229,7 @@ FROM ref.keyword_expansion r_ke;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr1">
+            <tr class="tr0">
 				<td>
                 
                 </td>
@@ -120962,7 +141245,7 @@ FROM ref.keyword_expansion r_ke;</pre>
 				</td>
 			 </tr>
             
-            <tr class="tr0">
+            <tr class="tr1">
 				<td>
                 
                 </td>
@@ -120998,51 +141281,82 @@ FROM ref.keyword_expansion r_ke;</pre>
 	
 	<pre>
 SELECT r_pt.pk AS pk_paperwork_template
-, r_pt.name_short
-, r_pt.name_long
-, r_pt.external_version
-, (
-SELECT form_types.name 
-  FROM ref.form_types 
- WHERE (form_types.pk = r_pt.fk_template_type)
+,
+    r_pt.name_short
+,
+    r_pt.name_long
+,
+    r_pt.external_version
+,
+    r_pt.gnumed_revision
+,
+    
+(
+SELECT r_ft.name
+           
+  FROM ref.form_types r_ft
+          
+ WHERE (r_ft.pk = r_pt.fk_template_type)
 ) AS template_type
-, (
+,
+    
+(
 SELECT _
-     (form_types.name) AS _ 
-  FROM ref.form_types 
- WHERE (form_types.pk = r_pt.fk_template_type)
+     (r_ft.name) AS _
+           
+  FROM ref.form_types r_ft
+          
+ WHERE (r_ft.pk = r_pt.fk_template_type)
 ) AS l10n_template_type
-, COALESCE
+,
+    COALESCE
 (r_pt.instance_type
      , (
-      SELECT form_types.name 
-        FROM ref.form_types 
-       WHERE (form_types.pk = r_pt.fk_template_type)
+      SELECT r_ft.name
+           
+        FROM ref.form_types r_ft
+          
+       WHERE (r_ft.pk = r_pt.fk_template_type)
      )
 ) AS instance_type
-, COALESCE
+,
+    COALESCE
 (_
      (r_pt.instance_type)
      , (
       SELECT _
-           (form_types.name) AS _ 
-        FROM ref.form_types 
-       WHERE (form_types.pk = r_pt.fk_template_type)
+           (r_ft.name) AS _
+           
+        FROM ref.form_types r_ft
+          
+       WHERE (r_ft.pk = r_pt.fk_template_type)
      )
 ) AS l10n_instance_type
-, r_pt.engine
-, r_pt.in_use
-, r_pt.edit_after_substitution
-, r_pt.filename
-, CASE WHEN 
-(r_pt.data IS NOT NULL) THEN true ELSE false END AS has_template_data
-, r_pt.modified_when AS last_modified
-, COALESCE
+,
+    r_pt.engine
+,
+    r_pt.in_use
+,
+    r_pt.edit_after_substitution
+,
+    r_pt.filename
+,
+        CASE
+            WHEN 
+(r_pt.data IS NOT NULL) THEN true
+            ELSE false
+        END AS has_template_data
+,
+    r_pt.modified_when AS last_modified
+,
+    COALESCE
 (
      (
-      SELECT staff.short_alias 
-        FROM dem.staff 
-       WHERE (staff.db_user = r_pt.modified_by)
+      SELECT d_s.short_alias
+           
+        FROM dem.staff d_s
+          
+       WHERE (d_s.db_user = r_pt.modified_by)
      )
      , (
            ('<'::text || 
@@ -121050,8 +141364,11 @@ SELECT _
            ) || '>'::text
      )
 ) AS modified_by
-, r_pt.fk_template_type AS pk_template_type
-, r_pt.xmin AS xmin_paperwork_template 
+,
+    r_pt.fk_template_type AS pk_template_type
+,
+    r_pt.xmin AS xmin_paperwork_template
+   
 FROM ref.paperwork_templates r_pt;</pre>
 	
 
@@ -121212,24 +141529,35 @@ FROM ref.paperwork_templates r_pt;</pre>
 	
 	<pre>
 SELECT rti.pk AS pk_tag_image
-, rti.description
-, _
+,
+    rti.description
+,
+    _
 (rti.description) AS l10n_description
-, rti.filename
-, octet_length
+,
+    rti.filename
+,
+    octet_length
 (COALESCE
      (rti.image
            ,'\x'::bytea
      )
 ) AS size
-, (EXISTS 
+,
+    
+(EXISTS 
      (
-      SELECT 1 
-        FROM dem.identity_tag dit 
-       WHERE (dit.fk_tag = rti.pk) LIMIT 1
+      SELECT 1
+           
+        FROM dem.identity_tag dit
+          
+       WHERE (dit.fk_tag = rti.pk)
+         LIMIT 1
      )
 ) AS is_in_use
-, rti.xmin AS xmin_tag_image 
+,
+    rti.xmin AS xmin_tag_image
+   
 FROM ref.tag_image rti;</pre>
 	
 
@@ -121459,53 +141787,96 @@ public expansion of the same keyword.</p>
 	<pre>
 SELECT DISTINCT 
 ON (union_result.keyword) union_result.pk_expansion
-, union_result.pk_staff
-, union_result.keyword
-, union_result.expansion
-, union_result.is_encrypted
-, union_result.is_textual
-, union_result.data_size
-, union_result.public_expansion
-, union_result.private_expansion
-, union_result.owner
-, union_result.xmin_expansion 
+,
+    union_result.pk_staff
+,
+    union_result.keyword
+,
+    union_result.expansion
+,
+    union_result.is_encrypted
+,
+    union_result.is_textual
+,
+    union_result.data_size
+,
+    union_result.public_expansion
+,
+    union_result.private_expansion
+,
+    union_result.owner
+,
+    union_result.xmin_expansion
+   
 FROM (
 SELECT r_ke.pk AS pk_expansion
-     , r_ke.fk_staff AS pk_staff
-     , r_ke.keyword
-     , r_ke.textual_data AS expansion
-     , r_ke.encrypted AS is_encrypted
-     , (r_ke.binary_data IS NULL) AS is_textual
-     , octet_length
+     ,
+            r_ke.fk_staff AS pk_staff
+     ,
+            r_ke.keyword
+     ,
+            r_ke.textual_data AS expansion
+     ,
+            r_ke.encrypted AS is_encrypted
+     ,
+            
+     (r_ke.binary_data IS NULL) AS is_textual
+     ,
+            octet_length
      (r_ke.binary_data) AS data_size
-     , false AS public_expansion
-     , true AS private_expansion
-     , r_ke.owner
-     , r_ke.xmin AS xmin_expansion 
-  FROM ref.keyword_expansion r_ke 
+     ,
+            false AS public_expansion
+     ,
+            true AS private_expansion
+     ,
+            r_ke.owner
+     ,
+            r_ke.xmin AS xmin_expansion
+           
+  FROM ref.keyword_expansion r_ke
+          
  WHERE (r_ke.fk_staff = 
            (
-            SELECT staff.pk 
-              FROM dem.staff 
+            SELECT staff.pk
+                   
+              FROM dem.staff
+                  
              WHERE (staff.db_user = "current_user"
                        ()
                  )
            )
      )
-UNION ALLSELECT r_ke.pk AS pk_expansion
-     , r_ke.fk_staff AS pk_staff
-     , r_ke.keyword
-     , r_ke.textual_data AS expansion
-     , r_ke.encrypted AS is_encrypted
-     , (r_ke.binary_data IS NULL) AS is_textual
-     , octet_length
+        
+UNION ALL
+         
+SELECT r_ke.pk AS pk_expansion
+     ,
+            r_ke.fk_staff AS pk_staff
+     ,
+            r_ke.keyword
+     ,
+            r_ke.textual_data AS expansion
+     ,
+            r_ke.encrypted AS is_encrypted
+     ,
+            
+     (r_ke.binary_data IS NULL) AS is_textual
+     ,
+            octet_length
      (r_ke.binary_data) AS data_size
-     , true AS public_expansion
-     , false AS private_expansion
-     , r_ke.owner
-     , r_ke.xmin AS xmin_expansion 
-  FROM ref.keyword_expansion r_ke 
+     ,
+            true AS public_expansion
+     ,
+            false AS private_expansion
+     ,
+            r_ke.owner
+     ,
+            r_ke.xmin AS xmin_expansion
+           
+  FROM ref.keyword_expansion r_ke
+          
  WHERE (r_ke.fk_staff IS NULL)
+  
 ORDER BY 9 DESC
 ) union_result;</pre>
 	
diff --git a/server/etc/gnumed/gnumed-backup.conf.example b/server/etc/gnumed/gnumed-backup.conf.example
index 73fac7c..cad1894 100644
--- a/server/etc/gnumed/gnumed-backup.conf.example
+++ b/server/etc/gnumed/gnumed-backup.conf.example
@@ -27,7 +27,7 @@ INSTANCE_OWNER="GNUmed_Team"
 BACKUP_DIR="${HOME}/.gnumed/backup/"
 
 # which database to backup
-GM_DATABASE="database_to_backup__for_example_gnumed_v20"
+GM_DATABASE="database_to_backup__for_example_gnumed_v21"
 
 # user/group the backup is eventually owned by
 BACKUP_OWNER="$USER:$USER"
diff --git a/server/etc/gnumed/gnumed-restore.conf.example b/server/etc/gnumed/gnumed-restore.conf
similarity index 72%
rename from server/etc/gnumed/gnumed-restore.conf.example
rename to server/etc/gnumed/gnumed-restore.conf
index a5b3add..45056ac 100644
--- a/server/etc/gnumed/gnumed-restore.conf.example
+++ b/server/etc/gnumed/gnumed-restore.conf
@@ -15,17 +15,20 @@
 #
 #------------------------------------------------------------
 
-# if your PostgreSQL server is running on another port
+# if your PostgreSQL server is running on a different
+# port then you need to configure that here,
+# note that setting PGPORT elsewhere doesn't cut it
 GM_PORT="5432"
 
-# set this to a writable directory on a drive where
-# there is plenty of disk space available
+# set this to a writable directory on a fast drive
+# where there is plenty of disk space available
 WORK_DIR_BASE="/tmp/gnumed"
 
 # where to store log files,
 # note that if you chose to write logs to the work
 # directory they may get lost during cleanup if the
 # restore process succeeds
-LOG_BASE="."
+LOG_TS=`date +%Y-%m-%d`
+LOG_BASE="${HOME}/.gnumed/logs/restore-${LOG_TS}"
 
 #============================================================
diff --git a/server/gm-adjust_db_settings.sh b/server/gm-adjust_db_settings.sh
index 617ae53..14f6eef 100755
--- a/server/gm-adjust_db_settings.sh
+++ b/server/gm-adjust_db_settings.sh
@@ -11,18 +11,12 @@
 #
 #==============================================================
 
-# if your PostgreSQL server is running on another port
-GM_PORT="5432"
-
-# set this to a writable directory on a drive where
-# there is some disk space available
-WORK_DIR="/tmp/gnumed"
+SQL_FILE="/tmp/gnumed/gm-db-settings-$$.sql"
 
 #==============================================================
 # There really should not be any need to
 # change anything below this line.
 #==============================================================
-SQL_FILE="${WORK_DIR}/gm-db-settings-$$.sql"
 
 TARGET_DB="$1"
 if test -z ${TARGET_DB} ; then
@@ -39,7 +33,7 @@ echo ""
 echo "==> Creating database settings adjustment SQL script ..."
 echo "    ${SQL_FILE}"
 
-mkdir -p ${WORK_DIR}
+mkdir -p /tmp/gnumed
 
 echo "-- GNUmed database settings adjustment script" > $SQL_FILE
 echo "-- (created by: $0 $*)" >> $SQL_FILE
@@ -79,14 +73,16 @@ echo "-- 3) log_disconnections = on (only needed for HIPAA compliance)" >> $SQL_
 echo "-- 4) fsync = on" >> $SQL_FILE
 echo "-- 5) full_page_writes = on" >> $SQL_FILE
 echo "-- 6) wal_sync_method = <see PostgreSQL docs>" >> $SQL_FILE
+echo "-- 7) track_commit_timestamp = on" >> $SQL_FILE
+echo "" >> $SQL_FILE
 
 echo "" >> $SQL_FILE
 echo "-- cannot be changed without an initdb (pg_dropcluster):" >> $SQL_FILE
 echo "-- lc_ctype = *.UTF-8" >> $SQL_FILE
-echo "-- server_encoding = UTF8" >> $SQL_FILE
+echo "-- server_encoding = UTF8"
 
 echo "" >> $SQL_FILE
-echo "select gm.log_script_insertion('gm-adjust_db_settings.sh', '20.3');" >> $SQL_FILE
+echo "select gm.log_script_insertion('gm-adjust_db_settings.sh', '21.0');" >> $SQL_FILE
 echo "commit;" >> $SQL_FILE
 
 echo "" >> $SQL_FILE
@@ -97,16 +93,13 @@ echo "-- data checksum version != 0" >> $SQL_FILE
 
 echo "" >> $SQL_FILE
 echo "-- current relevant settings:" >> $SQL_FILE
-echo "select name, setting from pg_settings where name in ('allow_system_table_mods', 'log_connections', 'log_disconnections', 'fsync', 'full_page_writes', 'wal_sync_method', 'lc_ctype', 'server_encoding', 'hba_file', 'config_file');" >> $SQL_FILE
+echo "select name, setting from pg_settings where name in ('allow_system_table_mods', 'log_connections', 'log_disconnections', 'fsync', 'full_page_writes', 'wal_sync_method', 'track_commit_timestamp', 'data_checksums', 'lc_ctype', 'server_encoding', 'hba_file', 'config_file');" >> $SQL_FILE
 echo "" >> $SQL_FILE
 
-
 echo ""
 echo "==> Adjusting settings of database ${TARGET_DB} ..."
-LOG="${WORK_DIR}/$(basename $0)-$$.log"
-sudo -u postgres psql -e -E -p ${GM_PORT} -f ${SQL_FILE} -d ${TARGET_DB} &> ${LOG}
-echo "=====================================================================================" >> ${LOG}
-cat $SQL_FILE >> ${LOG}
+LOG="/tmp/gnumed/$(basename $0)-$$.log"
+sudo -u postgres psql -d ${TARGET_DB} -f ${SQL_FILE} &> ${LOG}
 if test $? -ne 0 ; then
 	echo "    ERROR: failed to adjust database settings. Aborting."
 	echo "    LOG  : ${LOG}"
diff --git a/server/gm-backup_database.sh b/server/gm-backup.sh
similarity index 86%
copy from server/gm-backup_database.sh
copy to server/gm-backup.sh
index 2653809..bdb39d3 100755
--- a/server/gm-backup_database.sh
+++ b/server/gm-backup.sh
@@ -2,9 +2,9 @@
 
 #==============================================================
 #
-# This script creates an uncompressed, plain text (SQL) backup
+# This script creates an uncompressed, directory-style backup
 # of the database schema, data, and roles which can be used to
-# restore a GNUmed database from scratch with psql.
+# restore a GNUmed database from scratch with pg_restore.
 #
 # You need to allow root to access the GNUmed database as
 # user "gm-dbo" by either editing pg_hba.conf or using a
@@ -17,7 +17,7 @@
 #  /etc/anacrontab to make sure it creates daily
 #  database backups for GNUmed:
 #
-#  1       15      backup-gnumed-<your-company>    /usr/bin/gm-backup_database.sh
+#  1       15      backup-gnumed-<your-company>    /usr/bin/gm-backup.sh
 #
 #
 # cron
@@ -25,7 +25,7 @@
 #  add the following line to a crontab file to run a
 #  database backup at 12:47 and 19:47 every day
 #
-#  47 12,19 * * * * /usr/bin/gm-backup_database.sh
+#  47 12,19 * * * * /usr/bin/gm-backup.sh
 #
 # author: Karsten Hilbert
 # license: GPL v2 or later
@@ -107,8 +107,13 @@ fi
 # create dumps
 if test -z ${GM_HOST} ; then
 	# locally
+
+	# database
+	pg_dump -v --format=directory --compress=0 --column-inserts --clean --if-exists --serializable-deferrable -p ${GM_PORT} -U ${GM_DBO} -f ${BACKUP_FILENAME}.dir ${GM_DATABASE} 2> /dev/null
+
+	# roles
 	# -r -> -g for older versions
-	sudo -u postgres pg_dumpall -r -v -p ${GM_PORT} > ${BACKUP_FILENAME}-roles.sql 2> /dev/null
+	sudo -u postgres pg_dumpall -v --roles-only -p ${GM_PORT} > ${BACKUP_FILENAME}-roles.sql 2> /dev/null
 
 	echo "" >> ${BACKUP_FILENAME}-roles.sql 2> /dev/null
 	echo "-- -----------------------------------------------------" >> ${BACKUP_FILENAME}-roles.sql 2> /dev/null
@@ -126,12 +131,16 @@ if test -z ${GM_HOST} ; then
 	ROLES=`psql -A -t -d ${GM_DATABASE} -p ${GM_PORT} -U ${GM_DBO} -c "select gm.get_users('${GM_DATABASE}');"`
 	echo "-- ${ROLES}" >> ${BACKUP_FILENAME}-roles.sql 2> /dev/null
 
-	pg_dump -C -v -p ${GM_PORT} -U ${GM_DBO} -f ${BACKUP_FILENAME}-database.sql ${GM_DATABASE} 2> /dev/null
 else
 	# remotely
 	if ping -c 3 -i 2 ${GM_HOST} > /dev/null; then
+
+		# database
+		pg_dump -v --format=directory --compress=0 --column-inserts --clean --if-exists --serializable-deferrable -p ${GM_PORT} -U ${GM_DBO} -f ${BACKUP_FILENAME}.dir -h ${GM_HOST} ${GM_DATABASE} 2> /dev/null
+
+		# roles
 		# -r -> -g for older versions
-		pg_dumpall -r -v -h ${GM_HOST} -p ${GM_PORT} -U postgres > ${BACKUP_FILENAME}-roles.sql 2> /dev/null
+		pg_dumpall -v --roles-only -h ${GM_HOST} -p ${GM_PORT} -U postgres > ${BACKUP_FILENAME}-roles.sql 2> /dev/null
 
 		echo "" >> ${BACKUP_FILENAME}-roles.sql 2> /dev/null
 		echo "-- -----------------------------------------------------" >> ${BACKUP_FILENAME}-roles.sql 2> /dev/null
@@ -149,7 +158,6 @@ else
 		ROLES=`psql -A -t -d ${GM_DATABASE} -p ${GM_PORT} -U ${GM_DBO} -c "select gm.get_users('${GM_DATABASE}');"`
 		echo "-- ${ROLES}" >> ${BACKUP_FILENAME}-roles.sql 2> /dev/null
 
-		pg_dump -C -v -h ${GM_HOST} -p ${GM_PORT} -U ${GM_DBO} -f ${BACKUP_FILENAME}-database.sql ${GM_DATABASE} 2> /dev/null
 	else
 		echo "Cannot ping database host ${GM_HOST}."
 		exit 1
@@ -159,20 +167,18 @@ fi ;
 
 # tar and test it
 if test -z ${VERIFY_TAR} ; then
-	tar -cf ${BACKUP_FILENAME}.tar ${BACKUP_FILENAME}-database.sql ${BACKUP_FILENAME}-roles.sql
+	tar -cf ${BACKUP_FILENAME}.tar ${BACKUP_FILENAME}-roles.sql ${BACKUP_FILENAME}.dir/
 else
-	tar -cWf ${BACKUP_FILENAME}.tar ${BACKUP_FILENAME}-database.sql ${BACKUP_FILENAME}-roles.sql
+	tar -cWf ${BACKUP_FILENAME}.tar ${BACKUP_FILENAME}-roles.sql ${BACKUP_FILENAME}.dir/
 fi ;
 if test "$?" != "0" ; then
 	echo "Creating backup tar archive [${BACKUP_FILENAME}.tar] failed. Aborting."
 	exit 1
 fi
-rm -f ${BACKUP_FILENAME}-database.sql
+rm --dir --recursive --one-file-system ${BACKUP_FILENAME}.dir/
 rm -f ${BACKUP_FILENAME}-roles.sql
 
 
 chown ${BACKUP_OWNER} ${BACKUP_FILENAME}.tar
 
 exit 0
-
-#==============================================================
diff --git a/server/gm-backup_data.sh b/server/gm-backup_data.sh
index c78c304..2e6b991 100755
--- a/server/gm-backup_data.sh
+++ b/server/gm-backup_data.sh
@@ -99,7 +99,7 @@ fi
 
 
 # data only
-pg_dump --data-only -v -p ${GM_PORT} -U ${GM_DBO} -f ${BACKUP_FILENAME}-data_only.sql ${GM_DATABASE} 2> /dev/null
+pg_dump --data-only --column-inserts -v -p ${GM_PORT} -U ${GM_DBO} -f ${BACKUP_FILENAME}-data_only.sql ${GM_DATABASE} 2> /dev/null
 
 
 # tar and test it
diff --git a/server/gm-backup_database.sh b/server/gm-backup_database.sh
index 2653809..2e3c8e4 100755
--- a/server/gm-backup_database.sh
+++ b/server/gm-backup_database.sh
@@ -126,7 +126,7 @@ if test -z ${GM_HOST} ; then
 	ROLES=`psql -A -t -d ${GM_DATABASE} -p ${GM_PORT} -U ${GM_DBO} -c "select gm.get_users('${GM_DATABASE}');"`
 	echo "-- ${ROLES}" >> ${BACKUP_FILENAME}-roles.sql 2> /dev/null
 
-	pg_dump -C -v -p ${GM_PORT} -U ${GM_DBO} -f ${BACKUP_FILENAME}-database.sql ${GM_DATABASE} 2> /dev/null
+	pg_dump -C -v --column-inserts --disable-triggers -p ${GM_PORT} -U ${GM_DBO} -f ${BACKUP_FILENAME}-database.sql ${GM_DATABASE} 2> /dev/null
 else
 	# remotely
 	if ping -c 3 -i 2 ${GM_HOST} > /dev/null; then
@@ -149,7 +149,7 @@ else
 		ROLES=`psql -A -t -d ${GM_DATABASE} -p ${GM_PORT} -U ${GM_DBO} -c "select gm.get_users('${GM_DATABASE}');"`
 		echo "-- ${ROLES}" >> ${BACKUP_FILENAME}-roles.sql 2> /dev/null
 
-		pg_dump -C -v -h ${GM_HOST} -p ${GM_PORT} -U ${GM_DBO} -f ${BACKUP_FILENAME}-database.sql ${GM_DATABASE} 2> /dev/null
+		pg_dump -C -v --column-inserts --disable-triggers -h ${GM_HOST} -p ${GM_PORT} -U ${GM_DBO} -f ${BACKUP_FILENAME}-database.sql ${GM_DATABASE} 2> /dev/null
 	else
 		echo "Cannot ping database host ${GM_HOST}."
 		exit 1
diff --git a/server/gm-fingerprint_db.py b/server/gm-fingerprint_db.py
index 0b9c76b..dbed38a 100755
--- a/server/gm-fingerprint_db.py
+++ b/server/gm-fingerprint_db.py
@@ -12,13 +12,18 @@
 
 import sys
 import psycopg2
+import io
 
 database = sys.argv[1]
 passwd = sys.argv[2]
 dsn = u'dbname=%s user=gm-dbo password=%s' % (database, passwd)
 queries = [
+	("SELECT pg_size_pretty(pg_database_size('%s'))" % database, "Size (DB)"),
 	("SELECT md5(gm.concat_table_structure())", "Schema hash"),
-	("SELECT pg_size_pretty(pg_database_size('%s'))" % database, "Size"),
+	("SELECT setting FROM pg_settings WHERE name = 'server_version'", "Version (PG)"),
+	("SELECT setting FROM pg_settings WHERE name = 'server_encoding'", "Encoding (PG)"),
+	("SELECT setting FROM pg_settings WHERE name = 'lc_collate'", "LC_COLLATE (PG)"),
+	("SELECT setting FROM pg_settings WHERE name = 'lc_ctype'", "LC_CTYPE (PG)"),
 	("SELECT count(1) FROM dem.identity", "Patients"),
 	("SELECT count(1) FROM clin.encounter", "Contacts"),
 	("SELECT count(1) FROM clin.episode", "Episodes"),
@@ -29,19 +34,17 @@ queries = [
 	("SELECT count(1) FROM blobs.doc_obj", "Objects"),
 	("SELECT count(1) FROM dem.org", "Organizations"),
 	("SELECT count(1) FROM dem.org_unit", "Organizational units"),
-	("SELECT setting FROM pg_settings WHERE name = 'server_version'", "Version (PG)"),
-	("SELECT setting FROM pg_settings WHERE name = 'server_encoding'", "Encoding (PG)"),
-	("SELECT setting FROM pg_settings WHERE name = 'lc_collate'", "LC_COLLATE (PG)"),
-	("SELECT setting FROM pg_settings WHERE name = 'lc_ctype'", "LC_CTYPE (PG)")
+	("SELECT max(modified_when) FROM audit.audit_fields", "Last .modified_when"),
+	("SELECT max(audit_when) FROM audit.audit_trail", "Last .audit_when")
 ]
 
 fname = u'gm_db-%s-fingerprint.log' % database
 #==============================================================
-outfile = open(fname, 'wb')
+outfile = io.open(fname, mode = 'wt', encoding = 'utf8')
 
-outfile.write("Fingerprinting GNUmed database ...\n")
-outfile.write("\n")
-outfile.write("%20s: %s\n" % ("Name", database))
+outfile.write(u"Fingerprinting GNUmed database ...\n")
+outfile.write(u"\n")
+outfile.write(u"%20s: %s\n" % (u"Name (DB)", database))
 
 conn = psycopg2.connect(dsn=dsn)
 curs = conn.cursor()
@@ -49,14 +52,16 @@ curs = conn.cursor()
 for cmd, label in queries:
 	curs.execute(cmd)
 	rows = curs.fetchall()
-	outfile.write("%20s: %s\n" % (label, rows[0][0]))
+	outfile.write(u"%20s: %s\n" % (label, rows[0][0]))
 
 if len(sys.argv) > 3:
 	if sys.argv[3] == '--with-dump':
 		curs.execute('SELECT gm.concat_table_structure()')
 		rows = curs.fetchall()
-		outfile.write("\n%s\n" % rows[0][0])
+		outfile.write(u"\n%s\n" % rows[0][0])
 
 curs.close()
 conn.rollback()
+
+outfile.close()
 #==============================================================
diff --git a/server/gm-restore_database.sh b/server/gm-restore_database.sh
index 4b7627e..33e4490 100755
--- a/server/gm-restore_database.sh
+++ b/server/gm-restore_database.sh
@@ -155,6 +155,7 @@ chown -c postgres ${BACKUP}-*.sql
 
 echo ""
 echo "==> Restoring GNUmed roles ..."
+mkdir -p ${LOG_BASE}
 LOG="${LOG_BASE}/restoring-roles-${TS}.log"
 #sudo -u postgres psql -e -E -p ${GM_PORT} --single-transaction -f ${BACKUP}-roles.sql &> ${LOG}
 sudo -u postgres psql -e -E -p ${GM_PORT} -f ${BACKUP}-roles.sql &> ${LOG}
@@ -200,6 +201,7 @@ echo ""
 echo "==> Cleaning up ..."
 rm -vf ${WORK_DIR}/*
 rmdir -v ${WORK_DIR}
+echo "    log dir: ${LOG_BASE}"
 
 
 echo ""
diff --git a/server/gm-restore_database.sh b/server/gm-restore_database_from_archive.sh
similarity index 60%
copy from server/gm-restore_database.sh
copy to server/gm-restore_database_from_archive.sh
index 4b7627e..c1014e9 100755
--- a/server/gm-restore_database.sh
+++ b/server/gm-restore_database_from_archive.sh
@@ -31,7 +31,7 @@ fi
 
 echo ""
 echo "==> Trying to restore a GNUmed backup ..."
-echo "    file: ${BACKUP}"
+echo "    backup file: ${BACKUP}"
 if test ! -r ${BACKUP} ; then
 	echo "    ERROR: Cannot access backup file. Aborting."
 	echo "   "`ls -al ${BACKUP}`
@@ -51,14 +51,24 @@ else
 fi
 
 
+mkdir -p ${LOG_BASE}
+TS=`date +%Y-%m-%d_%H-%M-%S`
+LOG="${LOG_BASE}/restore-${TS}.log"
+echo "    log: ${LOG}"
+echo "restore: ${TS}" &> ${LOG}
+chmod 0666 ${LOG}
+
+
 if [[ "$BACKUP" =~ .*\.bz2 ]] ; then
 	echo ""
 	echo "==> Testing backup file integrity ..."
-	bzip2 -tv $BACKUP
+	bzip2 -tv $BACKUP &>> ${LOG}
 	if test $? -ne 0 ; then
 		echo "    ERROR: Integrity check failed. Aborting."
 		echo ""
 		echo "    You may want to try recovering data with bzip2recover."
+		echo ""
+		echo "    log: ${LOG}"
 		exit 1
 	fi
 fi
@@ -66,12 +76,12 @@ fi
 
 echo ""
 echo "==> Setting up workspace ..."
-TS=`date +%Y-%m-%d_%H-%M-%S`
 WORK_DIR="${WORK_DIR_BASE}/gm-restore_${TS}/"
-echo "    dir: ${WORK_DIR}"
-mkdir -p ${WORK_DIR}
+echo "    work dir: ${WORK_DIR}"
+mkdir -p -v ${WORK_DIR} &>> ${LOG}
 if test $? -ne 0 ; then
 	echo "    ERROR: Cannot create workspace. Aborting."
+	echo "           log: ${LOG}"
 	exit 1
 fi
 chmod +rx ${WORK_DIR}
@@ -79,10 +89,11 @@ chmod +rx ${WORK_DIR}
 
 echo ""
 echo "==> Creating copy of backup file ..."
-cp -v ${BACKUP} ${WORK_DIR}
+cp -v ${BACKUP} ${WORK_DIR} &>> ${LOG}
 if test $? -ne 0 ; then
 	echo "    ERROR: Cannot copy backup file. Aborting."
 	echo "   "`ls -al ${BACKUP}`
+	echo "   log: ${LOG}"
 	exit 1
 fi
 
@@ -92,11 +103,12 @@ echo "==> Unpacking backup file ..."
 BACKUP=${WORK_DIR}`basename ${BACKUP}`
 if [[ "${BACKUP}" =~ .*\.bz2 ]] ; then
 	echo " => Decompressing (from bzip2) ..."
-	bunzip2 -v ${BACKUP}
+	bunzip2 -v ${BACKUP} &>> ${LOG}
 	if test $? -ne 0 ; then
 		echo "    ERROR: Cannot decompress bzip2 backup file. Aborting."
 		echo "    pwd: "`pwd`
 		echo "    file: ${BACKUP}"
+		echo "    log: ${LOG}"
 		exit 1
 	fi
 	BACKUP=${WORK_DIR}`basename ${BACKUP} .bz2`
@@ -104,15 +116,52 @@ fi
 
 
 echo " => Extracting (from tarball) ..."
-tar -C ${WORK_DIR} -xvvf ${BACKUP}
+tar -C ${WORK_DIR} -xvf ${BACKUP} &>> ${LOG}
 if test $? -ne 0 ; then
 	echo "    ERROR: Cannot unpack tarball backup file. Aborting."
 	echo "    pwd: "`pwd`
 	echo "    file: ${BACKUP}"
+	echo "    log: ${LOG}"
 	exit 1
 fi
 BACKUP=${WORK_DIR}`basename ${BACKUP} .tar`
-rm ${BACKUP}.tar
+rm ${BACKUP}.tar &>> ${LOG}
+
+
+echo ""
+echo "==> Checking target database status ..."
+TARGET_DB=`pg_restore --create --schema-only ${BACKUP}.dir | head -n 40 | grep -i 'create database gnumed_v' | cut -f 3 -d ' '`
+ERROR="$?"
+echo "${TARGET_DB}" &>> ${LOG}
+#if test ${ERROR} -ne 0 ; then
+#	echo "exit code: ${ERROR}" &>> ${LOG}
+#	echo "    ERROR: Cannot determine target database from backup file. Aborting."
+#	echo "           log: ${LOG}"
+#	exit 1
+#fi
+if test -z ${TARGET_DB} ; then
+	echo "    ERROR: Backup does not create target database ${TARGET_DB}. Aborting."
+	echo "           log: ${LOG}"
+	exit 1
+fi
+echo "    db: ${TARGET_DB}"
+if test `sudo -u postgres psql -l -p ${GM_PORT} | grep ${TARGET_DB} | wc -l` -ne 0 ; then
+	echo ""
+	echo "    Target database ${TARGET_DB} already exists."
+	echo ""
+	echo "    Restoring will OVERWRITE the existing database."
+	echo "    Are you really positively sure ?"
+	echo ""
+	read -e -p "    [yes / NO]: "
+	if test "${REPLY}" != "yes" ; then
+		echo "${REPLY} (!='yes' => aborted by user)" &>> ${LOG}
+		echo "    Database restore aborted by user."
+		echo "    log: ${LOG}"
+		exit 1
+	fi
+	echo "user requested drop of existing database ${TARGET_DB}" &>> ${LOG}
+	sudo -u postgres dropdb -e -i --if-exists ${TARGET_DB} &>> ${LOG}
+fi
 
 
 echo ""
@@ -130,56 +179,44 @@ editor ${BACKUP}-roles.sql
 
 
 echo ""
-echo "==> Checking target database status ..."
-TARGET_DB=`head -n 40 ${BACKUP}-database.sql | grep -i "create database gnumed_v" | cut -f 3 -d " "`
-if test $? -ne 0 ; then
-	echo "    ERROR: Cannot determine target database from backup file. Aborting."
-	exit 1
-fi
-if test -z ${TARGET_DB} ; then
-	echo "    ERROR: Backup does not create target database ${TARGET_DB}. Aborting."
-	exit 1
-fi
-echo "    db: ${TARGET_DB}"
-if test `sudo -u postgres psql -l -p ${GM_PORT} | grep ${TARGET_DB} | wc -l` -ne 0 ; then
-	echo "    ERROR: Target database ${TARGET_DB} already exists. Aborting."
-	exit 1
-fi
-
-
-echo ""
 echo "==> Setting data file permissions ..."
-chmod -c +r ${BACKUP}-*.sql
-chown -c postgres ${BACKUP}-*.sql
+chmod -c +r ${BACKUP}-roles.sql &>> ${LOG}
+chown -c postgres ${BACKUP}-roles.sql &>> ${LOG}
+chmod -cR +r ${BACKUP}.dir &>> ${LOG}
+chown -cR postgres ${BACKUP}.dir &>> ${LOG}
 
 
 echo ""
 echo "==> Restoring GNUmed roles ..."
-LOG="${LOG_BASE}/restoring-roles-${TS}.log"
-#sudo -u postgres psql -e -E -p ${GM_PORT} --single-transaction -f ${BACKUP}-roles.sql &> ${LOG}
-sudo -u postgres psql -e -E -p ${GM_PORT} -f ${BACKUP}-roles.sql &> ${LOG}
+sudo -u postgres psql -e -E -p ${GM_PORT} --single-transaction -f ${BACKUP}-roles.sql &>> ${LOG}
 if test $? -ne 0 ; then
 	echo "    ERROR: Failed to restore roles. Aborting."
 	echo "           log: ${LOG}"
-	chmod 0666 ${LOG}
 	exit 1
 fi
-chmod 0666 ${LOG}
 
 
 echo ""
 echo "==> Restoring GNUmed database ${TARGET_DB} ..."
-LOG="${LOG_BASE}/restoring-database-${TS}.log"
-# can't use --single-transaction because CREATE DATABASE does not work inside transaction:
-#sudo -u postgres psql -p ${GM_PORT} --single-transaction -f ${BACKUP}-database.sql &> ${LOG}
-sudo -u postgres psql -p ${GM_PORT} -f ${BACKUP}-database.sql &> ${LOG}
-if test $? -ne 0 ; then
+# we require the database to not exist already above,
+# hence we can safely use --create which we need because
+# we want to create an empty target database,
+# in this case we also do not need --disable-triggers
+# (see pg-general list) since the section containing
+# constraints is restored after section data,
+# cannot use --single-transaction because CREATE DATABASE does not work inside a transaction
+# need not use --clean because --create already creates "empty" database and does not apply to things copied by createdb :-(
+# need not use --if-exists because --create already creates "empty" database and it does not apply to things copied by createdb :-(
+CMD="sudo -u postgres pg_restore --verbose --create --dbname=template1 --exit-on-error -p ${GM_PORT} ${BACKUP}.dir/"
+echo "${CMD}" &>> ${LOG}
+${CMD} &>> ${LOG}
+ERROR="$?"
+echo "pg_restore exit code: ${ERROR}" &>> ${LOG}
+if test ${ERROR} -ne 0 ; then
 	echo "    ERROR: failed to restore database. Aborting."
 	echo "           log: ${LOG}"
-	chmod 0666 ${LOG}
 	exit 1
 fi
-chmod 0666 ${LOG}
 
 
 echo ""
@@ -187,19 +224,18 @@ echo "==> Analyzing database ${TARGET_DB} ..."
 # --full doesn't make sense since there are no
 # deleted rows in a freshly restored database but
 # we need to update statistics to get decent performance
-LOG="${LOG_BASE}/analyzing-database-${TS}.log"
-sudo -u postgres vacuumdb -v -z -d ${TARGET_DB} -p ${GM_PORT} &> ${LOG}
-chmod 0666 ${LOG}
+sudo -u postgres vacuumdb -v -z -d ${TARGET_DB} -p ${GM_PORT} &>> ${LOG}
+sudo -u postgres vacuumdb -v -Z -d ${TARGET_DB} -p ${GM_PORT} &>> ${LOG}
 
 
 # adjusting settings
-gm-adjust_db_settings.sh ${TARGET_DB}
+gm-adjust_db_settings ${TARGET_DB} &>> ${LOG}
 
 
 echo ""
 echo "==> Cleaning up ..."
-rm -vf ${WORK_DIR}/*
-rmdir -v ${WORK_DIR}
+echo "    log dir: ${LOG_BASE}"
+rm --verbose --dir --recursive --one-file-system ${WORK_DIR} &>> ${LOG}
 
 
 echo ""
diff --git a/server/pycommon/gmBackendListener.py b/server/pycommon/gmBackendListener.py
index 665f029..d9345ec 100644
--- a/server/pycommon/gmBackendListener.py
+++ b/server/pycommon/gmBackendListener.py
@@ -1,4 +1,7 @@
-"""GNUmed database backend listener.
+
+from __future__ import print_function
+
+__doc__ = """GNUmed database backend listener.
 
 This module implements threaded listening for asynchronuous
 notifications from the database backend.
@@ -97,7 +100,7 @@ class gmBackendListener(gmBorg.cBorg):
 			except:
 				pass
 		except:
-			print sys.exc_info()
+			print(sys.exc_info())
 
 		self._listener_thread = None
 
@@ -216,7 +219,7 @@ class gmBackendListener(gmBorg.cBorg):
 					self._conn_lock.release()
 				self.__notifications_received += 1
 				if self.debug:
-					print notification
+					print(notification)
 				_log.debug('#%s: %s (first param is PID of sending backend)', self.__notifications_received, notification)
 				# decode payload
 				payload = notification.payload.split(u'::')
@@ -233,9 +236,9 @@ class gmBackendListener(gmBorg.cBorg):
 					if item.startswith(u'PK name='):
 						pk_column = item.split(u'=')[1]
 					if item.startswith(u'row PK='):
-						pk_row = item.split(u'=')[1]
+						pk_row = int(item.split(u'=')[1])
 					if item.startswith(u'person PK='):
-						pk_identity = item.split(u'=')[1]
+						pk_identity = int(item.split(u'=')[1])
 				# try sending intra-client signals:
 				# 1) generic signal
 				self.__messages_sent += 1
@@ -254,8 +257,8 @@ class gmBackendListener(gmBorg.cBorg):
 						notification_index = self.__notifications_received
 					)
 				except:
-					print "problem routing notification [%s] from backend [%s] to intra-client dispatcher" % (notification.channel, notification.pid)
-					print sys.exc_info()
+					print("problem routing notification [%s] from backend [%s] to intra-client dispatcher" % (notification.channel, notification.pid))
+					print(sys.exc_info())
 				# 2) dynamically emulated old style table specific signals
 				if table is not None:
 					self.__messages_sent += 1
@@ -276,8 +279,8 @@ class gmBackendListener(gmBorg.cBorg):
 							notification_index = self.__notifications_received
 						)
 					except:
-						print "problem routing notification [%s] from backend [%s] to intra-client dispatcher" % (signal, notification.pid)
-						print sys.exc_info()
+						print("problem routing notification [%s] from backend [%s] to intra-client dispatcher" % (signal, notification.pid))
+						print(sys.exc_info())
 
 				# there *may* be more pending notifications but
 				# we don't care when quitting
@@ -317,16 +320,16 @@ if __name__ == "__main__":
 			global notifies
 			notifies += 1
 			sys.stdout.flush()
-			print "\nBackend says: patient data has been modified (%s. notification)" % notifies
+			print("\nBackend says: patient data has been modified (%s. notification)" % notifies)
 		#-------------------------------
 		try:
 			n = int(sys.argv[2])
 		except:
-			print "You can set the number of iterations\nwith the second command line argument"
+			print("You can set the number of iterations\nwith the second command line argument")
 			n = 100000
 
 		# try loop without backend listener
-		print "Looping", n, "times through dummy function"
+		print("Looping", n, "times through dummy function")
 		i = 0
 		t1 = time.time()
 		while i < n:
@@ -334,21 +337,21 @@ if __name__ == "__main__":
 			i += 1
 		t2 = time.time()
 		t_nothreads = t2-t1
-		print "Without backend thread, it took", t_nothreads, "seconds"
+		print("Without backend thread, it took", t_nothreads, "seconds")
 
 		listener = gmBackendListener(conn = gmPG2.get_raw_connection())
 
 		# now try with listener to measure impact
-		print "Now in a new shell connect psql to the"
-		print "database <gnumed_v9> on localhost, return"
-		print "here and hit <enter> to continue."
+		print("Now in a new shell connect psql to the")
+		print("database <gnumed_v9> on localhost, return")
+		print("here and hit <enter> to continue.")
 		raw_input('hit <enter> when done starting psql')
-		print "You now have about 30 seconds to go"
-		print "to the psql shell and type"
-		print " notify patient_changed<enter>"
-		print "several times."
-		print "This should trigger our backend listening callback."
-		print "You can also try to stop the demo with Ctrl-C !"
+		print("You now have about 30 seconds to go")
+		print("to the psql shell and type")
+		print(" notify patient_changed<enter>")
+		print("several times.")
+		print("This should trigger our backend listening callback.")
+		print("You can also try to stop the demo with Ctrl-C !")
 
 		listener.register_callback('patient_changed', OnPatientModified)
 
@@ -358,8 +361,8 @@ if __name__ == "__main__":
 				counter += 1
 				time.sleep(1)
 				sys.stdout.flush()
-				print '.',
-			print "Looping",n,"times through dummy function"
+				print('.', end=' ')
+			print("Looping",n,"times through dummy function")
 			i = 0
 			t1 = time.time()
 			while i < n:
@@ -367,49 +370,49 @@ if __name__ == "__main__":
 				i += 1
 			t2 = time.time()
 			t_threaded = t2-t1
-			print "With backend thread, it took", t_threaded, "seconds"
-			print "Difference:", t_threaded-t_nothreads
+			print("With backend thread, it took", t_threaded, "seconds")
+			print("Difference:", t_threaded-t_nothreads)
 		except KeyboardInterrupt:
-			print "cancelled by user"
+			print("cancelled by user")
 
 		listener.shutdown()
 		listener.unregister_callback('patient_changed', OnPatientModified)
 	#-------------------------------
 	def run_monitor():
 
-		print "starting up backend notifications monitor"
+		print("starting up backend notifications monitor")
 
 		def monitoring_callback(*args, **kwargs):
 			try:
 				kwargs['originated_in_database']
-				print '==> got notification from database "%s":' % kwargs['signal']
+				print('==> got notification from database "%s":' % kwargs['signal'])
 			except KeyError:
-				print '==> received signal from client: "%s"' % kwargs['signal']
+				print('==> received signal from client: "%s"' % kwargs['signal'])
 			del kwargs['signal']
 			for key in kwargs.keys():
-				print '    [%s]: %s' % (key, kwargs[key])
+				print('    [%s]: %s' % (key, kwargs[key]))
 
 		gmDispatcher.connect(receiver = monitoring_callback)
 
 		listener = gmBackendListener(conn = gmPG2.get_raw_connection())
-		print "listening for the following notifications:"
-		print "1) unspecific:"
+		print("listening for the following notifications:")
+		print("1) unspecific:")
 		for sig in listener.unspecific_notifications:
-			print '   - %s' % sig
+			print('   - %s' % sig)
 
 		while True:
 			pat = gmPersonSearch.ask_for_patient()
 			if pat is None:
 				break
-			print "found patient", pat
+			print("found patient", pat)
 			gmPerson.set_active_patient(patient=pat)
-			print "now waiting for notifications, hit <ENTER> to select another patient"
+			print("now waiting for notifications, hit <ENTER> to select another patient")
 			raw_input()
 
-		print "cleanup"
+		print("cleanup")
 		listener.shutdown()
 
-		print "shutting down backend notifications monitor"
+		print("shutting down backend notifications monitor")
 
 	#-------------------------------
 	if sys.argv[1] == 'monitor':
diff --git a/server/pycommon/gmBorg.py b/server/pycommon/gmBorg.py
index 76864b2..f6f5358 100644
--- a/server/pycommon/gmBorg.py
+++ b/server/pycommon/gmBorg.py
@@ -24,6 +24,15 @@ class cBorg(object):
 #===================================================
 if __name__ == '__main__':
 
+	import sys
+
+	if len(sys.argv) < 2:
+		sys.exit()
+
+	if sys.argv[1] != u'test':
+		sys.exit()
+
+
 	class A(cBorg):
 		pass
 
@@ -34,25 +43,25 @@ if __name__ == '__main__':
 		def __init__(self, val='default'):
 			self.x = val
 
-	print "testing new-style classes borg"
+	print("testing new-style classes borg")
 	a1 = A()
 	a2 = A()
 	a1.a = 5
-	print a1.a, "==", a2.a
+	print(a1.a, "==", a2.a)
 	a3 = A()
-	print a1.a, "==", a2.a, "==", a3.a
+	print(a1.a, "==", a2.a, "==", a3.a)
 	b1 = B()
 	b1.a = 10
-	print b1.a
-	print a1.a
+	print(b1.a)
+	print(a1.a)
 	b2 = B()
-	print b2.a
+	print(b2.a)
 
 	c1 = C(val = 'non-default')
-	print c1.x
+	print(c1.x)
 	c2 = C(val = 'non-default 2')
-	print c2.x
+	print(c2.x)
 	c3 = C()
-	print c3.x
+	print(c3.x)
 
 #===================================================
diff --git a/server/pycommon/gmBusinessDBObject.py b/server/pycommon/gmBusinessDBObject.py
index 19589f9..4a02b36 100644
--- a/server/pycommon/gmBusinessDBObject.py
+++ b/server/pycommon/gmBusinessDBObject.py
@@ -1,4 +1,7 @@
-"""GNUmed database object business class.
+
+from __future__ import print_function
+
+__doc__ = """GNUmed database object business class.
 
 Overview
 --------
@@ -81,10 +84,10 @@ episode, encounter).
 
 One can offer all the data to the user:
 
-self.original_payload
+self.payload_most_recently_fetched
 - contains the data at the last successful refetch
 
-self.modified_payload
+self.payload_most_recently_attempted_to_store
 - contains the modified payload just before the last
   failure of save_payload() - IOW what is currently
   in the database
@@ -141,9 +144,11 @@ if __name__ == '__main__':
 from Gnumed.pycommon import gmExceptions
 from Gnumed.pycommon import gmPG2
 from Gnumed.pycommon.gmDateTime import pydt_strftime
-from Gnumed.pycommon.gmTools import tex_escape_string, xetex_escape_string, compare_dict_likes
+from Gnumed.pycommon.gmTools import tex_escape_string
 from Gnumed.pycommon.gmTools import xetex_escape_string
 from Gnumed.pycommon.gmTools import compare_dict_likes
+from Gnumed.pycommon.gmTools import format_dict_like
+from Gnumed.pycommon.gmTools import format_dict_likes_comparison
 
 
 _log = logging.getLogger('gm.db')
@@ -334,9 +339,9 @@ def delete_xxx(pk_XXX=None):
 		self.pk_obj = aPK_obj
 		result = self.refetch_payload(link_obj = link_obj)
 		if result is True:
-			self.original_payload = {}
+			self.payload_most_recently_fetched = {}
 			for field in self._idx.keys():
-				self.original_payload[field] = self._payload[self._idx[field]]
+				self.payload_most_recently_fetched[field] = self._payload[self._idx[field]]
 			return True
 
 		if result is False:
@@ -351,7 +356,7 @@ def delete_xxx(pk_XXX=None):
 			- data: the field values in a list (as returned by
 			  cursor.fetchone() in the DB-API)
 
-		row = {'data': row, 'idx': idx, 'pk_field': 'the PK column name'}
+		row = {'data': rows[0], 'idx': idx, 'pk_field': 'pk_XXX (the PK column name)'}
 
 		rows, idx = gmPG2.run_ro_queries(queries = [{'cmd': cmd, 'args': args}], get_col_idx = True)
 		objects = [ cChildClass(row = {'data': r, 'idx': idx, 'pk_field': 'the PK column name'}) for r in rows ]
@@ -369,15 +374,15 @@ def delete_xxx(pk_XXX=None):
 			_log.critical('faulty <row> argument structure: %s' % row)
 			raise gmExceptions.ConstructorError, "[%s:??]: error loading instance from row data" % self.__class__.__name__
 
-		self.original_payload = {}
+		self.payload_most_recently_fetched = {}
 		for field in self._idx.keys():
-			self.original_payload[field] = self._payload[self._idx[field]]
+			self.payload_most_recently_fetched[field] = self._payload[self._idx[field]]
 	#--------------------------------------------------------
 	def __del__(self):
-		if self.__dict__.has_key('_is_modified'):
+		if u'_is_modified' in self.__dict__:
 			if self._is_modified:
 				_log.critical('[%s:%s]: loosing payload changes' % (self.__class__.__name__, self.pk_obj))
-				_log.debug('original: %s' % self.original_payload)
+				_log.debug('most recently fetched: %s' % self.payload_most_recently_fetched)
 				_log.debug('modified: %s' % self._payload)
 	#--------------------------------------------------------
 	def __str__(self):
@@ -392,6 +397,7 @@ def delete_xxx(pk_XXX=None):
 			#return '[%s:%s]:\n %s' % (self.__class__.__name__, self.pk_obj, '\n '.join(lines))
 		except:
 			return 'nascent [%s @ %s], cannot show payload and primary key' %(self.__class__.__name__, id(self))
+
 	#--------------------------------------------------------
 	def __unicode__(self):
 		lines = []
@@ -404,6 +410,7 @@ def delete_xxx(pk_XXX=None):
 			return '[%s:%s]:\n%s' % (self.__class__.__name__, self.pk_obj, u'\n'.join(lines))
 		except:
 			return 'nascent [%s @ %s], cannot show payload and primary key' %(self.__class__.__name__, id(self))
+
 	#--------------------------------------------------------
 	def __getitem__(self, attribute):
 		# use try: except: as it is faster and we want this as fast as possible
@@ -473,15 +480,18 @@ def delete_xxx(pk_XXX=None):
 	#--------------------------------------------------------
 	def is_modified(self):
 		return self._is_modified
+
 	#--------------------------------------------------------
 	def get_fields(self):
 		try:
 			return self._idx.keys()
 		except AttributeError:
 			return 'nascent [%s @ %s], cannot return keys' %(self.__class__.__name__, id(self))
+
 	#--------------------------------------------------------
 	def get_updatable_fields(self):
 		return self.__class__._updatable_fields
+
 	#--------------------------------------------------------
 	def fields_as_dict(self, date_format='%Y %b %d  %H:%M', none_string=u'', escape_style=None, bool_strings=None):
 		if bool_strings is None:
@@ -531,9 +541,48 @@ def delete_xxx(pk_XXX=None):
 	def get_patient(self):
 		_log.error('[%s:%s]: forgot to override get_patient()' % (self.__class__.__name__, self.pk_obj))
 		return None
+
+	#--------------------------------------------------------
+	def format(self, *args, **kwargs):
+		return format_dict_like (
+			self.fields_as_dict(none_string = u'<?>'),
+			tabular = True,
+			value_delimiters = None
+		).split(u'\n')
+
 	#--------------------------------------------------------
-	def format(self):
-		return u'%s' % self
+	def _get_revision_history(self, query, args, title):
+		rows, idx = gmPG2.run_ro_queries(queries = [{'cmd': query, 'args': args}], get_col_idx = True)
+		lines = []
+		lines.append(u'%s (%s versions)' % (title, rows[0]['row_version'] + 1))
+		if len(rows) == 1:
+			lines.append(u'')
+			lines.extend(format_dict_like (
+					rows[0],
+					left_margin = 1,
+					tabular = True,
+					value_delimiters = None,
+					eol = None
+			))
+			return lines
+
+		for row_idx in range(len(rows)-1):
+			lines.append(u'')
+			row_older = rows[row_idx + 1]
+			row_newer = rows[row_idx]
+			lines.extend(format_dict_likes_comparison (
+				row_older,
+				row_newer,
+				title_left = _('Revision #%s') % row_older['row_version'],
+				title_right = _('Revision #%s') % row_newer['row_version'],
+				left_margin = 0,
+				key_delim = u' | ',
+				data_delim = u' | ',
+				missing_string = u'',
+				ignore_diff_in_keys = ['audit__action_applied', 'audit__action_when', 'audit__action_by', 'pk_audit', 'row_version', 'modified_when', 'modified_by']
+			))
+		return lines
+
 	#--------------------------------------------------------
 	def refetch_payload(self, ignore_changes=False, link_obj=None):
 		"""Fetch field values from backend.
@@ -542,7 +591,7 @@ def delete_xxx(pk_XXX=None):
 			compare_dict_likes(self.original_payload, self.fields_as_dict(date_format = None, none_string = None), u'original payload', u'modified payload')
 			if ignore_changes:
 				_log.critical('[%s:%s]: loosing payload changes' % (self.__class__.__name__, self.pk_obj))
-				#_log.debug('original: %s' % self.original_payload)
+				#_log.debug('most recently fetched: %s' % self.payload_most_recently_fetched)
 				#_log.debug('modified: %s' % self._payload)
 			else:
 				_log.critical('[%s:%s]: cannot reload, payload changed' % (self.__class__.__name__, self.pk_obj))
@@ -585,7 +634,7 @@ def delete_xxx(pk_XXX=None):
 		args = {}
 		for field in self._idx.keys():
 			args[field] = self._payload[self._idx[field]]
-		self.modified_payload = args
+		self.payload_most_recently_attempted_to_store = args
 
 		close_conn = self.__noop
 		if conn is None:
@@ -637,9 +686,9 @@ def delete_xxx(pk_XXX=None):
 		close_conn()
 
 		# update to new "original" payload
-		self.original_payload = {}
+		self.payload_most_recently_fetched = {}
 		for field in self._idx.keys():
-			self.original_payload[field] = self._payload[self._idx[field]]
+			self.payload_most_recently_fetched[field] = self._payload[self._idx[field]]
 
 		return (True, None)
 
@@ -698,12 +747,12 @@ def jsonclasshintify(obj):
 		for k in obj.get_fields():
 			t = jsonclasshintify(obj[k])
 			res[k] = t
-		print "props", res, dir(obj)
+		print("props", res, dir(obj))
 		for attribute in dir(obj):
 			if not attribute.startswith("get_"):
 				continue
 			k = attribute[4:]
-			if res.has_key(k):
+			if k in res:
 				continue
 			getter = getattr(obj, attribute, None)
 			if callable(getter):
@@ -742,9 +791,10 @@ if __name__ == '__main__':
 		'data': [-1, 'bogus_data', datetime.datetime.now()]
 	}
 	obj = cTestObj(row=data)
-	#print obj['wrong_field']
-	#print jsonclasshintify(obj)
+	#print(obj['wrong_field'])
+	#print(jsonclasshintify(obj))
 	#obj['wrong_field'] = 1
-	print obj.fields_as_dict()
+	#print(obj.fields_as_dict())
+	print(obj.format())
 
 #============================================================
diff --git a/server/pycommon/gmCfg.py b/server/pycommon/gmCfg.py
index 3bc4336..f89a5cd 100644
--- a/server/pycommon/gmCfg.py
+++ b/server/pycommon/gmCfg.py
@@ -25,7 +25,7 @@ The database config objects auto-sync with the backend.
 __author__ = "Karsten Hilbert <Karsten.Hilbert at gmx.net>"
 
 # standard modules
-import sys, types, cPickle, decimal, logging, re as regex
+import sys, types, pickle, decimal, logging, re as regex
 
 
 # gnumed modules
@@ -186,7 +186,7 @@ class cCfgSQL:
 		rows, idx = gmPG2.run_ro_queries(link_obj=self.ro_conn, queries = [{'cmd': cmd, 'args': args}])
 		if len(rows) > 0:
 			if cfg_table_type_suffix == u'data':
-				return cPickle.loads(str(rows[0][0]))
+				return pickle.loads(str(rows[0][0]))
 			return rows[0][0]
 
 		_log.warning('no user AND workplace specific value for option [%s] in config database' % option)
@@ -224,7 +224,7 @@ class cCfgSQL:
 				value = rows[0][0]
 			)
 			if cfg_table_type_suffix == u'data':
-				return cPickle.loads(str(rows[0][0]))
+				return pickle.loads(str(rows[0][0]))
 			return rows[0][0]
 
 		_log.warning('no user OR workplace specific value for option [%s] in config database' % option)
@@ -250,7 +250,7 @@ class cCfgSQL:
 				value = rows[0]['value']
 			)
 			if cfg_table_type_suffix == u'data':
-				return cPickle.loads(str(rows[0]['value']))
+				return pickle.loads(str(rows[0]['value']))
 			return rows[0]['value']
 
 		_log.warning('no default site policy value for option [%s] in config database' % option)
@@ -346,9 +346,9 @@ limit 1""" % where_clause
 			pass
 		else:
 			try:
-				opt_value = gmPG2.dbapi.Binary(cPickle.dumps(value))
+				opt_value = gmPG2.dbapi.Binary(pickle.dumps(value))
 				sql_type_cast = '::bytea'
-			except cPickle.PicklingError:
+			except pickle.PicklingError:
 				_log.error("cannot pickle option of type [%s] (key: %s, value: %s)", type(value), alias, str(value))
 				raise
 			except:
diff --git a/server/pycommon/gmCfg2.py b/server/pycommon/gmCfg2.py
index 91e6608..a6ac311 100644
--- a/server/pycommon/gmCfg2.py
+++ b/server/pycommon/gmCfg2.py
@@ -7,7 +7,7 @@ __licence__ = "GPL"
 
 import logging
 import sys
-import codecs
+import io
 import re as regex
 import shutil
 import os
@@ -81,7 +81,7 @@ def __set_opt_in_INI_file(src=None, sink=None, group=None, option=None, value=No
 
 	# need to add group ?
 	if not group_seen:
-		sink.write('[%s]\n' % group)
+		sink.write(u'[%s]\n' % group)
 
 	# We either just added the group or it was the last group
 	# but did not contain the option. It must have been the
@@ -113,9 +113,9 @@ def __set_list_in_INI_file(src=None, sink=None, group=None, option=None, value=N
 			# our option ?
 			if regex.match('%s(\s|\t)*=(\s|\t)*\$%s\$' % (option, option), line.strip()) is not None:
 				sink.write(line)										# list header
-				sink.write('\n'.join(value))
-				sink.write('\n')
-				sink.write('$%s$\n' % option)							# list footer
+				sink.write(u'\n'.join(value))
+				sink.write(u'\n')
+				sink.write(u'$%s$\n' % option)							# list footer
 				our_list_seen = True
 				inside_our_list = True
 				continue
@@ -125,10 +125,10 @@ def __set_list_in_INI_file(src=None, sink=None, group=None, option=None, value=N
 				# our list already handled ?  (if so must already be finished)
 				if not our_list_seen:
 					# no, so need to add our list to the group before ...
-					sink.write('%s = $%s$\n' % (option, option))		# list header
-					sink.write('\n'.join(value))
-					sink.write('\n')
-					sink.write('$%s$\n' % option)						# list footer
+					sink.write(u'%s = $%s$\n' % (option, option))		# list header
+					sink.write(u'\n'.join(value))
+					sink.write(u'\n')
+					sink.write(u'$%s$\n' % option)						# list footer
 					our_list_seen = True
 					inside_our_list = False
 				# ... starting the next group
@@ -151,17 +151,17 @@ def __set_list_in_INI_file(src=None, sink=None, group=None, option=None, value=N
 
 	# looped over all lines but did not find our group, so add group
 	if not our_group_seen:
-		sink.write('[%s]\n' % group)
+		sink.write(u'[%s]\n' % group)
 
 	if not our_list_seen:
 		# We either just added the group or it was the last group
 		# but did not contain the option. It must have been the
 		# last group then or else the group following it would have
 		# triggered the option writeout.
-		sink.write('%s = $%s$\n' % (option, option))
-		sink.write('\n'.join(value))
-		sink.write('\n')
-		sink.write('$%s$\n' % option)
+		sink.write(u'%s = $%s$\n' % (option, option))
+		sink.write(u'\n'.join(value))
+		sink.write(u'\n')
+		sink.write(u'$%s$\n' % option)
 
 #==================================================================
 def __set_list_in_INI_file_old(src=None, sink=None, group=None, option=None, value=None):
@@ -194,8 +194,8 @@ def __set_list_in_INI_file_old(src=None, sink=None, group=None, option=None, val
 			if our_group_seen and (match.group('list_name') == option):
 				option_seen = True
 				sink.write(line)
-				sink.write('\n'.join(value))
-				sink.write('\n')
+				sink.write(u'\n'.join(value))
+				sink.write(u'\n')
 				continue
 			sink.write(line)
 			continue
@@ -217,9 +217,9 @@ def __set_list_in_INI_file_old(src=None, sink=None, group=None, option=None, val
 			# next group but option not seen yet ?
 			if our_group_seen and not option_seen:
 				option_seen = True
-				sink.write('%s = $%s$\n' % (option, option))
-				sink.write('\n'.join(value))
-				sink.write('\n')
+				sink.write(u'%s = $%s$\n' % (option, option))
+				sink.write(u'\n'.join(value))
+				sink.write(u'\n')
 				continue
 			sink.write(line)
 			continue
@@ -233,16 +233,17 @@ def __set_list_in_INI_file_old(src=None, sink=None, group=None, option=None, val
 
 	# need to add group ?
 	if not our_group_seen:
-		sink.write('[%s]\n' % group)
+		sink.write(u'[%s]\n' % group)
 
 	# We either just added the group or it was the last group
 	# but did not contain the option. It must have been the
 	# last group then or else the following group would have
 	# triggered the option writeout.
-	sink.write('%s = $%s$\n' % (option, option))
-	sink.write('\n'.join(value))
-	sink.write('\n')
-	sink.write('$%s$\n' % option)
+	sink.write(u'%s = $%s$\n' % (option, option))
+	sink.write(u'\n'.join(value))
+	sink.write(u'\n')
+	sink.write(u'$%s$\n' % option)
+
 #==================================================================
 def set_option_in_INI_file(filename=None, group=None, option=None, value=None, encoding='utf8'):
 
@@ -252,8 +253,8 @@ def set_option_in_INI_file(filename=None, group=None, option=None, value=None, e
 	sink = tempfile.NamedTemporaryFile(suffix = '.cfg', delete = True)
 	sink_name = sink.name
 	sink.close()	# close it so it gets deleted so we can safely open it again
-	src = codecs.open(filename = filename, mode = 'rU', encoding = encoding)
-	sink = codecs.open(filename = sink_name, mode = 'wb', encoding = encoding)
+	src = io.open(filename, mode = 'rt', encoding = encoding)
+	sink = io.open(sink_name, mode = 'wt', encoding = encoding)
 
 	# is value a list ?
 	if isinstance(value, type([])):
@@ -265,6 +266,7 @@ def set_option_in_INI_file(filename=None, group=None, option=None, value=None, e
 	src.close()
 
 	shutil.copy2(sink_name, filename)
+
 #==================================================================
 def parse_INI_stream(stream=None):
 	"""Parse an iterable for INI-style data.
@@ -329,7 +331,7 @@ def parse_INI_stream(stream=None):
 
 		current_option = name
 		current_option_path = '%s::%s' % (current_group, current_option)
-		if data.has_key(current_option_path):
+		if current_option_path in data:
 			_log.warning(u'duplicate option [%s]', current_option_path)
 
 		value = remainder.split(u'#', 1)[0].strip()
@@ -434,7 +436,7 @@ class gmCfgData(gmBorg.cBorg):
 			_log.exception('error parsing source <%s> from [%s]', source, stream)
 			raise
 
-		if self.__cfg_data.has_key(source):
+		if source in self.__cfg_data:
 			_log.warning('overriding source <%s> with [%s]', source, stream)
 
 		self.__cfg_data[source] = data
@@ -453,13 +455,13 @@ class gmCfgData(gmBorg.cBorg):
 		cfg_file = None
 		if file is not None:
 			try:
-				cfg_file = codecs.open(filename = file, mode = 'rU', encoding = encoding)
+				cfg_file = io.open(file, mode = 'rt', encoding = encoding)
 			except IOError:
 				_log.error('cannot open [%s], keeping as dummy source', file)
 
 		if cfg_file is None:
 			file = None
-			if self.__cfg_data.has_key(source):
+			if source in self.__cfg_data:
 				_log.warning('overriding source <%s> with dummy', source)
 			self.__cfg_data[source] = {}
 		else:
@@ -544,8 +546,8 @@ if __name__ == "__main__":
 		cfg = gmCfgData()
 		cfg.add_cli(short_options=u'h?', long_options=[u'help', u'conf-file='])
 		cfg.set_option('internal option', True)
-		print cfg.get(option = '--help', source_order = [('cli', 'return')])
-		print cfg.get(option = '-?', source_order = [('cli', 'return')])
+		print (cfg.get(option = '--help', source_order = [('cli', 'return')]))
+		print (cfg.get(option = '-?', source_order = [('cli', 'return')]))
 		fname = cfg.get(option = '--conf-file', source_order = [('cli', 'return')])
 		if fname is not None:
 			cfg.add_file_source(source = 'explicit', file = fname)
diff --git a/server/pycommon/gmConfigCommon.py b/server/pycommon/gmConfigCommon.py
deleted file mode 100644
index 63ae47b..0000000
--- a/server/pycommon/gmConfigCommon.py
+++ /dev/null
@@ -1,872 +0,0 @@
-"""GNUmed: Mid-level configuration editor object.
-
-Theory of operation:
-
-ConfigSourceDB/File holds config data (read from backend or file) and related
-config definitions. Definitions are retrieved automatically from a given config
-definition file (if available). See _defaultDefSourceTable below for standard file
-names.
-
-First get a list of available config parameters through getAllParamNames (returns
-names + metadata), get the values using GetConfigData, change, check for validity
-using isValid (if definition data and parameter definition is available) and 
-set data using SetConfigData.
-License: GNU Public License 
-"""
-#==================================================================
-# $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/client/pycommon/gmConfigCommon.py,v $
-__version__ = "$Revision: 1.10 $"
-__author__ = "H.Berger,K.Hilbert"
-
-import sys, os, string, types, pickle
-
-from Gnumed.pycommon import gmCfg, gmPG2
-
-_log = gmLog.gmDefLog
-if __name__ == '__main__':
-	_log.SetAllLogLevels(gmLog.lData)
-	_ = lambda x:x
-
-_log.Log(gmLog.lData, __version__)
-_cfg = gmCfg.gmDefCfgFile
-_defaultDefSourceTable = {
-	'DB:CURRENT_USER_CURRENT_WORKPLACE': 'config-definitions/DBDefault.definitions',
-	'DB:CURRENT_USER_DEFAULT_WORKPLACE' : 'config-definitions/DBDefault.definitions',
-	'DB:DEFAULT_USER_CURRENT_WORKPLACE' : 'config-definitions/DBDefault.definitions',
-	'DB:DEFAULT_USER_DEFAULT_WORKPLACE' : 'config-definitions/DBDefault.definitions',
-	'gnumed.conf': 'config-definitions/gnumed.conf.definitions'
-}
-
-###############################################################################
-class ConfigSource:
-	"""Base class for interface to access config data and definitions on a single 
-	   configuration source (config file, user/workplace specific backend data
-	   collection.
-	   The source name will be used to retrieve the config definitions from
-	   a config definition source (file, DB) automatically.
-	"""
-	
-	_DefinitionSourceTable = None
-	
-	def __init__(self,aSourceType=None,aSourceName=None,aDataSource=None):
-		self.mSourceType = aSourceType
-		self.mSourceName = aSourceName
-		self.mDataSource = aDataSource
-
-		if ConfigSource._DefinitionSourceTable is None:
-			ConfigSource._DefinitionSourceTable=self.__getDefinitionSourceTable()
-		
-		try:
-			DefinitionSource = ConfigSource._DefinitionSourceTable[self.mSourceName]
-			self.mDefinitionSource = ConfigDefinition(DefinitionSource)
-		except:
-			_log.Log(gmLog.lWarn, "No definition source found for %s" % self.mSourceName)
-			self.mDefinitionSource = None 
-
-	#---------------------------------------------------------------------
-	# TODO : get definition source table from cfg file if available
-	def __getDefinitionSourceTable(self):
-		return _defaultDefSourceTable
-			
-	#------------------------------------------------------------------------
-	def getParamType(self, aParam = None):
-		""" get type of parameter value """
-
-		# try to get the type from config definitions
-		# if this fails, get last known type from config data dict 
-		definitionType = None
-
-		if not self.mDefinitionSource is None:
-			definitionName = self.mDataSource.getRawName(aParam)
-			definitionType = self.mDefinitionSource.getParamType(definitionName)
-
-		if not definitionType is None:
-			mType = definitionType
-		else:
-			mType = self.mDataSource.getParamType(aParam)
-
-		return mType
-
-	#------------------------------------------------------------------------
-	def castType(self, aParam = None, aValue=None):
-		""" cast type of entered parameter value to the previously existing type."""
-					
-		castType = self.getParamType(aParam)
-		if castType == 'str_array':
-			castedVal = string.split(aValue,'\n')
-			if not type(castedVal) is types.ListType:
-				castedVal = [str(castedVal)]
-		elif castType == 'numeric':
-			if not type(eval(aValue)) in (types.IntType, types.FloatType, types.LongType):
-				castedVal = None
-			else:
-				castedVal = eval(aValue)
-		elif castType == 'string':
-			castedVal = str(aValue)
-
-		return castedVal
-
-	#----------------------------------------------------------------------
-	def getDescription(self, aParam=None):
-		"""
-		Get parameter description either from config definition or from config data
-		"""
-		# if no parameter definition is available, get definition from data
-		# source
-		definitionName = self.mDataSource.getRawName(aParam)
-		description = None
-		if not self.mDefinitionSource is None:
-			description = self.mDefinitionSource.getParamDescription(definitionName)
-		
-		if  description is None:
-			description = self.mDataSource.getParamDescription(aParam)
-
-		return description
-
-	# here come the wrapper functions that link to config data and definition
-	# objects
-	#---------------------------------------------------------------------
-	def getAllParamNames(self):
-		"""
-		Get all parameter names from backend or a file.
-		Returns dict of names + metadata.
-		format:
-		dict {'name1': [namepart_2,namepart_1,owner,type,description],
-		       'name2': [option,group,owner,type,description],...}
-		usually the full name is a composition of namepart_1 +_2, 
-		but don't rely on the order - it depends on whether you get 
-		data from DB or file. type is the type as found in the data 
-		(one of 'string', 'string_arr' or 'numeric'). description is the
-		description supplied with the data, not the one given in the
-		parameter definition file ! Use getDescription() to get the right 
-		one.
-		"""
-		if not self.mDataSource is None:
-			return self.mDataSource.getAllNames()
-	#---------------------------------------------------------------------
-	def setConfigData(self,aParam,aValue):
-		"""
-		Set config data for a aParam to aValue.
-		"""
-		return self.mDataSource.SetConfigData(aParam,aValue)
-	#---------------------------------------------------------------------
-	def getConfigData(self,aParam):
-		"""
-		Get config data for a aParam.
-		"""
-		return self.mDataSource.GetConfigData(aParam)
-
-	#---------------------------------------------------------------------
-	def addConfigParam(self,aParam,aType,aValue,aDescription):
-		"""
-		Adds config new config parameter.
-		"""
-		return self.mDataSource.AddConfigParam(aParam,aType,aValue,aDescription)
-	#---------------------------------------------------------------------
-	def getRawName(self,aParam):
-		"""Get config data for a aParam."""
-		return self.mDataSource.getRawName(aParam)
-	#---------------------------------------------------------------------
-	def hasDefinition(self):
-		""" return true if config definition object is available"""
-		return ( not self.mDefinitionSource is None)	
-		
-	#---------------------------------------------------------------------
-	def hasParameterDefinition(self,aParam):
-		"""
-		Returns true if config definition is available for this
-		parameter.
-		"""
-		return self.mDefinitionSource.hasParameter(aParam)
-
-	#---------------------------------------------------------------------
-	def isValid(self,aParam,aValue):
-		"""
-		Returns true if aValue matches config definition for this
-		parameter.
-		"""
-		return self.mDefinitionSource.isValid(aParam,aValue)
-
-		
-###############################################################################
-class ConfigSourceDB(ConfigSource):
-	"""Interface to access config data and definitions in a single 
-	   configuration user/workplace specific backend data collection.
-	"""
-	def __init__(self, aSourceName=None,aUser = None, aWorkplace = 'xxxDEFAULTxxx'):
-		try:
-			mConfigDataSource = ConfigDataDB(aUser,aWorkplace)
-		except:	
-			mConfigDataSource = None
-
-		ConfigSource.__init__(self,"DB",aSourceName,mConfigDataSource)
-
-
-###############################################################################
-class ConfigSourceFile(ConfigSource):
-	"""
-	Interface to access config data and definitions in a config file.
-	"""
-	def __init__(self, aSourceName=None,aFileName=None):
-		try:
-			mConfigDataSource = ConfigDataFile(aFileName)		
-		except:	
-			mConfigDataSource = None
-
-		ConfigSource.__init__(self,"FILE",aSourceName,mConfigDataSource)
-			
-
-	def GetFullPath(self):
-		if not self.mDataSource is None:
-			return self.mDataSource.GetFullPath()
-		
-###############################################################################
-class ParameterDefinition:
-	"""Describes a gnumed configuration parameter.
-	"""
-	def __init__(self,aParamName = None,aParamType = None,aValidValsList = None,aParamDescription = None):
-		self.mName = aParamName
-		self.mType = aParamType
-		self.mDescription = aParamDescription
-		# perhaps make this a class <validator>, too ?
-		# - one method: bool isValid()
-		# - derived classes for:
-		#   validator -> string -> font
-		#   validator -> string -> color
-		#   validator -> numeric -> range
-		#   ...
-		self.mValidVals = aValidValsList
-
-	#---------------------------------------------------------------------
-	def isValid(self,aValue):
-		if self.mType == "string":
-			return self.__isString(aValue)
-		elif self.mType == "str_array":
-			return self.__isStringArray(aValue)
-		elif self.mType == "numeric":
-			return self.__isNumeric(aValue)
-		else:
-			_log.Log (gmLog.lPanic, "isValid %s - %s %s" % (self.mName, self.mType, aValue))
-			return 0
-			
-	#---------------------------------------------------------------------
-	def __isString(self,aValue):
-		if type(aValue) == types.StringType or type (s) == types.UnicodeType:
-			if self.mValidVals is None:
-				return 1
-			elif str(aValue) in (self.mValidVals):
-				return 1
-		return 0
-	
-	#---------------------------------------------------------------------
-	def __isStringArray(self,aValue):
-		# value must be a list and all elements must be strings
-		if type(aValue) == types.ListType:
-			for s in (aValue):
-				if not (type(s) == types.StringType or type (s) == types.UnicodeType):
-					return 0
-			return 1
-		return 0
-
-	#---------------------------------------------------------------------
-	def __isNumeric(self,aValue):
-		if type(aValue) in (types.IntType, types.FloatType, types.LongType):
-			if self.mValidVals is None:
-				return 1
-			elif str(aValue) in (self.mValidVals):
-				return 1
-		return 0
-
-###############################################################################
-# IDEAS: if no config definition is available, we should make the 
-# data read-only by default, and only allow change after an explicit warning
-# TODO : almost all
-class ConfigDefinition:
-	""" holds config definitions read from a file/DB.
-	this will contain: 
-		a) config parameter names
-		b) config parameter description (optional)
-		c) config parameter type
-		d) config parameter valid values (if type is select_from_list)
-		e) config information version (must match the version used in ConfigData)
-	"""
-
-	def __init__(self, aDefinitionSource=None):
-		# get queries from configuration source (currently only files are supported)
-
-		self.__mParameterDefinitions = {}
-		self.__mVersion = None
-
-		if aDefinitionSource is None:
-			_log.Log(gmLog.lWarn, "No configuration definition source specified")
-			# we want to return an error here 
-			# in that case we'll have to raise an exception... can't return
-			# anything else than None from an __init__ method
-			raise TypeError, "No configuration definition source specified !"
-		else:
-			self.__mDefinitionSource = aDefinitionSource
-			if not self.__getDefinitions():
-				raise IOError, "cannot load definitions"
-		
-	#------------------------------------------------------------------------
-	def hasParameter(self, aParameterName = None):
-		return self.__mParameterDefinitions.has_key(aParameterName)
-		
-	#------------------------------------------------------------------------
-	def isValid(self,aParameterName=None,aValue=None):
-		if self.hasParameter(aParameterName):
-			return self.__mParameterDefinitions[aParameterName].isValid(aValue)		
-		else:
-			return 0
-
-	#------------------------------------------------------------------------
-	def getParamType(self, aParameterName = None):
-		if self.hasParameter(aParameterName):
-			return self.__mParameterDefinitions[aParameterName].mType
-
-	#------------------------------------------------------------------------
-	def getParamDescription(self, aParameterName = None):
-		if self.hasParameter(aParameterName):
-			return self.__mParameterDefinitions[aParameterName].mDescription
-						
-	#------------------------------------------------------------------------
-	def __getDefinitions(self):
-		"""get config definitions"""
-
-		# open configuration definition source
-		try:
-			cfgDefSource = gmCfg.cCfgFile(aFile = self.__mDefinitionSource, \
-				flags=gmCfg.cfg_SEARCH_STD_DIRS | gmCfg.cfg_IGNORE_CMD_LINE)
-			# handle all exceptions including 'config file not found'
-		except:
-			exc = sys.exc_info()
-			_log.LogException("Unhandled exception while opening config file [%s]" % self.__mDefinitionSource, exc,verbose=0)
-			return None
-
-		cfgData = cfgDefSource.getCfg()
-		groups = cfgDefSource.getGroups()
-
-		if not '_config_version_' in (groups):
-			_log.Log(gmLog.lWarn, "No configuration definition version defined.")
-			_log.Log(gmLog.lWarn, "Matching definitions to config data is unsafe.")
-			_log.Log(gmLog.lWarn, "Config data will be read-only by default.")
-			self.mVersion = None
-		else:
-			version = cfgDefSource.get('_config_version_', "version")
-			# we don't check for type in order to allow for versions like '1.20.1b'			 
-			self.__mVersion = version
-			_log.Log(gmLog.lInfo, "Found config parameter definition version %s in %s" % (version,self.__mDefinitionSource))
-
-
-		# every group holds one parameter description
-		# group name = parameter name
-		for paramName in groups:
-			# ignore config version group
-			if paramName == '_config_version_':
-				continue
-
-			paramType = cfgDefSource.get(paramName, "type")			
-			if paramType is None:
-				continue
-			
-			# parameter description - might differ from that stored 
-			# in backend tables (cfg_template)
-			paramDescription = cfgDefSource.get(paramName, "description")
-			if paramDescription is None:
-				continue
-
-			validValuesRaw = None
-			# if valid value list is supplied, get it
-			if "validvalue" in (cfgDefSource.getOptions(paramName)):
-				validValuesRaw = cfgDefSource.get(paramName, "validvalues")
-			# transform valid values to a list
-			validVals = None
-			if not validValuesRaw is None:
-				if type(validValuesRaw) == types.ListType:
-					validVals = validValuesRaw
-			
-			# add new entry to parameter definition dictionary
-			self.__mParameterDefinitions
-			self.__mParameterDefinitions[paramName] = ParameterDefinition(paramName,paramType,validVals,paramDescription)
-		return 1
-
-###############################################################################
-# TODO: 
-# -handle backend data modifications using backend notification
-# -method to change/add new parameters
-
-class ConfigData:
-	""" 
-    Base class. Derived classes hold config data for a particular 
-	backend user/workplace combination, config file etc.	    
-	this will contain: 
-		a) config parameter names
-		b) config parameter values
-		c) config information version (must match the version used in ConfigDefinition)
-	"""
-
-	def __init__(self, aType = None):
-		self.type = aType
-		self.mConfigData = {}
-
-# pure virtual methods
-	def GetAllNames(self):
-		pass
-
-	def GetConfigData(self):
-		pass
-
-	def SetConfigData(self):
-		pass    	
-
-	def getRawName(self):
-		pass
-
-	def AddConfigParam(self):
-		pass
-		
-	#---------------------------------------------------------------------
-	def getParamType(self,aParameterName = None):
-		"""
-		Returns the parameter type as found in the data source.
-		"""
-		try:
-			return self.mConfigData[aParameterName][3]
-		except KeyError:
-		# is it possible to have a parameter without type ??
-		# TODO
-			return None
-
-	#---------------------------------------------------------------------
-	def getParamDescription(self,aParameterName = None):
-		"""
-		Returns the parameter type as found in the data source.
-		"""
-		try:
-			return self.mConfigData[aParameterName][4]
-		except KeyError:
-			return None
-
-
-#--------------------------------------------------------------------------
-class ConfigDataDB(ConfigData):
-	""" 
-	Class that holds config data for a particular user/workplace pair 
-	"""
-	# static class variables that hold links to backend and gmCfg
-	# this will be shared by all ConfigDataDB objects
-	# this assumes that there will always be only one backend config source
-	_dbcfg = None
-
-	def __init__(self, aUser = None, aWorkplace = 'xxxDEFAULTxxx'):
-		""" Init DB connection"""
-		ConfigData.__init__(self,"DB")
-		
-		# connect to config database
-		if ConfigDataDB._dbcfg is None:
-			ConfigDataDB._dbcfg = gmCfg.cCfgSQL()
-
-		self.mUser = aUser
-		self.mWorkplace = aWorkplace
-	#---------------------------------------------------------------------
-	def GetConfigData(self, aParameterName = None):
-		"""
-		Gets Config Data for a particular parameter. 
-		Returns parameter value.
-		"""
-		try:
-#			print "param name:", aParameterName
-			name=self.mConfigData[aParameterName][0]
-			cookie = self.mConfigData[aParameterName][1]
-#			print "name:", name
-#			print "cookie.", cookie
-			result = ConfigDataDB._dbcfg.get2 (
-				workplace=self.mWorkplace,
-#				self.mUser,
-				cookie = cookie,
-				option = name,
-				bias = 'user'
-			)
-		except:
-			_log.Log(gmLog.lErr, "Cannot get parameter value for [%s]" % aParameterName )
-			return None
-		return result
-		
-	#---------------------------------------------------------------------
-	def SetConfigData(self, aParameterName, aValue):
-		"""
-		Sets Config Data for a particular parameter. 
-		"""
-		try:
-			name=self.mConfigData[aParameterName][0]
-			cookie = self.mConfigData[aParameterName][1]
-			result=ConfigDataDB._dbcfg.set (
-				workplace = self.mWorkplace,
-#				user = self.mUser,
-				cookie = cookie,
-				option = name,
-				value = aValue,
-			)
-		except:
-			_log.Log(gmLog.lErr, "Cannot set parameter value for [%s]" % aParameterName )
-			return None
-		return 1
-	#---------------------------------------------------------------------
-	# aType is not used so far. Do we need it ?
-	# TODO: maybe we could combine that with SetConfigData (the low level methods in gmCfg do add/update, anyways)
-	def AddConfigParam(self, aParameterName, aType = None ,aValue=None,aDescription = None):
-		"""
-		Adds a new config parameter. 
-		Note: You will have to re-read the cache (call GetAllNames())
-		in order to change this parameter afterwards.
-		"""
-		# make sure that the pameter does not exist yet
-		if self.mConfigData.has_key(aParameterName):
-			return None
-		
-		# now we have to split the parameter name into 
-		# option and cookie part
-		
-		pNameParts  = string.split(aParameterName,".")
-		# check if we have a cookie
-		if pNameParts[-1][0] == '_':
-			cookie = pNameParts[-1][1:]
-			option = string.join(pNameParts[:-1],".")
-		else:
-			cookie = None
-			option = aParameterName
-			
-#		print "[%s, %s]" % (cookie, option)		
-		if option is None:
-			return None
-		# now actually write the new parameter
-		try:
-			result=ConfigDataDB._dbcfg.set (
-				workplace = self.mWorkplace, 
-#				user = self.mUser,
-				cookie = cookie,
-				option = option,
-				value = aValue,
-			)
-		except:
-			_log.Log(gmLog.lErr, "Cannot set parameter value for [%s]" % aParameterName )
-			return None
-		# now we should re-read the name cache in order to have 
-		# consistent data. Since we wont signal the frontend, we will
-		# have to do this manually in the fronend 
-
-		return 1
-	#---------------------------------------------------------------------
-	def getAllNames(self):
-		"""
-		fetch names and parameter data from backend. Returns list of
-		parameter names where cookie and real name are concatenated.
-		Refreshes the parameter cache, too.
-		"""
-		result=ConfigDataDB._dbcfg.getAllParams(self.mUser,self.mWorkplace)
-		if not result:
-			return None
-		else:
-			# gmCfg.getAllParams returns name,cookie, owner, type and description 
-			# of a parameter. 
-			# We combine name + cookie to one single name. If cookie == 'xxxDEFAULTxxx'
-			# we set the last part of the name to "" (an empty part). This
-			# must processed by the ConfigTree so that the empty part is not 
-			# displayed. If the cookie is something else, we mark the cookie part
-			# by a leading "._"
-			mParamNames = []
-			# for param in (result): why???
-			for param in result:
-				name = param[0]
-				cookie = param[1]
-				if cookie == 'xxxDEFAULTxxx':
-					cookie_part = ""
-				else:
-					cookie_part = "._%s" % cookie
-
-				newName = name + cookie_part
-				# store data for every parameter in mConfigData
-				self.mConfigData[newName]=param
-				# add new name to list
-				mParamNames.append(newName)
-#DEBUG		
-#		_log.Log (gmLog.lData, "%s" % self.mConfigData)
-
-		return mParamNames
-
-	#---------------------------------------------------------------------
-	def getRawName(self,aParameterName = None):
-		"""
-		Returns the parameter name without possible cookie part(s).
-		Needed to indentify matching config definition entry.
-		"""
-		try:
-			return self.mConfigData[aParameterName][0]
-		except KeyError:
-			return None
-
-#--------------------------------------------------------------------------
-class ConfigDataFile(ConfigData):
-	""" 
-	Class that holds config data for a particular config file
-	"""
-	def __init__(self, aFilename = None):
-		""" Init config file """
-		ConfigData.__init__(self,"FILE")
-
-		self.filename = aFilename
-		self.__cfgfile = None
-		self.fullPath = None
-				
-		# open config file
-		try:
-			self.__cfgfile = gmCfg.cCfgFile(aFile = self.filename)
-			# this is a little bit ugly, but we need to get the full name of the
-			# file because this depends on the installation/system settings
-			# if no absolute path was specified, we get the config file gnumed
-			# would find first which is what we want usually
-			self.fullPath = self.__cfgfile.cfgName
-
-		except:
-			_log.LogException("Can't open config file !", sys.exc_info(), verbose=0)
-			raise ConstructorError, "ConfigDataFile: couldn't open config file"
-
-	#---------------------------------------------------------------------
-	def GetFullPath(self):
-		""" returns the absolute path to the config file in use"""
-		return self.fullPath
-
-	#---------------------------------------------------------------------
-	def GetConfigData(self, aParameterName = None):
-		"""
-		Gets Config Data for a particular parameter. 
-		Returns parameter value.
-		"""
-		name=self.mConfigData[aParameterName][0]
-		group = self.mConfigData[aParameterName][1]
-		try:
-			result=self.__cfgfile.get(group,name)
-		except:
-			_log.Log(gmLog.lErr, "Cannot get parameter value for [%s]" % aParameterName )
-			return None
-		return result
-		
-	#---------------------------------------------------------------------
-	def SetConfigData(self, aParameterName = None, aValue = None):
-		"""
-		Sets Config Data for a particular parameter. 
-		"""
-		option = self.mConfigData[aParameterName][0]
-		group = self.mConfigData[aParameterName][1]
-		try:
-			result=self.__cfgfile.set(aGroup = group,
-						anOption = option,
-						aValue = aValue)
-			self.__cfgfile.store()
-		except:
-			_log.Log(gmLog.lErr, "Cannot set parameter value for [%s]" % aParameterName )
-			return None
-		return 1
-
-	#---------------------------------------------------------------------
-	def AddConfigParam(self, aParameterName, aType = None ,aValue=None, aDescription =None):
-		"""
-		Adds a new config parameter. 
-		"""
-		pNameParts  = string.split(aParameterName,".")
-		# check if we have a cookie
-		option = pNameParts[-1:][1:]
-		group = string.join(pNameParts[:-1],".")
-		if option is None or group is None:
-			return None
-
-		try:
-			result=self.__cfgfile.set(aGroup = group,
-						anOption = option,
-						aValue = aValue,
-						aComment = aDescription)
-			self.__cfgfile.store()
-		except:
-			_log.Log(gmLog.lErr, "Cannot set parameter value for [%s]" % aParameterName )
-			return None
-		return 1
-
-	#---------------------------------------------------------------------
-	def getAllNames(self):
-		"""
-		fetch names and parameter data from config file. Returns list of
-		parameter names where group and option name are concatenated.
-		"""
-		
-		# this returns name,cookie, owner (TODO), type and description 
-		# of a parameter. 
-		# We combine group + option name to one single name. 
-		groups = self.__cfgfile.getGroups()
-		if len(groups) == 0:
-			return None
-		mParamNames = []		
-		for group in (groups):
-			options = self.__cfgfile.getOptions(group)
-			if len(options) == 0:
-				continue
-			else:
-				for option in (options):			
-					currType=type(self.__cfgfile.get(group,option))
-					if currType in (types.IntType, types.FloatType, types.LongType):
-						myType = 'numeric'
-					elif currType is types.StringType:
-						myType = 'string'
-					elif currType is types.ListType:
-						myType = 'str_array'
-					else:
-					# FIXME: we should raise an exception here or make the entry
-					# read only since we don't know how to handle this entry
-						mType = 'string'
-
-					description = self.__cfgfile.getComment(group,option)
-					if description is []:
-						description = ''
-					else:
-						myDescription = string.join(description,'\n')
-					optionData=[option,group,'',myType,myDescription]
-
-					newName = group + '.' + option
-					self.mConfigData[newName] = optionData
-					mParamNames.append(newName)
-			
-#DEBUG		
-#		_log.Log (gmLog.lData, "%s" % self.mConfigData)
-
-		return mParamNames
-
-	#---------------------------------------------------------------------
-	def getRawName(self,aParameterName = None):
-		"""
-		Returns the parameter name without possible cookie part(s).
-		Needed to indentify matching config definition entry.
-		"""
-		# since CfgFile does not know about cookies, just return 
-		# the parameter name
-
-		return aParameterName
-
-
-#=========================================================================
-def exportDBSet(filename,aUser = None, aWorkplace = 'xxxDEFAULTxxx'):
-	"""
-	Fetches a backend stored set of config options (defined by user and workplace)
-	and returns it as a plain text file.
-	NOTE: This will not write "valid value" information, since this is only
-	hold in config definition files !
-	Returns: 1 for success, 0 if no parameters were found, None on failure.
-	"""
-	try:
-		expConfigSource = ConfigSourceDB("export",aUser,aWorkplace)
-	except:
-		_log.Log(gmLog.lErr, "Cannot open config set [%s@%s]." % (aUser,aWorkplace))
-		return None
-		
-	try:
-		file = open(filename,"w")
-	except:
-		_log.Log(gmLog.lErr, "Cannot open output file %s." % (filename))
-		raise
-		
-	paramList = expConfigSource.getAllParamNames()
-	if paramList is None:
-		_log.Log(gmLog.lInfo, "DB-set [%s,%s]contained no data." % (aUser,aWorkplace))
-		return 0
-	text = ''
-	for param in (paramList):
-		description = expConfigSource.getDescription(param)
-		cType = expConfigSource.getParamType(param)
-		value = expConfigSource.getConfigData(param)
-		# we try to dump human readable types as text, 
-		# all other as a 'pickled' string
-		if cType in ['string','numeric','str_array']:
-			valuestr = value
-		else:
-			valuestr = pickle.dumps(value)
-			
-		file.write( "[%s]\ntype = %s\ndescription = %s\nvalue = %s\n\n" % \
-			(param,cType,description,value))
-	return len(paramList)
-#-------------------------------------------------------------------------
-def importDBSet(filename,aUser = None, aWorkplace = 'xxxDEFAULTxxx'):
-	"""get config definitions from a file exported with 
-	   exportDBSet()."""
-
-	# open configuration definition source
-	try:
-		importFile = gmCfg.cCfgFile(aFile = filename, \
-			flags= gmCfg.cfg_IGNORE_CMD_LINE)
-		# handle all exceptions including 'config file not found'
-	except:
-		exc = sys.exc_info()
-		_log.LogException("Unhandled exception while opening input file [%s]" % filename, exc,verbose=0)
-		return None
-
-	try:
-		importConfigSource = ConfigSourceDB("export",aUser,aWorkplace)
-	except:
-		_log.Log(gmLog.lErr, "Cannot open config set [%s@%s]." % (aUser,aWorkplace))
-		return None
-
-	existingParamList = importConfigSource.getAllParamNames()
-
-	importData = importFile.getCfg()
-	groups = importFile.getGroups()
-	# every group holds one parameter description
-	# group name = parameter name
-	successfully_stored = 0
-	for paramName in groups:
-		# ignore empty parameter names
-		if paramName == "":
-			continue
-		paramType = importFile.get(paramName, "type")			
-		if paramType is None:
-			continue
-
-		# parameter description - might differ from that stored 
-		# in backend tables (cfg_template)
-		paramDescription = importFile.get(paramName, "description")
-		if paramDescription is None:
-			continue
-
-
-		paramValueStr = importFile.get(paramName, "value")
-		if paramDescription is None:
-			continue
-		else:
-			if paramType in ['string','numeric','str_array']:
-				paramValue = eval(repr(paramValueStr))
-			else:
-				paramValue = pickle.loads(paramValueStr)
-		# TODO: check if the parameter already exists with different type
-		if existingParamList is not None and paramName in (existingParamList):
-			if not importConfigSource.getParamType(paramName) == paramType:
-				# if yes, print a warning
-				# you will have to delete that parameter before
-				# storing a different type
-				_log.Log(gmLog.lWarn,
-				"Cannot store config parameter [%s]: different type stored already." % paramName)
-			else:
-				# same type -> store new value	
-				s=importConfigSource.setConfigData(paramName,paramValue)
-				if s is None:
-					_log.Log(gmLog.lWarn, 
-						"Cannot store config parameter [%s] to set [%s@%s]." % (paramName,aUser,aWorkplace))
-				else:
-					successfully_stored = successfully_stored + 1
-
-		else:
-			# add new entry to parameter definition dictionary
-			s=importConfigSource.addConfigParam(paramName,paramType,paramValue,paramDescription)
-			if s is None:
-				_log.Log(gmLog.lWarn, 
-					"Cannot store config parameter [%s] to set [%s@%s]." % (paramName,aUser,aWorkplace))
-			else:
-				successfully_stored = successfully_stored + 1	
-	return successfully_stored
-
-#=============================================================
diff --git a/server/pycommon/gmDateTime.py b/server/pycommon/gmDateTime.py
index 96d118a..06cd3ea 100644
--- a/server/pycommon/gmDateTime.py
+++ b/server/pycommon/gmDateTime.py
@@ -1,3 +1,6 @@
+
+from __future__ import print_function
+
 __doc__ = """
 GNUmed date/time handling.
 
@@ -190,9 +193,10 @@ def init():
 
 	global gmCurrentLocalTimezone
 	gmCurrentLocalTimezone = cFixedOffsetTimezone (
-		offset = (current_local_utc_offset_in_seconds / 60),
+		offset = (current_local_utc_offset_in_seconds // 60),
 		name = current_local_iso_numeric_timezone_string
 	)
+
 #===========================================================================
 # mxDateTime conversions
 #---------------------------------------------------------------------------
@@ -254,7 +258,8 @@ def pydt_strftime(dt=None, format='%Y %b %d  %H:%M.%S', encoding=None, accuracy=
 	if dt is None:
 		if none_str is not None:
 			return none_str
-		dt = pydt_now_here()
+		raise ValueError('must provide <none_str> if <dt>=None is to be dealt with')
+		#dt = pydt_now_here()
 
 	if encoding is None:
 		encoding = gmI18N.get_encoding()
@@ -344,6 +349,7 @@ def pydt_max_here():
 def wx_now_here(wx=None):
 	"""Returns NOW @ HERE (IOW, in the local timezone."""
 	return py_dt2wxDate(py_dt = pydt_now_here(), wx = wx)
+
 #===========================================================================
 # wxPython conversions
 #---------------------------------------------------------------------------
@@ -385,6 +391,7 @@ def py_dt2wxDate(py_dt=None, wx=None):
 	# month, and year at once
 	wxdt = wx.DateTimeFromDMY(py_dt.day, py_dt.month-1, py_dt.year)
 	return wxdt
+
 #===========================================================================
 # interval related
 #---------------------------------------------------------------------------
@@ -1413,6 +1420,7 @@ def str2pydt_matches(str2parse=None, patterns=None):
 	matches.extend(__single_char2py_dt(str2parse))
 	matches.extend(__explicit_offset2py_dt(str2parse))
 
+	# no more with Python3
 	# try mxDT parsers
 	try:
 		date = mxDT.Parser.DateFromString (
@@ -2124,10 +2132,10 @@ class cFuzzyTimestamp:
 		if accuracy == acc_subseconds:
 			return unicode(self.timestamp)
 
-		raise ValueError, '%s.format_accurately(): <accuracy> (%s) must be between 1 and 7' % (
+		raise ValueError('%s.format_accurately(): <accuracy> (%s) must be between 1 and 7' % (
 			self.__class__.__name__,
 			accuracy
-		)
+		))
 	#-----------------------------------------------------------------------
 	def get_mxdt(self):
 		return self.timestamp
@@ -2182,7 +2190,7 @@ if __name__ == '__main__':
 		for tmp in intervals_as_str:
 			intv = str2interval(str_interval = tmp)
 			for acc in _accuracy_strings.keys():
-				print '[%s]: "%s" -> "%s"' % (acc, tmp, format_interval(intv, acc))
+				print ('[%s]: "%s" -> "%s"' % (acc, tmp, format_interval(intv, acc)))
 	#-----------------------------------------------------------------------
 	def test_format_interval_medically():
 
@@ -2249,159 +2257,160 @@ if __name__ == '__main__':
 
 		idx = 1
 		for intv in intervals:
-			print '%s) %s -> %s' % (idx, intv, format_interval_medically(intv))
+			print ('%s) %s -> %s' % (idx, intv, format_interval_medically(intv)))
 			idx += 1
 	#-----------------------------------------------------------------------
 	def test_str2interval():
-		print "testing str2interval()"
-		print "----------------------"
+		print ("testing str2interval()")
+		print ("----------------------")
 
 		for interval_as_str in intervals_as_str:
-			print "input: <%s>" % interval_as_str
-			print "  ==>", str2interval(str_interval=interval_as_str)
+			print ("input: <%s>" % interval_as_str)
+			print ("  ==>", str2interval(str_interval=interval_as_str))
 
 		return True
 	#-------------------------------------------------
 	def test_date_time():
-		print "DST currently in effect:", dst_currently_in_effect
-		print "current UTC offset:", current_local_utc_offset_in_seconds, "seconds"
-		print "current timezone (interval):", current_local_timezone_interval
-		print "current timezone (ISO conformant numeric string):", current_local_iso_numeric_timezone_string
-		print "local timezone class:", cLocalTimezone
-		print ""
+		print ("DST currently in effect:", dst_currently_in_effect)
+		print ("current UTC offset:", current_local_utc_offset_in_seconds, "seconds")
+		print ("current timezone (interval):", current_local_timezone_interval)
+		print ("current timezone (ISO conformant numeric string):", current_local_iso_numeric_timezone_string)
+		print ("local timezone class:", cLocalTimezone)
+		print ("")
 		tz = cLocalTimezone()
-		print "local timezone instance:", tz
-		print " (total) UTC offset:", tz.utcoffset(pyDT.datetime.now())
-		print " DST adjustment:", tz.dst(pyDT.datetime.now())
-		print " timezone name:", tz.tzname(pyDT.datetime.now())
-		print ""
-		print "current local timezone:", gmCurrentLocalTimezone
-		print " (total) UTC offset:", gmCurrentLocalTimezone.utcoffset(pyDT.datetime.now())
-		print " DST adjustment:", gmCurrentLocalTimezone.dst(pyDT.datetime.now())
-		print " timezone name:", gmCurrentLocalTimezone.tzname(pyDT.datetime.now())
-		print ""
-		print "now here:", pydt_now_here()
-		print ""
+		print ("local timezone instance:", tz)
+		print (" (total) UTC offset:", tz.utcoffset(pyDT.datetime.now()))
+		print (" DST adjustment:", tz.dst(pyDT.datetime.now()))
+		print (" timezone name:", tz.tzname(pyDT.datetime.now()))
+		print ("")
+		print ("current local timezone:", gmCurrentLocalTimezone)
+		print (" (total) UTC offset:", gmCurrentLocalTimezone.utcoffset(pyDT.datetime.now()))
+		print (" DST adjustment:", gmCurrentLocalTimezone.dst(pyDT.datetime.now()))
+		print (" timezone name:", gmCurrentLocalTimezone.tzname(pyDT.datetime.now()))
+		print ("")
+		print ("now here:", pydt_now_here())
+		print ("")
 	#-------------------------------------------------
 	def test_str2fuzzy_timestamp_matches():
-		print "testing function str2fuzzy_timestamp_matches"
-		print "--------------------------------------------"
+		print ("testing function str2fuzzy_timestamp_matches")
+		print ("--------------------------------------------")
 
 		val = None
 		while val != 'exit':
 			val = raw_input('Enter date fragment ("exit" quits): ')
 			matches = str2fuzzy_timestamp_matches(str2parse = val)
 			for match in matches:
-				print 'label shown  :', match['label']
-				print 'data attached:', match['data'], match['data'].timestamp
-				print ""
-			print "---------------"
+				print ('label shown  :', match['label'])
+				print ('data attached:', match['data'], match['data'].timestamp)
+				print ("")
+			print ("---------------")
 	#-------------------------------------------------
 	def test_cFuzzyTimeStamp():
-		print "testing fuzzy timestamp class"
-		print "-----------------------------"
+		print ("testing fuzzy timestamp class")
+		print ("-----------------------------")
 
 		ts = mxDT.now()
-		print "mx.DateTime timestamp", type(ts)
-		print "  print ...       :", ts
-		print "  print '%%s' %% ...: %s" % ts
-		print "  str()           :", str(ts)
-		print "  repr()          :", repr(ts)
+		print ("mx.DateTime timestamp", type(ts))
+		print ("  print ...       :", ts)
+		print ("  print '%%s' %% ...: %s" % ts)
+		print ("  str()           :", str(ts))
+		print ("  repr()          :", repr(ts))
 
 		fts = cFuzzyTimestamp()
-		print "\nfuzzy timestamp <%s '%s'>" % ('class', fts.__class__.__name__)
+		print ("\nfuzzy timestamp <%s '%s'>" % ('class', fts.__class__.__name__))
 		for accuracy in range(1,8):
 			fts.accuracy = accuracy
-			print "  accuracy         : %s (%s)" % (accuracy, _accuracy_strings[accuracy])
-			print "  format_accurately:", fts.format_accurately()
-			print "  strftime()       :", fts.strftime('%Y %b %d  %H:%M:%S')
-			print "  print ...        :", fts
-			print "  print '%%s' %% ... : %s" % fts
-			print "  str()            :", str(fts)
-			print "  repr()           :", repr(fts)
+			print ("  accuracy         : %s (%s)" % (accuracy, _accuracy_strings[accuracy]))
+			print ("  format_accurately:", fts.format_accurately())
+			print ("  strftime()       :", fts.strftime('%Y %b %d  %H:%M:%S'))
+			print ("  print ...        :", fts)
+			print ("  print '%%s' %% ... : %s" % fts)
+			print ("  str()            :", str(fts))
+			print ("  repr()           :", repr(fts))
 			raw_input('press ENTER to continue')
 	#-------------------------------------------------
 	def test_get_pydt():
-		print "testing platform for handling dates before 1970"
-		print "-----------------------------------------------"
+		print ("testing platform for handling dates before 1970")
+		print ("-----------------------------------------------")
 		ts = mxDT.DateTime(1935, 4, 2)
 		fts = cFuzzyTimestamp(timestamp=ts)
-		print "fts           :", fts
-		print "fts.get_pydt():", fts.get_pydt()
+		print ("fts           :", fts)
+		print ("fts.get_pydt():", fts.get_pydt())
 	#-------------------------------------------------
 	def test_calculate_apparent_age():
 		# test leap year glitches
 		start = pydt_now_here().replace(year = 2000).replace(month = 2).replace(day = 29)
 		end = pydt_now_here().replace(year = 2012).replace(month = 2).replace(day = 27)
-		print "start is leap year: 29.2.2000"
-		print " ", calculate_apparent_age(start = start, end = end)
-		print " ", format_apparent_age_medically(calculate_apparent_age(start = start))
+		print ("start is leap year: 29.2.2000")
+		print (" ", calculate_apparent_age(start = start, end = end))
+		print (" ", format_apparent_age_medically(calculate_apparent_age(start = start)))
 
 		start = pydt_now_here().replace(month = 10).replace(day = 23).replace(year = 1974)
 		end = pydt_now_here().replace(year = 2012).replace(month = 2).replace(day = 29)
-		print "end is leap year: 29.2.2012"
-		print " ", calculate_apparent_age(start = start, end = end)
-		print " ", format_apparent_age_medically(calculate_apparent_age(start = start))
+		print ("end is leap year: 29.2.2012")
+		print (" ", calculate_apparent_age(start = start, end = end))
+		print (" ", format_apparent_age_medically(calculate_apparent_age(start = start)))
 
 		start = pydt_now_here().replace(year = 2000).replace(month = 2).replace(day = 29)
 		end = pydt_now_here().replace(year = 2012).replace(month = 2).replace(day = 29)
-		print "start is leap year: 29.2.2000"
-		print "end is leap year: 29.2.2012"
-		print " ", calculate_apparent_age(start = start, end = end)
-		print " ", format_apparent_age_medically(calculate_apparent_age(start = start))
+		print ("start is leap year: 29.2.2000")
+		print ("end is leap year: 29.2.2012")
+		print (" ", calculate_apparent_age(start = start, end = end))
+		print (" ", format_apparent_age_medically(calculate_apparent_age(start = start)))
 
-		print "leap year tests worked"
+		print ("leap year tests worked")
 
 		start = pydt_now_here().replace(month = 10).replace(day = 23).replace(year = 1974)
-		print calculate_apparent_age(start = start)
-		print format_apparent_age_medically(calculate_apparent_age(start = start))
+		print (calculate_apparent_age(start = start))
+		print (format_apparent_age_medically(calculate_apparent_age(start = start)))
 
 		start = pydt_now_here().replace(month = 3).replace(day = 13).replace(year = 1979)
-		print calculate_apparent_age(start = start)
-		print format_apparent_age_medically(calculate_apparent_age(start = start))
+		print (calculate_apparent_age(start = start))
+		print (format_apparent_age_medically(calculate_apparent_age(start = start)))
 
 		start = pydt_now_here().replace(month = 2, day = 2).replace(year = 1979)
 		end = pydt_now_here().replace(month = 3).replace(day = 31).replace(year = 1979)
-		print calculate_apparent_age(start = start, end = end)
+		print (calculate_apparent_age(start = start, end = end))
 
 		start = pydt_now_here().replace(month = 7, day = 21).replace(year = 2009)
-		print format_apparent_age_medically(calculate_apparent_age(start = start))
+		print (format_apparent_age_medically(calculate_apparent_age(start = start)))
 
-		print "-------"
+		print ("-------")
 		start = pydt_now_here().replace(month = 1).replace(day = 23).replace(hour = 12).replace(minute = 11).replace(year = 2011)
-		print calculate_apparent_age(start = start)
-		print format_apparent_age_medically(calculate_apparent_age(start = start))
+		print (calculate_apparent_age(start = start))
+		print (format_apparent_age_medically(calculate_apparent_age(start = start)))
 	#-------------------------------------------------
 	def test_str2pydt():
-		print "testing function str2pydt_matches"
-		print "---------------------------------"
+		print ("testing function str2pydt_matches")
+		print ("---------------------------------")
 
 		val = None
 		while val != 'exit':
 			val = raw_input('Enter date fragment ("exit" quits): ')
 			matches = str2pydt_matches(str2parse = val)
 			for match in matches:
-				print 'label shown  :', match['label']
-				print 'data attached:', match['data']
-				print ""
-			print "---------------"
+				print ('label shown  :', match['label'])
+				print ('data attached:', match['data'])
+				print ("")
+			print ("---------------")
 	#-------------------------------------------------
 	def test_pydt_strftime():
 		dt = pydt_now_here()
-		print pydt_strftime(dt, '-(%Y %b %d)-')
-		print pydt_strftime(dt)
-		print pydt_strftime(dt, accuracy = acc_days)
-		print pydt_strftime(dt, accuracy = acc_minutes)
-		print pydt_strftime(dt, accuracy = acc_seconds)
+		print (pydt_strftime(dt, '-(%Y %b %d)-'))
+		print (pydt_strftime(dt))
+		print (pydt_strftime(dt, accuracy = acc_days))
+		print (pydt_strftime(dt, accuracy = acc_minutes))
+		print (pydt_strftime(dt, accuracy = acc_seconds))
 		dt = dt.replace(year = 1899)
-		print pydt_strftime(dt)
-		print pydt_strftime(dt, accuracy = acc_days)
-		print pydt_strftime(dt, accuracy = acc_minutes)
-		print pydt_strftime(dt, accuracy = acc_seconds)
+		print (pydt_strftime(dt))
+		print (pydt_strftime(dt, accuracy = acc_days))
+		print (pydt_strftime(dt, accuracy = acc_minutes))
+		print (pydt_strftime(dt, accuracy = acc_seconds))
 	#-------------------------------------------------
 	def test_is_leap_year():
 		for year in range(1995, 2017):
-			print year, "leaps:", is_leap_year(year)
+			print (year, "leaps:", is_leap_year(year))
+
 	#-------------------------------------------------
 	# GNUmed libs
 	gmI18N.activate_locale()
@@ -2417,8 +2426,8 @@ if __name__ == '__main__':
 	#test_format_interval()
 	#test_format_interval_medically()
 	#test_str2pydt()
-	test_pydt_strftime()
+	#test_pydt_strftime()
 	#test_calculate_apparent_age()
-	#test_is_leap_year()
+	test_is_leap_year()
 
 #===========================================================================
diff --git a/server/pycommon/gmDispatcher.py b/server/pycommon/gmDispatcher.py
index 4fd6038..f0dd6af 100644
--- a/server/pycommon/gmDispatcher.py
+++ b/server/pycommon/gmDispatcher.py
@@ -1,4 +1,7 @@
-"""GNUmed client internal signal handling.
+
+from __future__ import print_function
+
+__doc__ = """GNUmed client internal signal handling.
 
 # this code has been written by Patrick O'Brien <pobrien at orbtech.com>
 # downloaded from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/87056
@@ -69,33 +72,31 @@ def connect(receiver=None, signal=Any, sender=Any, weak=1):
 	If sender is Any, receiver will receive signal from any sender.
 	If signal is Any, receiver will receive any signal from sender.
 	If sender is None, receiver will receive signal from anonymous.
-	If signal is Any and sender is None, receiver will receive any 
-		signal from anonymous.
-	If signal is Any and sender is Any, receiver will receive any 
-		signal from any sender.
+	If signal is Any and sender is None, receiver will receive any signal from anonymous.
+	If signal is Any and sender is Any, receiver will receive any signal from any sender.
 	If weak is true, weak references will be used.
 
 	ADDITIONAL gnumed specific documentation:
-			this dispatcher is not designed with a gui single threaded event
-			loop in mind.
-			when connecting to a receiver that may eventually make calls to			gui objects	 such as wxWindows objects, it is highly recommended that any
-	such calls be wrapped in wxCallAfter() e.g.
-		def receiveSignal(self, **args):
-				self._callsThatDoNotTriggerGuiUpdates()
-				self.data = processArgs(args)
-				wxCallAfter( self._callsThatTriggerGuiUpdates() )
-
-		since it is likely data change occurs before the signalling,
-		it would probably look more simply like:
-
-		def receiveSignal(self, **args):
-				wxCallAfter(self._updateUI() )
-
-		def _updateUI(self):
-				# your code that reads data
-
-		Especially if the widget can get a reference to updated data through
-		a global reference, such as via gmCurrentPatient.
+
+	this dispatcher is not designed with a gui single threaded event loop in mind.
+
+	when connecting to a receiver that may eventually make calls to gui objects such as wxWindows objects, it is highly recommended that any such calls be wrapped in wxCallAfter() e.g.
+
+	def receiveSignal(self, **args):
+		self._callsThatDoNotTriggerGuiUpdates()
+		self.data = processArgs(args)
+		wxCallAfter( self._callsThatTriggerGuiUpdates() )
+
+	since it is likely data change occurs before the signalling, it would probably look more simply like:
+
+	def receiveSignal(self, **args):
+		wxCallAfter(self._updateUI() )
+
+	def _updateUI(self):
+		# your code that reads data
+
+	Especially if the widget can get a reference to updated data through
+	a global reference, such as via gmCurrentPatient.
 """
 	if receiver is None:
 		raise ValueError('gmDispatcher.connect(): must define <receiver>')
@@ -110,7 +111,7 @@ def connect(receiver=None, signal=Any, sender=Any, weak=1):
 		receiver = safeRef(receiver)
 	senderkey = id(sender)
 	signals = {}
-	if connections.has_key(senderkey):
+	if senderkey in connections:
 		signals = connections[senderkey]
 	else:
 		connections[senderkey] = signals
@@ -126,7 +127,7 @@ def connect(receiver=None, signal=Any, sender=Any, weak=1):
 			except:
 				pass
 	receivers = []
-	if signals.has_key(signal):
+	if signal in signals:
 		receivers = signals[signal]
 	else:
 		signals[signal] = receivers
@@ -150,13 +151,13 @@ def disconnect(receiver, signal=Any, sender=Any, weak=1):
 		receivers = connections[senderkey][signal]
 	except KeyError:
 		_log.error('no receivers for signal %(sig)s from sender %(sender)s', {'sig': repr(signal), 'sender': sender})
-		print 'DISPATCHER ERROR: no receivers for signal %s from sender %s' % (repr(signal), sender)
+		print('DISPATCHER ERROR: no receivers for signal %s from sender %s' % (repr(signal), sender))
 		return
 	try:
 		receivers.remove(receiver)
 	except ValueError:
 		_log.error('receiver [%(rx)s] not connected to signal [%(sig)s] from [%(sender)s]', {'rx': receiver, 'sig': repr(signal), 'sender': sender})
-		print "DISPATCHER ERROR: receiver [%s] not connected to signal [%s] from [%s]" % (receiver, repr(signal), sender)
+		print("DISPATCHER ERROR: receiver [%s] not connected to signal [%s] from [%s]" % (receiver, repr(signal), sender))
 	_cleanupConnections(senderkey, signal)
 #---------------------------------------------------------------------
 def send(signal=None, sender=None, **kwds):
@@ -223,9 +224,9 @@ def safeRef(object):
 			# Keep track of these instances for lookup by disconnect().
 			selfkey = object.im_self
 			funckey = object.im_func
-			if not _boundMethods.has_key(selfkey):
+			if selfkey not in _boundMethods:
 				_boundMethods[selfkey] = weakref.WeakKeyDictionary()
-			if not _boundMethods[selfkey].has_key(funckey):
+			if funckey not in _boundMethods[selfkey]:
 				_boundMethods[selfkey][funckey] = \
 				BoundMethodWeakref(boundMethod=object)
 			return _boundMethods[selfkey][funckey]
@@ -285,7 +286,7 @@ def _call(receiver, **kwds):
 		acceptable_args = fc.co_varnames[0:fc.co_argcount]
 	else:
 		_log.error('<%(rx)s> must be instance, method or function', {'rx': str(receiver)})
-		print 'DISPATCHER ERROR: _call(): <%s> must be instance, method or function' % str(receiver)
+		print('DISPATCHER ERROR: _call(): <%s> must be instance, method or function' % str(receiver))
 	if not (fc.co_flags & 8):
 		# fc does not have a **kwds type parameter, therefore 
 		# remove unacceptable arguments.
@@ -294,7 +295,7 @@ def _call(receiver, **kwds):
 				del kwds[arg]
 
 	if __execute_in_main_thread is None:
-		print 'DISPATCHER problem: no main-thread executor available'
+		print('DISPATCHER problem: no main-thread executor available')
 		return receiver(**kwds)
 
 	# if a cross-thread executor is set
diff --git a/server/pycommon/gmExceptions.py b/server/pycommon/gmExceptions.py
index f8bdb2f..9688fdf 100644
--- a/server/pycommon/gmExceptions.py
+++ b/server/pycommon/gmExceptions.py
@@ -1,6 +1,5 @@
 ############################################################################
-#
-# gmExceptions - classes for exceptions gnumed modules may throw
+# gmExceptions - classes for exceptions GNUmed modules may throw
 # --------------------------------------------------------------------------
 #
 # @author: Dr. Horst Herb
@@ -39,14 +38,6 @@ class AccessDenied(Exception):
 		return txt
 
 #------------------------------------------------------------
-class DatabaseObjectInUseError(Exception):
-	def __init__(self, msg):
-		self.errmsg = msg
-
-	def __str__(self):
-		return self.errmsg
-
-
 class ConnectionError(Exception):
 	#raised whenever the database backend connection fails
 	def __init__(self, errmsg):
@@ -55,35 +46,6 @@ class ConnectionError(Exception):
 	def __str__(self):
 		return self.errmsg
 
-class ConfigError(Exception):
-	#raised whenever a configuration error occurs
-	def __init__(self, errmsg):
-		self.errmsg=errmsg
-
-	def __str__(self):
-		return self.errmsg
-
-
-
-class NoGuiError(Exception):
-	def __init__(self, errmsg):
-		self.errmsg=errmsg
-
-	def __str__(self):
-		return self.errmsg
-
-
-class PureVirtualFunction(Exception):
-	#raised whenever the database backend connection fails
-	def __init__(self, errmsg=None):
-		if errmsg is not None:
-			self.errmsg=errmsg
-		else:
-			self.errmsg="Attempt to call a pure virtual function!"
-
-	def __str__(self):
-		return self.errmsg
-
 #------------------------------------------------------------
 # constructor errors
 class ConstructorError(Exception):
@@ -107,17 +69,4 @@ class NoSuchBusinessObjectError(ConstructorError):
 	def __str__(self):
 		return self.errmsg
 
-#------------------------------------------------------------
-class InvalidInputError(Exception):
-	"""Raised by business layers when an attempt is made to input
-	invalid data"""
-	def __init__(self, errmsg = None):
-		if errmsg is None:
-			self.errmsg = "%s.__init__() failed" % self.__class__.__name__
-		else:
-			self.errmsg = errmsg
-
-	def __str__(self):
-		return self.errmsg
-
 #=====================================================================
diff --git a/server/pycommon/gmGuiBroker.py b/server/pycommon/gmGuiBroker.py
index 6f261c1..d598f77 100644
--- a/server/pycommon/gmGuiBroker.py
+++ b/server/pycommon/gmGuiBroker.py
@@ -1,4 +1,7 @@
-"""GNUMed GUI element brokerage
+
+from __future__ import print_function
+
+__doc__ = """GNUmed GUI element brokerage
 
 This module provides wrappers for the equivalent of global
 variables needed for a gnumed GUI client interface
@@ -7,10 +10,7 @@ variables needed for a gnumed GUI client interface
 @version: 0.2
 @copyright: GPL v2 or later
 """
-#-----------------------------------------------------------
-# $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/client/pycommon/gmGuiBroker.py,v $
-# $Id: gmGuiBroker.py,v 1.4 2004-06-20 15:44:28 ncq Exp $
-__version__ = "$Revision: 1.4 $"
+
 __author__ = "H.Herb <hherb at gnumed.net>, H.Berger <Hilmar.Berger at gmx.de>"
 #===========================================================
 if __name__ == '__main__':
@@ -54,7 +54,7 @@ class GuiBroker:
 		if not key:
 		# create a new sequential key that doesn't exist yet
 			key = GuiBroker.__keycounter + 1
-			while GuiBroker.__objects.has_key(key):
+			while key in GuiBroker.__objects:
 				key +=1
 		GuiBroker.__keycounter = key
 		GuiBroker.__objects[key]=widget
@@ -67,7 +67,7 @@ class GuiBroker:
 		return GuiBroker.__objects[key]
 
 	def has_key( self, key):
-		return GuiBroker.__objects.has_key(key)
+		return key in GuiBroker.__objects
 
 
 
@@ -100,99 +100,69 @@ class GuiBroker:
 		return self.addobject(object, key)
 
 #===========================================================
-# you can test this module by invoking it as main program
 if __name__ == "__main__":
-    print '>>> gmGuiBroker.GuiBroker test'
-    test = GuiBroker()
 
-    print '>>> test.addobject("something", 3)'
-    var = test.addobject("something", 3)
-    print var, "\n"
+	import sys
 
-    print '>>> test.addobject("something else without a specified key")'
-    var = test.addobject("something else without a specified key")
-    print var, "\n"
+	if len(sys.argv) < 2:
+		sys.exit()
 
-    print '>>> test.addobject(test)'
-    testreference = test.addobject(test)
-    print testreference, "\n"
+	if sys.argv[1] != u'test':
+		sys.exit()
 
-    print '>>> test.addobject(100, "hundred)'
-    var = test.addobject(100, "hundred")
-    print var, "\n"
+	# you can test this module by invoking it as main program
+	print('>>> gmGuiBroker.GuiBroker test')
+	test = GuiBroker()
 
-    print ">>> test.keylist()"
-    var = test.keylist()
-    print var, "\n"
+	print('>>> test.addobject("something", 3)')
+	var = test.addobject("something", 3)
+	print(var, "\n")
 
-    print ">>> test.valuelist()"
-    var = test.valuelist()
-    print var, "\n"
+	print('>>> test.addobject("something else without a specified key")')
+	var = test.addobject("something else without a specified key")
+	print(var, "\n")
 
-    print ">>> test.itemlist()"
-    var = test.itemlist()
-    print var, "\n"
+	print('>>> test.addobject(test)')
+	testreference = test.addobject(test)
+	print(testreference, "\n")
 
-    print ">>> test[3]"
-    var = test[3]
-    print var, "\n"
+	print('>>> test.addobject(100, "hundred)')
+	var = test.addobject(100, "hundred")
+	print(var, "\n")
 
-    print ">>> test[testreference].getobject('hundred')"
-    var = test[testreference].getobject('hundred')
-    print var, "\n"
+	print(">>> test.keylist()")
+	var = test.keylist()
+	print(var, "\n")
 
-    print ">>> var = test[testreference]"
-    var = test[testreference]
-    print var, "\n"
+	print(">>> test.valuelist()")
+	var = test.valuelist()
+	print(var, "\n")
 
-    print ">>> var = var['hundred']"
-    var = var['hundred']
-    print var, "\n"
+	print(">>> test.itemlist()")
+	var = test.itemlist()
+	print(var, "\n")
 
-    print '>>> try: test.addobject["duplicate key", 3]'
-    print '>>> except KeyError: print "Duplicate keys not allowed!"'
-    try: test["duplicate key", 3]
-    except KeyError: print "Duplicate keys not allowed!"
+	print(">>> test[3]")
+	var = test[3]
+	print(var, "\n")
 
-    print ">>> test['key']='value'"
-    test['key']='value'
-    print test['key']
+	print(">>> test[testreference].getobject('hundred')")
+	var = test[testreference].getobject('hundred')
+	print(var, "\n")
 
-#===========================================================
-# $Log: gmGuiBroker.py,v $
-# Revision 1.4  2004-06-20 15:44:28  ncq
-# - we need to be more careful in pleasing epydoc
-#
-# Revision 1.3  2004/06/20 06:49:21  ihaywood
-# changes required due to Epydoc's OCD
-#
-# Revision 1.2  2004/03/10 00:14:04  ncq
-# - fix imports
-#
-# Revision 1.1  2004/02/25 09:30:13  ncq
-# - moved here from python-common
-#
-# Revision 1.8  2003/11/17 10:56:36  sjtan
-#
-# synced and commiting.
-#
-# Revision 1.1  2003/10/23 06:02:39  sjtan
-#
-# manual edit areas modelled after r.terry's specs.
-#
-# Revision 1.7  2003/02/09 11:48:59  ncq
-# - just some silly cvs keyword
-#
-# Revision 1.6  2003/02/09 09:41:57  sjtan
-#
-# clean up new code, make it less intrusive.
-#
-# Revision 1.5  2003/01/16 14:45:03  ncq
-# - debianized
-#
-# Revision 1.4  2003/01/12 00:20:04  ncq
-# - fixed __author__
-#
-# Revision 1.3  2003/01/12 00:17:44  ncq
-# - fixed typo, added CVS keywords
-#
+	print(">>> var = test[testreference]")
+	var = test[testreference]
+	print(var, "\n")
+
+	print(">>> var = var['hundred']")
+	var = var['hundred']
+	print(var, "\n")
+
+	print('>>> try: test.addobject["duplicate key", 3]')
+	print('>>> except KeyError: print("Duplicate keys not allowed!"')
+	try: test["duplicate key", 3]
+	except KeyError: print("Duplicate keys not allowed!")
+
+	print(">>> test['key']='value'")
+	test['key']='value'
+	print(test['key'])
diff --git a/server/pycommon/gmHooks.py b/server/pycommon/gmHooks.py
index 1b0f9a5..4523987 100644
--- a/server/pycommon/gmHooks.py
+++ b/server/pycommon/gmHooks.py
@@ -25,6 +25,7 @@ import os
 import sys
 import stat
 import logging
+import io
 
 
 # GNUmed libs
@@ -89,8 +90,8 @@ def import_hook_module(reimport=False):
 
 	if not os.access(full_script, os.F_OK):
 		_log.warning('creating default hook script')
-		f = open(full_script, 'w')
-		f.write("""
+		f = io.open(full_script, mode = u'wt', encoding = u'utf8')
+		f.write(u"""
 # known hooks:
 #  %s
 
@@ -130,7 +131,7 @@ def run_script(hook=None):
 
 	try:
 		tmp = gmTools.import_module_from_directory(script_path, script_name)
-	except StandardError:
+	except Exception:
 		_log.exception('cannot import hook script')
 		return False
 
@@ -164,7 +165,7 @@ def run_hook_script(hook=None):
 
 	try:
 		hook_module.run_script(hook = hook)
-	except StandardError:
+	except Exception:
 		_log.exception('error running hook script for [%s]', hook)
 		gmDispatcher.send (
 			signal = u'statustext',
@@ -190,6 +191,12 @@ def run_hook_script(hook=None):
 # ========================================================================
 if __name__ == '__main__':
 
+	if len(sys.argv) < 2:
+		sys.exit()
+
+	if sys.argv[1] != u'test':
+		sys.exit()
+
 	run_hook_script(hook = 'shutdown-post-GUI')
 	run_hook_script(hook = 'invalid hook')
 
diff --git a/server/pycommon/gmI18N.py b/server/pycommon/gmI18N.py
index 6294f45..4aed585 100644
--- a/server/pycommon/gmI18N.py
+++ b/server/pycommon/gmI18N.py
@@ -1,4 +1,7 @@
-"""GNUmed client internationalization/localization.
+
+from __future__ import print_function
+
+__doc__ = """GNUmed client internationalization/localization.
 
 All i18n/l10n issues should be handled through this modules.
 
@@ -53,8 +56,14 @@ __license__ = "GPL v2 or later (details at http://www.gnu.org)"
 
 
 # stdlib
-import sys, os.path, os, re as regex, locale, gettext, logging, codecs
-
+import sys
+import os.path
+import os
+import locale
+import gettext
+import logging
+import codecs
+import re as regex
 
 _log = logging.getLogger('gm.i18n')
 
@@ -236,7 +245,6 @@ def activate_locale():
 	"""Get system locale from environment."""
 	global system_locale
 
-	# logging state of affairs
 	__log_locale_settings('unmodified startup locale settings (should be [C])')
 
 	# activate user-preferred locale
@@ -255,7 +263,6 @@ def activate_locale():
 	except:
 		_log.exception('error activating user-default locale')
 
-	# logging state of affairs
 	__log_locale_settings('locale settings after activating user-default locale')
 
 	# did we find any locale setting ? assume en_EN if not
@@ -325,7 +332,7 @@ def install_domain(domain=None, language=None, prefer_local_catalog=False):
 	# - $(<script-name>_DIR)/
 	env_key = "%s_DIR" % os.path.splitext(os.path.basename(sys.argv[0]))[0].upper()
 	_log.debug('looking at ${%s}' % env_key)
-	if os.environ.has_key(env_key):
+	if env_key in os.environ:
 		loc_dir = os.path.abspath(os.path.join(os.environ[env_key], 'po'))
 		_log.debug('${%s} = "%s" -> [%s]' % (env_key, os.environ[env_key], loc_dir))
 		candidates.append(loc_dir)
@@ -419,6 +426,7 @@ def get_encoding():
 		_encoding_mismatch_already_logged = True
 
 	return locale.getpreferredencoding(do_setlocale=False)
+
 #===========================================================================
 # Main
 #---------------------------------------------------------------------------
@@ -451,20 +459,20 @@ if __name__ == "__main__":
 
 		]
 		for cands in candidates:
-			print cands[0], u'<vs>', cands[1], '=', locale.strcoll(cands[0], cands[1])
-#			print cands[1], u'<vs>', cands[0], '=', locale.strcoll(cands[1], cands[0])
+			print(cands[0], u'<vs>', cands[1], '=', locale.strcoll(cands[0], cands[1]))
+#			print(cands[1], u'<vs>', cands[0], '=', locale.strcoll(cands[1], cands[0]))
 
 	#----------------------------------------------------------------------
-	print "======================================================================"
-	print "GNUmed i18n"
-	print ""
-	print "authors:", __author__
-	print "license:", __license__
-	print "======================================================================"
+	print("======================================================================")
+	print("GNUmed i18n")
+	print("")
+	print("authors:", __author__)
+	print("license:", __license__)
+	print("======================================================================")
 
 	activate_locale()
-	print "system locale: ", system_locale, "; levels:", system_locale_level
-	print "likely encoding:", get_encoding()
+	print("system locale: ", system_locale, "; levels:", system_locale_level)
+	print("likely encoding:", get_encoding())
 
 	if len(sys.argv) > 1:
 		install_domain(domain = sys.argv[2])
@@ -481,6 +489,3 @@ if __name__ == "__main__":
 	tmp = _('Translate this or i18n into <en_EN> will not work properly !') #
 	# ********************************************************************* #
 	# ********************************************************************* #
-
-#=====================================================================
-
diff --git a/server/pycommon/gmLog2.py b/server/pycommon/gmLog2.py
index e63b8a5..0697db6 100644
--- a/server/pycommon/gmLog2.py
+++ b/server/pycommon/gmLog2.py
@@ -47,6 +47,7 @@ __license__ = "GPL v2 or later (details at http://www.gnu.org)"
 import logging
 import sys
 import os
+import io
 import codecs
 import locale
 import datetime as pydt
@@ -256,7 +257,7 @@ def __setup_logging():
 	else:
 		fmt = u'%(asctime)s  %(levelname)-8s  %(name)s (%(pathname)s::%(funcName)s() #%(lineno)d): %(message)s'
 
-	_logfile = codecs.open(filename = _logfile_name, mode = 'wb', encoding = 'utf8', errors = 'replace')
+	_logfile = io.open(_logfile_name, mode = 'wt', encoding = 'utf8', errors = 'replace')
 
 	logging.basicConfig (
 		format = fmt,
@@ -297,11 +298,11 @@ def __get_logfile_name():
 			_logfile_name = os.path.abspath(os.path.expanduser(os.path.join(dir_name, file_name)))
 			return True
 
-	# else store it in ~/.gm-logs/def_log_basename/default_logfile_name
-	dir_name = os.path.expanduser(os.path.join('~', '.gnumed-logs', def_log_basename))
+	# else store it in ~/.gnumed/logs/def_log_basename/default_logfile_name
+	dir_name = os.path.expanduser(os.path.join('~', '.gnumed', 'logs', def_log_basename))
 	try:
 		os.makedirs(dir_name)
-	except OSError, e:
+	except OSError as e:
 		if (e.errno == 17) and not os.path.isdir(dir_name):
 			raise
 
diff --git a/server/pycommon/gmLoginInfo.py b/server/pycommon/gmLoginInfo.py
index f21d35a..8eb8645 100644
--- a/server/pycommon/gmLoginInfo.py
+++ b/server/pycommon/gmLoginInfo.py
@@ -154,4 +154,13 @@ class LoginInfo:
 
 #====================================================================
 if __name__ == "__main__" :
-	print "Please somebody write a module test function here!"
+
+	import sys
+
+	if len(sys.argv) < 2:
+		sys.exit()
+
+	if sys.argv[1] != u'test':
+		sys.exit()
+
+	print("Please somebody write a module test function here!")
diff --git a/server/pycommon/gmMatchProvider.py b/server/pycommon/gmMatchProvider.py
index b42cb6f..0fdf665 100644
--- a/server/pycommon/gmMatchProvider.py
+++ b/server/pycommon/gmMatchProvider.py
@@ -1,4 +1,5 @@
-"""Base classes for match providers.
+
+__doc__ = """Base classes for match providers.
 
 They are used by business objects to give
 phrasewheels the ability to guess phrases.
@@ -6,16 +7,18 @@ phrasewheels the ability to guess phrases.
 Copyright (C) GNUMed developers
 license: GPL v2 or later
 """
-__version__ = "$Revision: 1.34 $"
 __author__  = "K.Hilbert <Karsten.Hilbert at gmx.net>, I.Haywood <ihaywood at gnu.org>, S.J.Tan <sjtan at bigpond.com>"
 
 # std lib
-import re as regex
+import sys
 import logging
+import re as regex
 import datetime as pydt
 
 
 # GNUmed
+if __name__ == "__main__":
+	sys.path.insert(0, '../../')
 from Gnumed.pycommon import gmPG2
 
 
@@ -568,8 +571,7 @@ class cMatchProvider_SQL2(cMatchProvider):
 
 		# none found whatsoever
 		return (False, [])
+
 #================================================================
 if __name__ == '__main__':
 	pass
-
-#================================================================
diff --git a/server/pycommon/gmMimeLib.py b/server/pycommon/gmMimeLib.py
index 5e65f3f..c773ec5 100644
--- a/server/pycommon/gmMimeLib.py
+++ b/server/pycommon/gmMimeLib.py
@@ -14,17 +14,21 @@ import mimetypes
 import subprocess
 import shutil
 import logging
+import io
 
 
 # GNUmed
 if __name__ == '__main__':
 	sys.path.insert(0, '../../')
-import gmShellAPI, gmTools, gmCfg2
+import gmShellAPI
+import gmTools
+import gmCfg2
 
 
 _log = logging.getLogger('gm.docs')
+
 #=======================================================================================
-def guess_mimetype(aFileName = None):
+def guess_mimetype(filename = None):
 	"""Guess mime type of arbitrary file.
 
 	filenames are supposed to be in Unicode
@@ -35,19 +39,19 @@ def guess_mimetype(aFileName = None):
 	try:
 		import extractor
 		xtract = extractor.Extractor()
-		props = xtract.extract(filename = aFileName)
+		props = xtract.extract(filename = filename)
 		for prop, val in props:
 			if (prop == 'mimetype') and (val != worst_case):
 				return val
 	except ImportError:
-		_log.exception('Python wrapper for libextractor not installed.')
+		_log.debug('module <extractor> (python wrapper for libextractor) not installed')
 
 	ret_code = -1
 
 	# 2) use "file" system command
 	#    -i get mime type
 	#    -b don't display a header
-	mime_guesser_cmd = u'file -i -b "%s"' % aFileName
+	mime_guesser_cmd = u'file -i -b "%s"' % filename
 	# this only works on POSIX with 'file' installed (which is standard, however)
 	# it might work on Cygwin installations
 	aPipe = os.popen(mime_guesser_cmd.encode(sys.getfilesystemencoding()), 'r')
@@ -59,12 +63,12 @@ def guess_mimetype(aFileName = None):
 		if ret_code is None:
 			_log.debug('[%s]: <%s>' % (mime_guesser_cmd, pipe_output))
 			if pipe_output not in [u'', worst_case]:
-				return pipe_output
+				return pipe_output.split(u';')[0].strip()
 		else:
 			_log.error('[%s] on %s (%s): failed with exit(%s)' % (mime_guesser_cmd, os.name, sys.platform, ret_code))
 
 	# 3) use "extract" shell level libextractor wrapper
-	mime_guesser_cmd = 'extract -p mimetype "%s"' % aFileName
+	mime_guesser_cmd = 'extract -p mimetype "%s"' % filename
 	aPipe = os.popen(mime_guesser_cmd.encode(sys.getfilesystemencoding()), 'r')
 	if aPipe is None:
 		_log.debug("cannot open pipe to [%s]" % mime_guesser_cmd)
@@ -85,11 +89,12 @@ def guess_mimetype(aFileName = None):
 	_log.info("OS level mime detection failed, falling back to built-in magic")
 
 	import gmMimeMagic
-	mime_type = gmTools.coalesce(gmMimeMagic.file(aFileName), worst_case)
+	mime_type = gmTools.coalesce(gmMimeMagic.file(filename), worst_case)
 	del gmMimeMagic
 
-	_log.debug('"%s" -> <%s>' % (aFileName, mime_type))
+	_log.debug('"%s" -> <%s>' % (filename, mime_type))
 	return mime_type
+
 #-----------------------------------------------------------------------------------
 def get_viewer_cmd(aMimeType = None, aFileName = None, aToken = None):
 	"""Return command for viewer for this mime type complete with this file"""
@@ -107,6 +112,7 @@ def get_viewer_cmd(aMimeType = None, aFileName = None, aToken = None):
 	_log.debug("<%s> viewer: [%s]" % (aMimeType, viewer))
 
 	return viewer
+
 #-----------------------------------------------------------------------------------
 def get_editor_cmd(mimetype=None, filename=None):
 
@@ -124,6 +130,7 @@ def get_editor_cmd(mimetype=None, filename=None):
 	_log.debug("<%s> editor: [%s]" % (mimetype, editor))
 
 	return editor
+
 #-----------------------------------------------------------------------------------
 def guess_ext_by_mimetype(mimetype=''):
 	"""Return file extension based on what the OS thinks a file of this mimetype should end in."""
@@ -168,6 +175,7 @@ def guess_ext_for_file(aFile=None):
 		return None
 
 	return f_ext
+
 #-----------------------------------------------------------------------------------
 _system_startfile_cmd = None
 
@@ -204,6 +212,7 @@ def _get_system_startfile_cmd(filename):
 
 	_system_startfile_cmd = u''
 	return False, None
+
 #-----------------------------------------------------------------------------------
 def convert_file(filename=None, target_mime=None, target_filename=None, target_extension=None):
 	"""Convert file from one format into another.
@@ -242,19 +251,65 @@ def convert_file(filename=None, target_mime=None, target_filename=None, target_e
 		return False
 
 	return True
+
+#-----------------------------------------------------------------------------------
+def describe_file(filename):
+
+	base_name = u'gm-describe_file'
+
+	paths = gmTools.gmPaths()
+	local_script = os.path.join(paths.local_base_dir, '..', 'external-tools', base_name)
+
+	candidates = [ base_name, local_script ]		#, base_name + u'.bat'
+	found, binary = gmShellAPI.find_first_binary(binaries = candidates)
+	if not found:
+		#binary = base_name# + r'.bat'
+		_log.debug(u'cannot find <%s(.bat)>', base_name)
+		return (False, _(u'<%s(.bat)> not found') % base_name)
+
+	desc_fname = gmTools.get_unique_filename()
+
+	cmd_line = [
+		binary,
+		filename,
+		desc_fname
+	]
+	_log.debug('describing: %s', cmd_line)
+	try:
+		gm_describe = subprocess.Popen(cmd_line)
+	except OSError:
+		_log.debug('cannot run <%s>', binary)
+		return (False, _(u'problem with <%s>') % binary)
+
+	gm_describe.communicate()
+	if gm_describe.returncode != 0:
+		_log.error('<%s> returned [%s], failed to convert', binary, gm_describe.returncode)
+		return (False, _(u'problem with <%s>') % binary)
+
+	try:
+		desc_file = io.open(desc_fname, mode = 'rt', encoding = 'utf8', errors = 'replace')
+	except IOError:
+		_log.exception('cannot open [%s]', desc_fname)
+		return (False, _(u'problem with <%s>') % binary)
+
+	desc = u''.join(desc_file.readlines())
+	desc_file.close()
+	return (True, desc)
+
 #-----------------------------------------------------------------------------------
 def call_viewer_on_file(aFile = None, block=None):
 	"""Try to find an appropriate viewer with all tricks and call it.
 
 	block: try to detach from viewer or not, None means to use mailcap default
 	"""
-	# does this file exist, actually ?
-	try:
-		open(aFile).close()
-	except:
-		_log.exception('cannot read [%s]', aFile)
-		msg = _('[%s] is not a readable file') % aFile
-		return False, msg
+	if not os.path.isdir(aFile):
+		# is the file accessible at all ?
+		try:
+			open(aFile).close()
+		except:
+			_log.exception('cannot read [%s]', aFile)
+			msg = _('[%s] is not a readable file') % aFile
+			return False, msg
 
 	# try to detect any of the UNIX openers
 	found, startfile_cmd = _get_system_startfile_cmd(aFile)
@@ -266,7 +321,7 @@ def call_viewer_on_file(aFile = None, block=None):
 	viewer_cmd = get_viewer_cmd(mime_type, aFile)
 
 	if viewer_cmd is not None:
-		if gmShellAPI.run_command_in_shell(command=viewer_cmd, blocking=block):
+		if gmShellAPI.run_command_in_shell(command = viewer_cmd, blocking = block):
 			return True, ''
 
 	_log.warning("no viewer found via standard mailcap system")
@@ -311,15 +366,27 @@ def call_viewer_on_file(aFile = None, block=None):
 #		os.remove(file_to_display)
 
 	return True, ''
+
 #=======================================================================================
 if __name__ == "__main__":
 
-	if len(sys.argv) > 1 and sys.argv[1] == u'test':
+	if len(sys.argv) < 2:
+		sys.exit()
+
+	if sys.argv[1] != 'test':
+		sys.exit()
+
+	# for testing:
+	logging.basicConfig(level = logging.DEBUG)
 
-		filename = sys.argv[2]
+	filename = sys.argv[2]
 
-		_get_system_startfile_cmd(filename)
-		print _system_startfile_cmd
-		#print guess_mimetype(filename)
-		#print get_viewer_cmd(guess_mimetype(filename), filename)
-		#print guess_ext_by_mimetype(mimetype=filename)
+	#_get_system_startfile_cmd(filename)
+	#print(_system_startfile_cmd)
+	#print(guess_mimetype(filename))
+	#print(get_viewer_cmd(guess_mimetype(filename), filename))
+	#print(guess_ext_by_mimetype(mimetype=filename))
+	#call_viewer_on_file(aFile = filename, block=None)
+	status, desc = describe_file(filename)
+	print status
+	print desc
diff --git a/server/pycommon/gmMimeMagic.py b/server/pycommon/gmMimeMagic.py
index 73ddd3c..6587f02 100644
--- a/server/pycommon/gmMimeMagic.py
+++ b/server/pycommon/gmMimeMagic.py
@@ -27,7 +27,7 @@ __version__ = '0.1'
 __author__ = "Jason Petrone <jp at demonseed.net>, Karsten Hilbert <Karsten.Hilbert at gmx.net>"
 __license__ = "GPL"
 
-import re, struct, string
+import re, struct, string, io
 #=================================================================
 magic = [
 	[0L, 'leshort', '=', 1538L, 'application/x-alan-adventure-game'],
@@ -1000,7 +1000,7 @@ class magicTest:
 			elif self.type == 'belong':
 				[data] = struct.unpack('>l', data[self.offset : self.offset + 4])
 			else:
-				#print 'UNKNOWN TYPE: ' + self.type
+				#print('UNKNOWN TYPE: ' + self.type)
 				pass
 		except:
 			return None
@@ -1011,7 +1011,7 @@ class magicTest:
 
 def load(file):
 	global magicNumbers
-	lines = open(file).readlines()
+	lines = io.open(file, mode = u'rt', encoding = 'utf8').readlines()
 	last = { 0: None }
 	for line in lines:
 		if re.match(r'\s*#', line):
@@ -1037,11 +1037,11 @@ def load(file):
 				l = last[level - 1].subTests
 			if offset[0] == '(':
 				# don't handle indirect offsets just yet
-				print 'SKIPPING ' + string.join(list(line[3:]))
+				print('SKIPPING ' + string.join(list(line[3:])))
 				pass
 			elif offset[0] == '&':
 				# don't handle relative offsets just yet
-				print 'SKIPPING ' + string.join(list(line[3:]))
+				print('SKIPPING ' + string.join(list(line[3:])))
 				pass
 			else:
 				operands = ['=', '<', '>', '&']
@@ -1069,7 +1069,7 @@ def load(file):
 				else:
 					if value.count('&') != 0:
 						mask = value[(value.index('&') + 1):]
-						print 'MASK: ' + mask
+						print('MASK: ' + mask)
 						value = value[:(value.index('&')+1)]
 					try: value = strToNum(value)
 					except: continue
@@ -1106,7 +1106,7 @@ def file(file):
 
 #### BUILD DATA ####
 #load('mime-magic')
-#f = open('out', 'w')
+#f = io.open('out', mode = 'wt', encoding = 'utf8')
 #for m in magicNumbers:
 #  f.write(str([m.offset, m.type, m.op, m.value, m.msg]) + ',\n')
 #f.close
@@ -1125,24 +1125,3 @@ if __name__ == '__main__':
 		else:
 			print arg + ': unknown'
 #=================================================================
-# $Log: gmMimeMagic.py,v $
-# Revision 1.2  2009-09-13 18:31:57  ncq
-# - proper mimetype for bitmaps
-#
-# Revision 1.1  2004/02/25 09:30:13  ncq
-# - moved here from python-common
-#
-# Revision 1.3  2003/11/17 10:56:36  sjtan
-#
-# synced and commiting.
-#
-# Revision 1.1  2003/10/23 06:02:39  sjtan
-#
-# manual edit areas modelled after r.terry's specs.
-#
-# Revision 1.2  2003/02/27 09:18:48  ncq
-# - added TODO
-#
-# Revision 1.1  2003/02/14 00:32:21  ncq
-# - Mime magic data
-#
diff --git a/server/pycommon/gmNetworkTools.py b/server/pycommon/gmNetworkTools.py
index 23a05de..73a633d 100644
--- a/server/pycommon/gmNetworkTools.py
+++ b/server/pycommon/gmNetworkTools.py
@@ -1,4 +1,7 @@
 # -*- coding: utf-8 -*-
+
+from __future__ import print_function
+
 __doc__ = """GNUmed internetworking tools."""
 
 #===========================================================================
@@ -17,6 +20,7 @@ import mimetools
 import StringIO
 import zipfile
 import webbrowser
+import io
 
 
 # GNUmed libs
@@ -35,6 +39,7 @@ _log = logging.getLogger('gm.net')
 #---------------------------------------------------------------------------
 def open_url_in_browser(url, new=2, autoraise=True, *args, **kwargs):
 	# url, new=0, autoraise=True
+	# new=2: open new tab if possible
 	try:
 		webbrowser.open(url, new = new, autoraise = autoraise, **kwargs)
 	except (webbrowser.Error, OSError, UnicodeEncodeError):
@@ -70,7 +75,7 @@ def download_data_pack(pack_url, filename=None, md5_url=None):
 	_log.debug('downloading MD5 from: %s', md5_url)
 	md5_fname = download_file(md5_url, filename = dp_fname + u'.md5')
 
-	md5_file = open(md5_fname, 'rU')
+	md5_file = io.open(md5_fname, mode = 'rt', encoding = 'utf8')
 	md5_expected = md5_file.readline().strip('\n')
 	md5_file.close()
 	_log.debug('expected MD5: %s', md5_expected)
@@ -428,14 +433,14 @@ Subject: gmTools test suite mail
 
 This is a test mail from the gmTools.py module.
 """ % (default_mail_receiver, default_mail_sender)
-		print "mail sending succeeded:", send_mail (
+		print("mail sending succeeded:", send_mail (
 #			sender = 'abc at xyz.123',
 			receiver = [default_mail_receiver, u'karsten.hilbert at gmx.net'],
 			message = msg,
 			auth = {'user': default_mail_sender, 'password': u'gnumed-at-gmx-net'}, # u'gm/bugs/gmx'
 			debug = True,
 			attachments = [[sys.argv[2]]]
-		)
+		))
 	#-----------------------------------------------------------------------
 	def test_check_for_update():
 
@@ -448,9 +453,9 @@ This is a test mail from the gmTools.py module.
 		]
 
 		for test in test_data:
-			print "arguments:", test
+			print("arguments:", test)
 			found, msg = check_for_update(test[0], test[1], test[2], test[3])
-			print msg
+			print(msg)
 
 		return
 	#-----------------------------------------------------------------------
@@ -459,13 +464,13 @@ This is a test mail from the gmTools.py module.
 		#url = 'missing-file.zip'
 		url = 'gmTools.py'
 		dl_name = download_data_pack(url)
-		print url, "->", dl_name
+		print(url, "->", dl_name)
 		unzip_dir = unzip_data_pack(dl_name)
-		print "unzipped into", unzip_dir
+		print("unzipped into", unzip_dir)
 	#-----------------------------------------------------------------------
 	def test_browser():
 		success = open_url_in_browser(sys.argv[2])
-		print success
+		print(success)
 		open_url_in_browser(sys.argv[2], abc=222)
 	#-----------------------------------------------------------------------
 	#test_check_for_update()
diff --git a/server/pycommon/gmNull.py b/server/pycommon/gmNull.py
index 8967d80..256c8ff 100644
--- a/server/pycommon/gmNull.py
+++ b/server/pycommon/gmNull.py
@@ -166,10 +166,19 @@ def test():
 
 	# comparing
 	if n == 1:
-		print "Null object == 1"
+		print("Null object == 1")
 	else:
-		print "Null object != 1"
+		print("Null object != 1")
 
-#==============================================================
+#--------------------------------------------------------------
 if __name__ == '__main__':
+
+	import sys
+
+	if len(sys.argv) < 2:
+		sys.exit()
+
+	if sys.argv[1] != 'test':
+		sys.exit()
+
 	test()
diff --git a/server/pycommon/gmPG2.py b/server/pycommon/gmPG2.py
index 4e9317b..d3f837d 100644
--- a/server/pycommon/gmPG2.py
+++ b/server/pycommon/gmPG2.py
@@ -18,6 +18,7 @@ __license__ = 'GPL v2 or later (details at http://www.gnu.org)'
 import time
 import sys
 import os
+import io
 import codecs
 import types
 import logging
@@ -119,7 +120,8 @@ known_schema_hashes = {
 	#19: '419e5225259c53dd36ad80d82066ff02'	# 19.0 only
 	#19: '9765373098b03fb208332498f34cd4b5' # until 19.11
 	19: '57f009a159f55f77525cc0291e0c8b60', # starting with 19.12
-	20: 'baed1901ed4c2f272b56c8cb2c6d88e8'
+	20: 'baed1901ed4c2f272b56c8cb2c6d88e8',
+	21: 'e6a51a89dd22b75b61ead8f7083f251f'
 }
 
 map_schema_hash2version = {
@@ -143,7 +145,8 @@ map_schema_hash2version = {
 	#'419e5225259c53dd36ad80d82066ff02': 19	# 19.0 only
 	#'9765373098b03fb208332498f34cd4b5': 19 # until 19.11
 	'57f009a159f55f77525cc0291e0c8b60': 19, # starting with 19.12
-	'baed1901ed4c2f272b56c8cb2c6d88e8': 20
+	'baed1901ed4c2f272b56c8cb2c6d88e8': 20,
+	'e6a51a89dd22b75b61ead8f7083f251f': 21
 }
 
 map_client_branch2required_db_version = {
@@ -160,7 +163,8 @@ map_client_branch2required_db_version = {
 	u'1.2': 17,
 	u'1.3': 18,
 	u'1.4': 19,
-	u'1.5': 20
+	u'1.5': 20,
+	u'1.6': 21
 }
 
 # get columns and data types for a given table
@@ -419,7 +423,7 @@ def __request_login_params_tui():
 	print "\nPlease enter the required login parameters:"
 	try:
 		login.host = prompted_input(prompt = "host ('' = non-TCP/IP)", default = '')
-		login.database = prompted_input(prompt = "database", default = 'gnumed_v20')
+		login.database = prompted_input(prompt = "database", default = 'gnumed_v21')
 		login.user = prompted_input(prompt = "user name", default = '')
 		tmp = 'password for "%s" (not shown): ' % login.user
 		login.password = getpass.getpass(tmp)
@@ -440,7 +444,7 @@ def __request_login_params_gui_wx():
 	# OK, wxPython was already loaded. But has the main Application instance
 	# been initialized yet ? if not, the exception will kick us out
 	if wx.GetApp() is None:
-		raise gmExceptions.NoGuiError(_("The wxPython GUI framework hasn't been initialized yet!"))
+		raise AssertionError(_("The wxPython GUI framework hasn't been initialized yet!"))
 
 	# Let's launch the login dialog
 	# if wx was not initialized /no main App loop, an exception should be raised anyway
@@ -465,7 +469,7 @@ def request_login_params():
 	# are we inside X ?
 	# (if we aren't wxGTK will crash hard at
 	# C-level with "can't open Display")
-	if os.environ.has_key('DISPLAY'):
+	if u'DISPLAY' in os.environ:
 		# try wxPython GUI
 		try: return __request_login_params_gui_wx()
 		except: pass
@@ -557,7 +561,7 @@ def log_auth_environment():
 				_log.debug('$PGPASSFILE=%s exists', pgpass_var)
 			else:
 				_log.debug('$PGPASSFILE=%s not found')
-	except StandardError:
+	except Exception:
 		_log.exception('cannot detect .pgpass and or $PGPASSFILE')
 # =======================================================================
 # netadata API
@@ -790,7 +794,7 @@ def get_col_indices(cursor = None):
 		# a query like "select 1,2;" will return two columns of the same name !
 		# hence adjust to that, note, however, that dict-style access won't work
 		# on results of such queries ...
-		if col_indices.has_key(col_name):
+		if col_name in col_indices:
 			col_name = '%s_%s' % (col_name, col_index)
 		col_indices[col_name] = col_index
 		col_index += 1
@@ -825,7 +829,7 @@ def get_col_names(link_obj=None, schema='public', table=None):
 # i18n functions
 #------------------------------------------------------------------------
 def export_translations_from_database(filename=None):
-	tx_file = codecs.open(filename, 'wb', 'utf8')
+	tx_file = io.open(filename, mode = 'wt', encoding = 'utf8')
 	tx_file.write(u'-- GNUmed database string translations exported %s\n' % gmDateTime.pydt_now_here().strftime('%Y-%m-%d %H:%M'))
 	tx_file.write(u'-- - contains translations for each of [%s]\n' % u', '.join(get_translation_languages()))
 	tx_file.write(u'-- - user database language is set to [%s]\n\n' % get_current_user_language())
@@ -850,6 +854,7 @@ def export_translations_from_database(filename=None):
 	tx_file.close()
 
 	return True
+
 #------------------------------------------------------------------------
 def delete_translation_from_database(link_obj=None, language=None, original=None):
 	cmd = u'DELETE FROM i18n.translations WHERE lang = %(lang)s AND orig = %(orig)s'
@@ -1086,6 +1091,7 @@ def bytea2file(data_query=None, filename=None, chunk_size=0, data_size=None, dat
 	result = bytea2file_object(data_query=data_query, file_obj=outfile, chunk_size=chunk_size, data_size=data_size, data_size_query=data_size_query)
 	outfile.close()
 	return result
+
 #------------------------------------------------------------------------
 def bytea2file_object(data_query=None, file_obj=None, chunk_size=0, data_size=None, data_size_query=None):
 	"""Store data from a bytea field into a file.
@@ -1184,6 +1190,7 @@ def bytea2file_object(data_query=None, file_obj=None, chunk_size=0, data_size=No
 
 	conn.rollback()
 	return True
+
 #------------------------------------------------------------------------
 def file2bytea(query=None, filename=None, args=None, conn=None, file_md5=None):
 	"""Store data from a file into a bytea field.
@@ -1234,6 +1241,218 @@ def file2bytea(query=None, filename=None, args=None, conn=None, file_md5=None):
 		conn.close()
 
 	return success_status
+
+#------------------------------------------------------------------------
+def file2lo(filename=None, conn=None, check_md5=False):
+	# 1 GB limit unless 64 bit Python build ...
+	file_size = os.path.getsize(filename)
+	if file_size > (1024 * 1024) * 1024:
+		_log.debug(u'file size of [%s] > 1 GB, supposedly not supported by psycopg2 large objects (but seems to work anyway ?)', file_size)
+#		return -1
+
+	if conn is None:
+		conn = get_raw_connection(readonly = False)
+		close_conn = conn.close
+	else:
+		close_conn = __noop
+	_log.debug(u'[%s] -> large object', filename)
+
+	# insert the data
+	lo = conn.lobject(0, 'w', 0, filename)
+	lo_oid = lo.oid
+	lo.close()
+	_log.debug('large object OID: %s', lo_oid)
+
+	# verify
+	if file_md5 is None:
+		conn.commit()
+		close_conn()
+		return lo_oid
+	cmd = u'SELECT md5(lo_get(%(loid)s::oid))'
+	args = {'loid': lo_oid}
+	rows, idx = run_ro_queries(link_obj = conn, queries = [{'cmd': cmd, 'args': args}])
+	db_md5 = rows[0][0]
+	if file_md5 == db_md5:
+		conn.commit()
+		close_conn()
+		_log.debug('MD5 sums of data file and database large object match: [file::%s] = [DB::%s]', file_md5, db_md5)
+		return lo_oid
+	conn.rollback()
+	close_conn()
+	_log.error('MD5 sums of data file and database large object [%s] do not match: [file::%s] <> [DB::%s]', lo_oid, file_md5, db_md5)
+	return -1
+
+#------------------------------------------------------------------------
+def file2bytea_lo(filename=None, conn=None, file_md5=None):
+	# 1 GB limit unless 64 bit Python build ...
+	file_size = os.path.getsize(filename)
+	if file_size > (1024 * 1024) * 1024:
+		_log.debug(u'file size of [%s] > 1 GB, supposedly not supported by psycopg2 large objects (but seems to work anyway ?)', file_size)
+#		return -1
+
+	if conn is None:
+		conn = get_raw_connection(readonly = False)
+		close_conn = conn.close
+	else:
+		close_conn = __noop
+	_log.debug(u'[%s] -> large object', filename)
+
+	# insert the data
+	lo = conn.lobject(0, 'w', 0, filename)
+	lo_oid = lo.oid
+	lo.close()
+	_log.debug('large object OID: %s', lo_oid)
+
+	# verify
+	if file_md5 is None:
+		conn.commit()
+		close_conn()
+		return lo_oid
+	cmd = u'SELECT md5(lo_get(%(loid)s::oid))'
+	args = {'loid': lo_oid}
+	rows, idx = run_ro_queries(link_obj = conn, queries = [{'cmd': cmd, 'args': args}])
+	db_md5 = rows[0][0]
+	if file_md5 == db_md5:
+		conn.commit()
+		close_conn()
+		_log.debug('MD5 sums of data file and database large object match: [file::%s] = [DB::%s]', file_md5, db_md5)
+		return lo_oid
+	conn.rollback()
+	close_conn()
+	_log.error('MD5 sums of data file and database large object [%s] do not match: [file::%s] <> [DB::%s]', lo_oid, file_md5, db_md5)
+	return -1
+
+#------------------------------------------------------------------------
+def file2bytea_copy_from(table=None, columns=None, filename=None, conn=None, md5_query=None, file_md5=None):
+	# md5_query: dict{'cmd': ..., 'args': ...}
+
+	# UNTESTED
+
+	chunk_size = 32 * (1024 * 1024)
+	_log.debug('[%s] (%s bytes) --(%s bytes)-> %s(%s)', filename, os.path.getsize(filename), chunk_size, table, columns)
+	if conn is None:
+		conn = get_raw_connection(readonly = False)
+		close_conn = True
+	else:
+		close_conn = False
+	curs = conn.cursor()
+	# write
+	infile = file(filename, "rb")
+	curs.copy_from(infile, table, size = chunk_size, columns = columns)
+	infile.close()
+	curs.close()
+	if None in [file_md5, md5_query]:
+		conn.commit()
+		close_conn()
+		return True
+	# verify
+	rows, idx = run_ro_queries(link_obj = conn, queries = [md5_query])
+	db_md5 = rows[0][0]
+	if file_md5 == db_md5:
+		conn.commit()
+		close_conn()
+		_log.debug('MD5 sums of data file and database BYTEA field match: [file::%s] = [DB::%s]', file_md5, db_md5)
+		return True
+	close_conn()
+	_log.error('MD5 sums of data file and database BYTEA field do not match: [file::%s] <> [DB::%s]', file_md5, db_md5)
+	return False
+
+#------------------------------------------------------------------------
+def file2bytea_overlay(query=None, args=None, filename=None, conn=None, md5_query=None, file_md5=None):
+	"""Store data from a file into a bytea field.
+
+	The query must:
+	- 'cmd' must be in unicode
+	- 'cmd' must contain a format spec identifying the row (eg
+	  a primary key) matching <args> if it is an UPDATE
+	- 'cmd' must contain "... SET ... <some_bytea_field> = OVERLAY(some_bytea_field PLACING %(data)s::bytea FROM %(start)s FOR %(size)s) ..."
+	- 'args' must be a dict matching 'cmd'
+
+	The query CAN return the MD5 of the inserted data:
+		RETURNING md5(<field>) AS md5
+	in which case it will compare it to the md5
+	of the file.
+
+	UPDATE
+		the_table
+	SET
+		bytea_field = OVERLAY (
+			coalesce(bytea_field, '':bytea),
+			PLACING
+				%(data)s::bytea
+			FROM
+				%(start)s
+			FOR
+				%(size)s
+		)
+	WHERE
+		primary_key = pk_value
+
+	SELECT md5(bytea_field) FROM the_table WHERE primary_key = pk_value
+	"""
+	chunk_size = 32 * (1024 * 1024)
+	file_size = os.path.getsize(filename)
+	if file_size <= chunk_size:
+		chunk_size = file_size
+	needed_chunks, remainder = divmod(file_size, chunk_size)
+	_log.debug('file data: %s bytes, chunks: %s, chunk size: %s bytes, remainder: %s bytes', file_size, needed_chunks, chunk_size, remainder)
+
+	if conn is None:
+		conn = get_raw_connection(readonly = False)
+		close_conn = conn.close
+	else:
+		close_conn = __noop
+
+	infile = file(filename, "rb")
+	# write chunks
+	for chunk_id in range(needed_chunks):
+		chunk_start = (chunk_id * chunk_size) + 1
+		args['start'] = chunk_start
+		args['size'] = chunk_size
+		data_as_byte_string = infile.read(chunk_size)
+		args['data'] = buffer(data_as_byte_string)
+		del(data_as_byte_string)
+		try:
+			rows, idx = run_rw_queries(link_obj = conn, queries = [{'cmd': query, 'args': args}], end_tx = False, return_data = False)
+		except StandardError:
+			_log.exception('cannot write chunk [%s/%s] of size [%s], try decreasing chunk size', chunk_id+1, needed_chunks, chunk_size)
+			conn.rollback()
+			close_conn()
+			infile.close()
+			raise
+	# write remainder
+	if remainder > 0:
+		chunk_start = (needed_chunks * chunk_size) + 1
+		args['start'] = chunk_start
+		args['size'] = remainder
+		data_as_byte_string = infile.read(remainder)
+		args['data'] = buffer(data_as_byte_string)
+		del(data_as_byte_string)
+		try:
+			rows, idx = run_rw_queries(link_obj = conn, queries = [{'cmd': query, 'args': args}], end_tx = False, return_data = False)
+		except StandardError:
+			_log.error('cannot retrieve remaining [%s] bytes' % remainder)
+			conn.rollback()
+			close_conn()
+			infile.close()
+			raise
+	infile.close()
+	if None in [file_md5, md5_query]:
+		conn.commit()
+		close_conn()
+		return True
+	# verify
+	rows, idx = run_ro_queries(link_obj = conn, queries = [{'cmd': md5_query, 'args': args}])
+	db_md5 = rows[0][0]
+	if file_md5 == db_md5:
+		conn.commit()
+		close_conn()
+		_log.debug('MD5 sums of data file and database BYTEA field match: [file::%s] = [DB::%s]', file_md5, db_md5)
+		return True
+	close_conn()
+	_log.error('MD5 sums of data file and database BYTEA field do not match: [file::%s] <> [DB::%s]', file_md5, db_md5)
+	return False
+
 #------------------------------------------------------------------------
 def sanitize_pg_regex(expression=None, escape_all=False):
 	"""Escape input for use in a PostgreSQL regular expression.
@@ -1260,6 +1479,7 @@ def sanitize_pg_regex(expression=None, escape_all=False):
 			'*', '\*'
 		)
 		#']', '\]',			# not needed
+
 #------------------------------------------------------------------------
 def run_ro_queries(link_obj=None, queries=None, verbose=False, return_data=True, get_col_idx=False):
 	"""Run read-only queries.
@@ -1275,15 +1495,24 @@ def run_ro_queries(link_obj=None, queries=None, verbose=False, return_data=True,
 		curs = link_obj
 		curs_close = __noop
 		tx_rollback = __noop
+		readonly_rollback_just_in_case = __noop
 	elif isinstance(link_obj, dbapi._psycopg.connection):
 		curs = link_obj.cursor()
 		curs_close = curs.close
 		tx_rollback = link_obj.rollback
+		if link_obj.autocommit is True:		# readonly connection ?
+			readonly_rollback_just_in_case = link_obj.rollback
+		else:
+			# do not rollback readonly queries on passed-in readwrite
+			# connections just in case because they may have already
+			# seen fully legitimate write action which would get lost
+			readonly_rollback_just_in_case = __noop
 	elif link_obj is None:
 		conn = get_connection(readonly=True, verbose=verbose)
 		curs = conn.cursor()
 		curs_close = curs.close
 		tx_rollback = conn.rollback
+		readonly_rollback_just_in_case = conn.rollback
 	else:
 		raise ValueError('link_obj must be cursor, connection or None but not [%s]' % link_obj)
 
@@ -1358,8 +1587,9 @@ def run_ro_queries(link_obj=None, queries=None, verbose=False, return_data=True,
 			col_idx = get_col_indices(curs)
 
 	curs_close()
-	tx_rollback()		# rollback just so that we don't stay IDLE IN TRANSACTION forever
+	readonly_rollback_just_in_case()
 	return (data, col_idx)
+
 #------------------------------------------------------------------------
 def run_rw_queries(link_obj=None, queries=None, end_tx=False, return_data=None, get_col_idx=False, verbose=False):
 	"""Convenience function for running a transaction
@@ -1511,6 +1741,7 @@ def run_rw_queries(link_obj=None, queries=None, end_tx=False, return_data=None,
 	conn_close()
 
 	return (data, col_idx)
+
 #------------------------------------------------------------------------
 def run_insert(link_obj=None, schema=None, table=None, values=None, returning=None, end_tx=False, get_col_idx=False, verbose=False):
 	"""Generates SQL for an INSERT query.
@@ -1554,6 +1785,7 @@ def run_insert(link_obj=None, schema=None, table=None, values=None, returning=No
 		get_col_idx = get_col_idx,
 		verbose = verbose
 	)
+
 # =======================================================================
 # connection handling API
 # -----------------------------------------------------------------------
@@ -1585,6 +1817,7 @@ class cConnectionPool(psycopg2.pool.PersistentConnectionPool):
 		for conn_key in self._used.keys():
 			_log.debug('closing pooled database connection, pool key: %s, backend PID: %s', conn_key, self._used[conn_key].get_backend_pid())
 			self._used[conn_key].original_close()
+
 # -----------------------------------------------------------------------
 def get_raw_connection(dsn=None, verbose=False, readonly=True):
 	"""Get a raw, unadorned connection.
@@ -1867,7 +2100,8 @@ def sanity_check_database_settings():
 		#u'regex_flavor': [u'advanced', u'query breakage', False],					# 9.0 doesn't support this anymore, default now advanced anyway
 		u'synchronous_commit': [u'on', u'data loss/corruption', False],
 		u'sql_inheritance': [u'on', u'query breakage, data loss/corruption', True],
-		u'ignore_checksum_failure': [u'off', u'data loss/corruption', False]		# starting with PG 9.3
+		u'ignore_checksum_failure': [u'off', u'data loss/corruption', False],		# starting with PG 9.3
+		u'track_commit_timestamp': [u'on', u'suboptimal auditing', False]			# starting with PG 9.3
 	}
 
 	from Gnumed.pycommon import gmCfg2
@@ -2069,22 +2303,99 @@ if __name__ == "__main__":
 	if sys.argv[1] != 'test':
 		sys.exit()
 
+	from Gnumed.pycommon.gmTools import file2md5
+
 	logging.basicConfig(level=logging.DEBUG)
+
 	#--------------------------------------------------------------------
 	def test_file2bytea():
 		run_rw_queries(queries = [
+			{'cmd': u'drop table if exists test_bytea'},
 			{'cmd': u'create table test_bytea (data bytea)'}
 		])
 
-		cmd = u'insert into test_bytea values (%(data)s::bytea)'
 		try:
-			file2bytea(query = cmd, filename = sys.argv[2])
+			file2bytea(query = u'insert into test_bytea values (%(data)s::bytea) returning md5(data) as md5', filename = sys.argv[2], file_md5 = file2md5(sys.argv[2], True))
 		except:
 			_log.exception('error')
 
 		run_rw_queries(queries = [
 			{'cmd': u'drop table test_bytea'}
 		])
+
+	#--------------------------------------------------------------------
+	def test_file2bytea_lo():
+		lo_oid = file2bytea_lo (
+			filename = sys.argv[2]
+			#, file_md5 = file2md5(sys.argv[2], True)
+		)
+		print lo_oid
+#		if lo_oid != -1:
+#			run_rw_queries(queries = [
+#				{'cmd': u'select lo_unlink(%(loid)s::oid)', 'args': {'loid': lo_oid}}
+#			])
+
+	#--------------------------------------------------------------------
+	def test_file2bytea_copy_from():
+
+		run_rw_queries(queries = [
+			{'cmd': u'drop table if exists test_bytea'},
+			{'cmd': u'create table test_bytea (pk serial primary key, data bytea)'},
+			{'cmd': u"insert into test_bytea (data) values (NULL::bytea)"}
+		])
+
+		md5_query = {
+			'cmd': u'select md5(data) AS md5 FROM test_bytea WHERE pk = %(pk)s',
+			'args': {'pk': 1}
+		}
+
+		file2bytea_copy_from (
+			table = u'test_bytea',
+			columns = [u'data'],
+			filename = sys.argv[2],
+			md5_query = md5_query,
+			file_md5 = file2md5(sys.argv[2], True)
+		)
+
+		run_rw_queries(queries = [
+			{'cmd': u'drop table if exists test_bytea'}
+		])
+
+	#--------------------------------------------------------------------
+	def test_file2bytea_overlay():
+
+		run_rw_queries(queries = [
+			{'cmd': u'drop table if exists test_bytea'},
+			{'cmd': u'create table test_bytea (pk serial primary key, data bytea)'},
+			{'cmd': u"insert into test_bytea (data) values (NULL::bytea)"}
+		])
+
+		cmd = u"""
+		update test_bytea
+		set data = overlay (
+			coalesce(data, ''::bytea)
+			placing %(data)s::bytea
+			from %(start)s
+			for %(size)s
+		)
+		where
+			pk > %(pk)s
+		"""
+		md5_cmd = u'select md5(data) from test_bytea'
+		args = {'pk': 0}
+		file2bytea_overlay (
+			query = cmd,
+			args = args,
+			filename = sys.argv[2],
+			conn = None,
+			md5_query = md5_cmd,
+			file_md5 = file2md5(sys.argv[2], True)
+		)
+
+		run_rw_queries(queries = [
+			{'cmd': u'drop table test_bytea'}
+		])
+
 	#--------------------------------------------------------------------
 	def test_get_connection():
 		print "testing get_connection()"
@@ -2455,7 +2766,6 @@ SELECT to_timestamp (foofoo,'YYMMDD.HH24MI') FROM (
 
 	#--------------------------------------------------------------------
 	# run tests
-	#test_file2bytea()
 	#test_get_connection()
 	#test_exceptions()
 	#test_ro_queries()
@@ -2468,12 +2778,16 @@ SELECT to_timestamp (foofoo,'YYMMDD.HH24MI') FROM (
 	#test_sanity_check_time_skew()
 	#test_get_foreign_key_details()
 	#test_get_foreign_key_names()
-	test_get_index_name()
+	#test_get_index_name()
 	#test_set_user_language()
 	#test_get_schema_revision_history()
 	#test_run_query()
 	#test_schema_exists()
 	#test_get_foreign_key_names()
 	#test_row_locks()
+	#test_file2bytea()
+	#test_file2bytea_overlay()
+	#test_file2bytea_copy_from()
+	test_file2bytea_lo()
 
 # ======================================================================
diff --git a/server/pycommon/gmPrinting.py b/server/pycommon/gmPrinting.py
index 3697b3c..f8eda0c 100644
--- a/server/pycommon/gmPrinting.py
+++ b/server/pycommon/gmPrinting.py
@@ -1,14 +1,16 @@
-"""GNUmed printing."""
-# =======================================================================
+
+from __future__ import print_function
+
+__doc__ = """GNUmed printing."""
+
 __author__  = "K.Hilbert <Karsten.Hilbert at gmx.net>"
 __license__ = 'GPL v2 or later (details at http://www.gnu.org)'
-
 # =======================================================================
 import logging
 import sys
 import os
 import subprocess
-import codecs
+import io
 import time
 
 
@@ -52,7 +54,7 @@ def print_files(filenames=None, jobtype=None, print_api=None):
 			return False
 
 	if jobtype not in known_printjob_types:
-		print "unregistered print job type <%s>" % jobtype
+		print("unregistered print job type <%s>" % jobtype)
 		_log.warning('print job type "%s" not registered', jobtype)
 
 	if print_api not in external_print_APIs:
@@ -196,12 +198,12 @@ def _print_files_by_gsprint_exe(filenames=None):
 	).encode(sys.getfilesystemencoding())
 
 	for filename in filenames:
-		conf_file = codecs.open(conf_filename, 'wb', 'utf8')
-		conf_file.write('-color\n')
-		conf_file.write('-query\n')				# printer setup dialog
-		conf_file.write('-all\n')				# all pages
-		conf_file.write('-copies 1\n')
-		conf_file.write('%s\n' % os.path.normpath(filename))
+		conf_file = io.open(conf_filename, mode = 'wt', encoding = 'utf8')
+		conf_file.write(u'-color\n')
+		conf_file.write(u'-query\n')			# printer setup dialog
+		conf_file.write(u'-all\n')				# all pages
+		conf_file.write(u'-copies 1\n')
+		conf_file.write(u'%s\n' % os.path.normpath(filename))
 		conf_file.close()
 
 		cmd_line = [
@@ -210,13 +212,13 @@ def _print_files_by_gsprint_exe(filenames=None):
 		]
 		_log.debug('printing with %s' % cmd_line)
 		try:
-			gsprint = subprocess.Popen(cmd_line)
+			gsprint_process = subprocess.Popen(cmd_line)
 		except OSError:
 			_log.debug('cannot run <gsprint.exe>')
 			return False
-		gsprint.communicate()
-		if gsprint.returncode != 0:
-			_log.error('<gsprint.exe> returned [%s], failed to print', gsprint.returncode)
+		gsprint_process.communicate()
+		if gsprint_process.returncode != 0:
+			_log.error('<gsprint.exe> returned [%s], failed to print', gsprint_process.returncode)
 			return False
 
 	return True
@@ -355,10 +357,10 @@ if __name__ == '__main__':
 		print_files(filenames = [sys.argv[2], sys.argv[2]], jobtype = u'generic_document', print_api = u'gtklp')
 	#--------------------------------------------------------------------
 	def test_print_files_by_mac_preview():
-		print "testing printing via Mac Preview"
+		print("testing printing via Mac Preview")
 		_print_files_by_mac_preview(filenames = [sys.argv[0]])
 	#--------------------------------------------------------------------
-	print test_print_files()
+	print(test_print_files())
 	#test_print_files_by_gtklp()
 	#test_print_files_by_mac_preview()
 
diff --git a/server/pycommon/gmPsql.py b/server/pycommon/gmPsql.py
index 92ef75d..46df8c1 100644
--- a/server/pycommon/gmPsql.py
+++ b/server/pycommon/gmPsql.py
@@ -9,7 +9,7 @@ __author__ = "Ian Haywood"
 __license__ = "GPL v2 or later (details at http://www.gnu.org)"
 
 # stdlib
-import sys, os, string, re, urllib2, logging
+import sys, os, string, re, urllib2, logging, io
 
 
 _log = logging.getLogger('gm.bootstrapper')
@@ -31,6 +31,7 @@ def shell(str):
 	performs backtick shell extension in a string
 	"""
 	return re.sub (r"`(.*)`", shellrun, str)
+
 #===================================================================
 class Psql:
 
@@ -59,8 +60,8 @@ class Psql:
 			global unformattable_error_id
 			tmp = u"%s:%d: <cannot unicode(msg), printing on console with ID [#%d]>" % (self.filename, self.lineno-1, unformattable_error_id)
 			try:
-				print 'ERROR: GNUmed bootstrap #%d:' % unformattable_error_id
-				print aMsg
+				print('ERROR: GNUmed bootstrap #%d:' % unformattable_error_id)
+				print(aMsg)
 			except: pass
 			unformattable_error_id += 1
 		return tmp
@@ -69,17 +70,18 @@ class Psql:
 		"""
 		filename: a file, containg semicolon-separated SQL commands
 		"""
+		_log.debug('processing [%s]', filename)
 		if re.match ("http://.*", filename) or re.match ("ftp://.*", filename) or re.match ("gopher://.*", filename):
 			try:
 				self.file = urllib2.urlopen (filename)
 			except URLError:
-				_log.error(u"cannot access %s" % filename)
+				_log.error(u"cannot access [%s]", filename)
 				return 1
 		else:
 			if os.access (filename, os.R_OK):
-				self.file = open(filename)
+				self.file = io.open(filename, mode = 'rt', encoding = 'utf8')
 			else:
-				_log.error(u"cannot open file [%s]" % filename)
+				_log.error(u"cannot open file [%s]", filename)
 				return 1
 
 		self.lineno = 0
@@ -88,7 +90,7 @@ class Psql:
 		bracketlevel = 0
 		curr_cmd = ''
 		curs = self.conn.cursor ()
-#		transaction_started = False
+##		transaction_started = False
 		for self.line in self.file.readlines():
 			self.lineno += 1
 			if len(self.line.strip()) == 0:
@@ -116,57 +118,6 @@ class Psql:
 			if self.match (r"^\\unset (\S+)"):
 				self.vars[self.groups[0]] = None
 				continue
-			# \connect
-			if self.match (r"^\\connect.*"):
-				_log.error(self.fmt_msg(u"\\connect not yet supported in scripts"))
-				continue
-			# \lo_import
-			if self.match (r"^\\lo_import.*"):
-				_log.error(self.fmt_msg(u"\\lo_import not yet supported"))
-				# no sense to continue here
-				return 1
-			# \copy ... to ...
-			if self.match (r"^\\copy .* to '(\S+)' .*"):
-				_log.error(self.fmt_msg(u"\\copy to not implemented"))
-				return 1
-			# \copy ... from ...
-			if self.match (r"^\\copy .* from '(\S+)' .*"):
-				copyfile = self.groups[0]
-				try:
-					copyfd = file (os.path.join (os.path.dirname (self.filename), copyfile))
-				except error:
-					_log.error(self.fmt_msg(error))
-					return 1
-				self.line = self.line[1:].strip() # lop off leading slash
-				self.line.replace ("'%s'" % copyfile, 'stdin')
-				# now we have a command that the backend understands
-				copyline = 0
-				try:
-					curs = self.conn.cursor ()
-					# send the COPY command
-					curs.execute (self.line)
-					# send the data
-					for i in copyfd.readlines ():
-						curs.execute (i)
-						copyline += 1
-					self.conn.commit ()
-					curs.close ()
-				except StandardError, error:
-					_log.error(u"%s: %d: %s" % (copyfile, copyline, error))
-					if self.vars['ON_ERROR_STOP']:
-						return 1
-				continue
-
-			# \i
-			if self.match (r"^\\i (\S+)"):
-				# create another interpreter instance in same connection
-				Psql(self.conn).run (os.path.join (os.path.dirname (self.filename), self.groups[0]))
-				continue
-
-			# \encoding
-			if self.match (r"^\\encoding.*"):
-				_log.error(self.fmt_msg(u"\\encoding not yet supported"))
-				continue
 
 			# other '\' commands
 			if self.match (r"^\\(.*)") and not in_string:
@@ -229,7 +180,7 @@ class Psql:
 							else:
 								curs.execute (curr_cmd)
 #								if not transaction_started:
-					except StandardError, error:
+					except Exception, error:
 						_log.debug(curr_cmd)
 						if re.match (r"^NOTICE:.*", str(error)):
 							_log.warning(self.fmt_msg(error))
@@ -256,7 +207,14 @@ class Psql:
 #===================================================================
 # testing code
 if __name__ == '__main__':
-	from pyPgSQL import PgSQL
+
+	if len(sys.argv) < 2:
+		sys.exit()
+
+	if sys.argv[1] != 'test':
+		sys.exit()
+
+	#from pyPgSQL import PgSQL
 	conn = PgSQL.connect (user='gm-dbo', database = 'gnumed')
 	psql = Psql (conn)
 	psql.run (sys.argv[1])
diff --git a/server/pycommon/gmScanBackend.py b/server/pycommon/gmScanBackend.py
index 4d6e6f4..560ff0e 100644
--- a/server/pycommon/gmScanBackend.py
+++ b/server/pycommon/gmScanBackend.py
@@ -1,6 +1,9 @@
 #==================================================
 # GNUmed SANE/TWAIN scanner classes
 #==================================================
+
+from __future__ import print_function
+
 __license__ = "GPL v2 or later"
 __author__ = """Sebastian Hilbert <Sebastian.Hilbert at gmx.net>, Karsten Hilbert <Karsten.Hilbert at gmx.net>"""
 
@@ -11,7 +14,7 @@ import os.path
 import os
 import time
 import shutil
-import codecs
+import io
 import glob
 import logging
 #import stat
@@ -413,8 +416,8 @@ class cXSaneScanner:
 
 		# our closest bet, might contain umlauts
 		enc = gmI18N.get_encoding()
-		fread = codecs.open(self._gm_custom_xsanerc, mode = "rU", encoding = enc)
-		fwrite = codecs.open(session_xsanerc, mode = "w", encoding = enc)
+		fread = io.open(self._gm_custom_xsanerc, mode = "rt", encoding = enc)
+		fwrite = io.open(session_xsanerc, mode = "wt", encoding = enc)
 
 		paths = gmTools.gmPaths()
 		val_dict = {
@@ -499,8 +502,8 @@ if __name__ == '__main__':
 
 		logging.basicConfig(level=logging.DEBUG)
 
-		print "devices:"
-		print get_devices()
+		print("devices:")
+		print(get_devices())
 
 		sys.exit()
 
@@ -512,10 +515,10 @@ if __name__ == '__main__':
 
 		idx = 1
 		for setup in setups:
-			print "scanning page #%s from device [%s]" % (idx, setup['dev'])
+			print("scanning page #%s from device [%s]" % (idx, setup['dev']))
 			idx += 1
 			fnames = acquire_pages_into_files(device = setup['dev'], filename = setup['file'], delay = (idx*5))
 			if fnames is False:
-				print "error, cannot acquire page"
+				print("error, cannot acquire page")
 			else:
-				print " image files:", fnames
+				print(" image files:", fnames)
diff --git a/server/pycommon/gmScriptingListener.py b/server/pycommon/gmScriptingListener.py
index adabe2b..f4a6c9f 100644
--- a/server/pycommon/gmScriptingListener.py
+++ b/server/pycommon/gmScriptingListener.py
@@ -108,7 +108,7 @@ class cScriptingListener:
 				try:
 					self._server.handle_request()
 				except:
-					print "cannot serve RPC"
+					print("cannot serve RPC")
 					break
 				if self._quit_lock.acquire(0):
 					break
diff --git a/server/pycommon/gmShellAPI.py b/server/pycommon/gmShellAPI.py
index 124c181..9b442c2 100644
--- a/server/pycommon/gmShellAPI.py
+++ b/server/pycommon/gmShellAPI.py
@@ -1,3 +1,6 @@
+
+from __future__ import print_function
+
 __doc__ = """GNUmed general tools."""
 
 #===========================================================================
@@ -269,25 +272,25 @@ if __name__ == '__main__':
 	def test_detect_external_binary():
 		found, path = detect_external_binary(binary = sys.argv[2])
 		if found:
-			print "found as:", path
+			print("found as:", path)
 		else:
-			print sys.argv[2], "not found"
+			print(sys.argv[2], "not found")
 	#---------------------------------------------------------
 	def test_run_command_in_shell():
-		print "-------------------------------------"
-		print "running:", sys.argv[2]
+		print("-------------------------------------")
+		print("running:", sys.argv[2])
 		if run_command_in_shell(command=sys.argv[2], blocking=False):
-			print "-------------------------------------"
-			print "success"
+			print("-------------------------------------")
+			print("success")
 		else:
-			print "-------------------------------------"
-			print "failure, consult log"
+			print("-------------------------------------")
+			print("failure, consult log")
 	#---------------------------------------------------------
 	def test_is_cmd_in_path():
-		print is_cmd_in_path(cmd = sys.argv[2])
+		print(is_cmd_in_path(cmd = sys.argv[2]))
 	#---------------------------------------------------------
 	def test_is_executable_by_wine():
-		print is_executable_by_wine(cmd = sys.argv[2])
+		print(is_executable_by_wine(cmd = sys.argv[2]))
 	#---------------------------------------------------------
 	test_run_command_in_shell()
 	#test_detect_external_binary()
diff --git a/server/pycommon/gmTools.py b/server/pycommon/gmTools.py
index de090ee..20d7058 100644
--- a/server/pycommon/gmTools.py
+++ b/server/pycommon/gmTools.py
@@ -1,4 +1,7 @@
 # -*- coding: utf-8 -*-
+
+from __future__ import print_function
+
 __doc__ = """GNUmed general tools."""
 
 #===========================================================================
@@ -17,20 +20,22 @@ import platform
 import subprocess
 import decimal
 import getpass
+import io
+import functools
+import json
+import shutil
+import zipfile
+import datetime as pydt
 import re as regex
 import xml.sax.saxutils as xml_tools
 # old:
-import cPickle, zlib
+import pickle, zlib
 
 
 # GNUmed libs
 if __name__ == '__main__':
-	# for testing:
-	logging.basicConfig(level = logging.DEBUG)
 	sys.path.insert(0, '../../')
-	from Gnumed.pycommon import gmI18N
-	gmI18N.activate_locale()
-	gmI18N.install_domain()
+
 
 from Gnumed.pycommon import gmBorg
 
@@ -69,7 +74,7 @@ u_numero = u'\u2116'						# No. / # sign
 u_down_left_arrow = u'\u21B5'				# <-'
 u_left_arrow = u'\u2190'					# <--
 u_up_arrow = u'\u2191'
-u_right_arrow = u'\u2192'					# -->
+u_arrow2right = u'\u2192'					# -->
 u_down_arrow = u'\u2193'
 u_left_arrow_with_tail = u'\u21a2'			# <--<
 u_sum = u'\u2211'							# sigma
@@ -78,8 +83,16 @@ u_corresponds_to = u'\u2258'
 u_infinity = u'\u221E'
 u_diameter = u'\u2300'
 u_checkmark_crossed_out = u'\u237B'
-u_box_horiz_single = u'\u2500'
+u_box_vert_left = u'\u23b8'
+u_box_vert_right = u'\u23b9'
+u_box_horiz_single = u'\u2500'				# -
+u_box_vert_light = u'\u2502'
+u_box_vert_light_4dashes = u'\u2506'
 u_box_horiz_4dashes = u'\u2508'
+u_box_T_right = u'\u251c'
+u_box_T_down = u'\u252c'
+u_box_T_up = u'\u2534'
+u_box_plus = u'\u253c'
 u_box_top_double = u'\u2550'
 u_box_top_left_double_single = u'\u2552'
 u_box_top_right_double_single = u'\u2555'
@@ -92,6 +105,9 @@ u_skull_and_crossbones = u'\u2620'
 u_frowning_face = u'\u2639'
 u_smiling_face = u'\u263a'
 u_black_heart = u'\u2665'
+u_female = u'\u2640'
+u_male = u'\u2642'
+u_male_female = u'\u26a5'
 u_checkmark_thin = u'\u2713'
 u_checkmark_thick = u'\u2714'
 u_writing_hand = u'\u270d'
@@ -112,11 +128,11 @@ _PB = 1024 * _TB
 #===========================================================================
 def handle_uncaught_exception_console(t, v, tb):
 
-	print ".========================================================"
-	print "| Unhandled exception caught !"
-	print "| Type :", t
-	print "| Value:", v
-	print "`========================================================"
+	print(".========================================================")
+	print("| Unhandled exception caught !")
+	print("| Type :", t)
+	print("| Value:", v)
+	print("`========================================================")
 	_log.critical('unhandled exception caught', exc_info = (t,v,tb))
 	sys.__excepthook__(t,v,tb)
 
@@ -131,12 +147,50 @@ def mkdir(directory=None, mode=None):
 			old_umask = os.umask(0)
 			os.makedirs(directory, mode)
 			os.umask(old_umask)
-	except OSError, e:
+	except OSError as e:
 		if (e.errno == 17) and not os.path.isdir(directory):
 			raise
 	return True
 
 #---------------------------------------------------------------------------
+def rmdir(directory):
+	#-------------------------------
+	def _on_rm_error(func, path, exc):
+		_log.error(u'error while shutil.rmtree(%s)', path, exc_info=exc)
+		return True
+	#-------------------------------
+	error_count = 0
+	try:
+		shutil.rmtree(directory, False, _on_rm_error)
+	except StandardError:
+		_log.exception('cannot shutil.rmtree(%s)', directory)
+		error_count += 1
+	return error_count
+
+#---------------------------------------------------------------------------
+def mk_sandbox_dir(prefix=None, base_dir=None):
+	if prefix is None:
+		if base_dir is None:
+			prefix = u'sandbox-'
+		else:
+			prefix = u'gm_sandbox-'
+	return tempfile.mkdtemp (
+		prefix = prefix,
+		suffix = u'',
+		dir = base_dir
+	)
+
+#---------------------------------------------------------------------------
+def parent_dir(directory):
+	return os.path.abspath(os.path.join(directory, '..'))
+
+#---------------------------------------------------------------------------
+def dirname_stem(directory):
+	# /home/user/dir/ -> dir
+	# /home/user/dir  -> dir
+	return os.path.basename(os.path.normpath(directory))		# normpath removes trailing slashes if any
+
+#---------------------------------------------------------------------------
 def dir_is_empty(directory=None):
 	return len(os.listdir(directory)) == 0
 
@@ -144,12 +198,12 @@ def dir_is_empty(directory=None):
 class gmPaths(gmBorg.cBorg):
 	"""This class provides the following paths:
 
-	.home_dir
-	.local_base_dir
-	.working_dir
+	.home_dir				user home
+	.local_base_dir			script installation dir
+	.working_dir			current dir
 	.user_config_dir
 	.system_config_dir
-	.system_app_data_dir
+	.system_app_data_dir	(not writable)
 	.tmp_dir
 	"""
 	def __init__(self, app_name=None, wx=None):
@@ -225,18 +279,13 @@ class gmPaths(gmBorg.cBorg):
 			_log.debug(u'temp dir already set')
 		except AttributeError:
 			_log.info(u'initial temp dir: %s', tempfile.gettempdir())
-			# /tmp/gnumed/
-			tmp_base = os.path.join(tempfile.gettempdir(), app_name)
-			mkdir(tmp_base, 0o777)
-			tempfile.tempdir = tmp_base
-			_log.info(u'level 1 intermediate temp dir: %s', tempfile.gettempdir())
-			# /tmp/gnumed/$USER/
-			tmp_base = os.path.join(tempfile.gettempdir(), getpass.getuser())
+			# $TMP/gnumed-$USER/
+			tmp_base = os.path.join(tempfile.gettempdir(), app_name + r'-' + getpass.getuser())
 			mkdir(tmp_base, 0o700)
 			tempfile.tempdir = tmp_base
-			_log.info(u'level 2 intermediate temp dir: %s', tempfile.gettempdir())
-			# /tmp/gnumed/$USER/gm-*/
-			self.tmp_dir = tempfile.mkdtemp(prefix = r'gm-')
+			_log.info(u'intermediate temp dir: %s', tempfile.gettempdir())
+			# $TMP/gnumed-$USER/g$UNIQUE/
+			self.tmp_dir = tempfile.mkdtemp(prefix = r'g')
 
 		self.__log_paths()
 		if wx is None:
@@ -367,6 +416,7 @@ class gmPaths(gmBorg.cBorg):
 		_log.debug('previous temp dir: %s', tempfile.gettempdir())
 		self.__tmp_dir = path
 		tempfile.tempdir = self.__tmp_dir
+		_log.debug('current temp dir: %s', tempfile.gettempdir())
 		self.__tmp_dir_already_set = True
 
 	def _get_tmp_dir(self):
@@ -377,6 +427,57 @@ class gmPaths(gmBorg.cBorg):
 #===========================================================================
 # file related tools
 #---------------------------------------------------------------------------
+def recode_file(source_file=None, target_file=None, source_encoding=u'utf8', target_encoding=None, base_dir=None, error_mode='replace'):
+	if target_encoding is None:
+		return source_file
+	if target_encoding == source_encoding:
+		return source_file
+	if target_file is None:
+		target_file = get_unique_filename (
+			prefix = u'%s-%s_%s-' % (fname_stem(source_file), source_encoding, target_encoding),
+			suffix = fname_extension(source_file, u'.txt'),
+			tmp_dir = base_dir
+		)
+
+	_log.debug('[%s] -> [%s] (%s -> %s)', source_encoding, target_encoding, source_file, target_file)
+
+	in_file = io.open(source_file, mode = 'rt', encoding = source_encoding)
+	out_file = io.open(target_file, mode = 'wt', encoding = target_encoding, errors = error_mode)
+	for line in in_file:
+		out_file.write(line)
+	out_file.close()
+	in_file.close()
+
+	return target_file
+
+#---------------------------------------------------------------------------
+def unzip_archive(archive_name, target_dir=None, remove_archive=False):
+	_log.debug('unzipping [%s] -> [%s]', archive_name, target_dir)
+	success = False
+	try:
+		with zipfile.ZipFile(archive_name) as archive:
+			archive.extractall(target_dir)
+		success = True
+	except StandardError:
+		_log.exception('cannot unzip')
+		return False
+	if remove_archive:
+		remove_file(archive_name)
+	return success
+
+#---------------------------------------------------------------------------
+def remove_file(filename, log_error=True):
+	# attempt file remove and ignore (but log) errors
+	try:
+		os.remove(filename)
+	except StandardError:
+		if log_error:
+			_log.exception('cannot os.remove(%s)', filename)
+		return False
+
+	return True
+
+#---------------------------------------------------------------------------
 def gpg_decrypt_file(filename=None, passphrase=None):
 
 	if platform.system() == 'Windows':
@@ -418,7 +519,7 @@ def file2md5(filename=None, return_hex=True):
 	blocksize = 2**10 * 128			# 128k, since md5 uses 128 byte blocks
 	_log.debug('md5(%s): <%s> byte blocks', filename, blocksize)
 
-	f = open(filename, 'rb')
+	f = io.open(filename, mode = 'rb')
 
 	md5 = hashlib.md5()
 	while True:
@@ -426,6 +527,7 @@ def file2md5(filename=None, return_hex=True):
 		if not data:
 			break
 		md5.update(data)
+	f.close()
 
 	_log.debug('md5(%s): %s', filename, md5.hexdigest())
 
@@ -498,9 +600,36 @@ def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, encoding='utf-8', **
 
 #---------------------------------------------------------------------------
 def fname_stem(filename):
+	# /home/user/dir/filename.ext -> filename
 	return os.path.splitext(os.path.basename(filename))[0]
 
 #---------------------------------------------------------------------------
+def fname_stem_with_path(filename):
+	# /home/user/dir/filename.ext -> /home/user/dir/filename
+	return os.path.splitext(filename)[0]
+
+#---------------------------------------------------------------------------
+def fname_extension(filename=None, fallback=None):
+	# /home/user/dir/filename.ext -> .ext
+	# '' or '.' -> fallback if any else ''
+	ext = os.path.splitext(filename)[1]
+	if ext.strip() not in [u'.', u'']:
+		return ext
+	if fallback is None:
+		return u''
+	return fallback
+
+#---------------------------------------------------------------------------
+def fname_dir(filename):
+	# /home/user/dir/filename.ext -> /home/user/dir
+	return os.path.split(filename)[0]
+
+#---------------------------------------------------------------------------
+def fname_from_path(filename):
+	# /home/user/dir/filename.ext -> filename.ext
+	return os.path.split(filename)[1]
+
+#---------------------------------------------------------------------------
 def get_unique_filename(prefix=None, suffix=None, tmp_dir=None):
 	"""This introduces a race condition between the file.close() and
 	actually using the filename.
@@ -516,7 +645,12 @@ def get_unique_filename(prefix=None, suffix=None, tmp_dir=None):
 			_log.warning('cannot find temporary dir [%s], using system default', tmp_dir)
 			tmp_dir = None
 
-	kwargs = {'dir': tmp_dir}
+	kwargs = {
+		'dir': tmp_dir,
+		#  make sure file gets deleted as soon as
+		# .close()d so we can safely open it again
+		'delete': True
+	}
 
 	if prefix is None:
 		kwargs['prefix'] = 'gnumed-'
@@ -555,7 +689,7 @@ def import_module_from_directory(module_path=None, module_name=None, always_remo
 
 	try:
 		module = __import__(module_name)
-	except StandardError:
+	except Exception:
 		_log.exception('cannot __import__() module [%s] from [%s]' % (module_name, module_path))
 		while module_path in sys.path:
 			sys.path.remove(module_path)
@@ -585,6 +719,7 @@ def size2str(size=0, template=u'%s'):
 	if size < _PB:
 		return template % u'%.1f TB' % (float(size) / _TB)
 	return template % u'%.1f PB' % (float(size) / _PB)
+
 #---------------------------------------------------------------------------
 def bool2subst(boolean=None, true_return=True, false_return=False, none_return=None):
 	if boolean is None:
@@ -594,6 +729,7 @@ def bool2subst(boolean=None, true_return=True, false_return=False, none_return=N
 	if not boolean:
 		return false_return
 	raise ValueError('bool2subst(): <boolean> arg must be either of True, False, None')
+
 #---------------------------------------------------------------------------
 def bool2str(boolean=None, true_str='True', false_str='False'):
 	return bool2subst (
@@ -601,6 +737,7 @@ def bool2str(boolean=None, true_str='True', false_str='False'):
 		true_return = true_str,
 		false_return = false_str
 	)
+
 #---------------------------------------------------------------------------
 def none_if(value=None, none_equivalent=None, strip_string=False):
 	"""Modelled after the SQL NULLIF function."""
@@ -613,6 +750,7 @@ def none_if(value=None, none_equivalent=None, strip_string=False):
 	if stripped == none_equivalent:
 		return None
 	return value
+
 #---------------------------------------------------------------------------
 def coalesce(initial=None, instead=None, template_initial=None, template_instead=None, none_equivalents=None, function_initial=None):
 	"""Modelled after the SQL coalesce function.
@@ -662,6 +800,7 @@ def coalesce(initial=None, instead=None, template_initial=None, template_instead
 		return template_initial % initial
 	except TypeError:
 		return template_initial
+
 #---------------------------------------------------------------------------
 def __cap_name(match_obj=None):
 	val = match_obj.group(0).lower()
@@ -673,6 +812,7 @@ def __cap_name(match_obj=None):
 		if len(val) > len(part) and val[:len(part)] == part:
 			buf[len(part)] = buf[len(part)].upper()
 	return ''.join(buf)
+
 #---------------------------------------------------------------------------
 def capitalize(text=None, mode=CAPS_NAMES):
 	"""Capitalize the first character but leave the rest alone.
@@ -695,19 +835,21 @@ def capitalize(text=None, mode=CAPS_NAMES):
 		return text.upper()
 
 	if mode == CAPS_FIRST_ONLY:
-		if len(text) == 1:
-			return text[0].upper()
+#		if len(text) == 1:
+#			return text[0].upper()
 		return text[0].upper() + text[1:].lower()
 
 	if mode == CAPS_WORDS:
-		return regex.sub(ur'(\w)(\w+)', lambda x: x.group(1).upper() + x.group(2).lower(), text)
+		#return regex.sub(ur'(\w)(\w+)', lambda x: x.group(1).upper() + x.group(2).lower(), text)
+		return regex.sub(r'(\w)(\w+)', lambda x: x.group(1).upper() + x.group(2).lower(), text)
 
 	if mode == CAPS_NAMES:
 		#return regex.sub(r'\w+', __cap_name, text)
 		return capitalize(text=text, mode=CAPS_FIRST)		# until fixed
 
-	print "ERROR: invalid capitalization mode: [%s], leaving input as is" % mode
+	print("ERROR: invalid capitalization mode: [%s], leaving input as is" % mode)
 	return text
+
 #---------------------------------------------------------------------------
 def input2decimal(initial=None):
 
@@ -730,6 +872,7 @@ def input2decimal(initial=None):
 		return True, d
 	except (TypeError, decimal.InvalidOperation):
 		return False, val
+
 #---------------------------------------------------------------------------
 def input2int(initial=None, minval=None, maxval=None):
 
@@ -756,6 +899,36 @@ def input2int(initial=None, minval=None, maxval=None):
 			return False, initial
 
 	return True, int_val
+
+#---------------------------------------------------------------------------
+def strip_prefix(text, prefix, remove_repeats=False, remove_whitespace=False):
+	if remove_repeats:
+		if remove_whitespace:
+			while text.lstrip().startswith(prefix):
+				text = text.lstrip().replace(prefix, u'', 1).lstrip()
+			return text
+		while text.startswith(prefix):
+			text = text.replace(prefix, u'', 1)
+		return text
+	if remove_whitespace:
+		return text.lstrip().replace(prefix, u'', 1).lstrip()
+	return text.replace(prefix, u'', 1)
+
+#---------------------------------------------------------------------------
+def strip_suffix(text, suffix, remove_repeats=False, remove_whitespace=False):
+	suffix_len = len(suffix)
+	if remove_repeats:
+		if remove_whitespace:
+			while text.rstrip().endswith(suffix):
+				text = text.rstrip()[:-suffix_len].rstrip()
+			return text
+		while text.endswith(suffix):
+			text = text[:-suffix_len]
+		return text
+	if remove_whitespace:
+		return text.rstrip()[:-suffix_len].rstrip()
+	return text[:-suffix_len]
+
 #---------------------------------------------------------------------------
 def strip_leading_empty_lines(lines=None, text=None, eol=u'\n', return_list=True):
 	if lines is None:
@@ -770,6 +943,7 @@ def strip_leading_empty_lines(lines=None, text=None, eol=u'\n', return_list=True
 		return lines
 
 	return eol.join(lines)
+
 #---------------------------------------------------------------------------
 def strip_trailing_empty_lines(lines=None, text=None, eol=u'\n', return_list=True):
 	if lines is None:
@@ -784,6 +958,7 @@ def strip_trailing_empty_lines(lines=None, text=None, eol=u'\n', return_list=Tru
 		return lines
 
 	return eol.join(lines)
+
 #---------------------------------------------------------------------------
 def strip_empty_lines(lines=None, text=None, eol=u'\n', return_list=True):
 	return strip_trailing_empty_lines (
@@ -792,6 +967,27 @@ def strip_empty_lines(lines=None, text=None, eol=u'\n', return_list=True):
 		eol = eol,
 		return_list = return_list
 	)
+
+#---------------------------------------------------------------------------
+def list2text(lines, initial_indent=u'', subsequent_indent=u'', eol=u'\n', strip_leading_empty_lines=True, strip_trailing_empty_lines=True, strip_trailing_whitespace=True):
+
+	if len(lines) == 0:
+		return u''
+
+	if strip_leading_empty_lines:
+		lines = strip_leading_empty_lines(lines = lines, eol = eol, return_list = True)
+
+	if strip_trailing_empty_lines:
+		lines = strip_trailing_empty_lines(lines = lines, eol = eol, return_list = True)
+
+	if strip_trailing_whitespace:
+		lines = [ l.rstrip() for l in lines ]
+
+	indented_lines = [initial_indent + lines[0]]
+	indented_lines.extend([ subsequent_indent + l for l in lines[1:] ])
+
+	return eol.join(indented_lines)
+
 #---------------------------------------------------------------------------
 def wrap(text=None, width=None, initial_indent=u'', subsequent_indent=u'', eol=u'\n'):
 	"""A word-wrap function that preserves existing line breaks
@@ -800,7 +996,7 @@ def wrap(text=None, width=None, initial_indent=u'', subsequent_indent=u'', eol=u
 	"""
 	if width is None:
 		return text
-	wrapped = initial_indent + reduce (
+	wrapped = initial_indent + functools.reduce (
 		lambda line, word, width=width: '%s%s%s' % (
 			line,
 			' \n'[(len(line) - line.rfind('\n') - 1 + len(word.split('\n',1)[0]) >= width)],
@@ -816,6 +1012,7 @@ def wrap(text=None, width=None, initial_indent=u'', subsequent_indent=u'', eol=u
 		wrapped = wrapped.replace('\n', eol)
 
 	return wrapped
+
 #---------------------------------------------------------------------------
 def unwrap(text=None, max_length=None, strip_whitespace=True, remove_empty_lines=True, line_separator = u' // '):
 
@@ -841,17 +1038,36 @@ def unwrap(text=None, max_length=None, strip_whitespace=True, remove_empty_lines
 	text = text.rstrip(line_separator)
 
 	return text
+
+#---------------------------------------------------------------------------
+def shorten_text(text=None, max_length=None):
+
+	if len(text) <= max_length:
+		return text
+
+	return text[:max_length-1] + u_ellipsis
+
 #---------------------------------------------------------------------------
 def xml_escape_string(text=None):
 	"""check for special XML characters and transform them"""
 	return xml_tools.escape(text)
+
 #---------------------------------------------------------------------------
 def tex_escape_string(text=None, replace_known_unicode=True, replace_eol=False, keep_visual_eol=False):
-	"""check for special TeX characters and transform them"""
-
-	text = text.replace(u'\\', u'\\textbackslash')
-	text = text.replace(u'^', u'\\textasciicircum')
-	text = text.replace(u'~', u'\\textasciitilde')
+	"""Check for special TeX characters and transform them.
+
+		replace_eol:
+			replaces "\n" with "\\newline"
+		keep_visual_eol:
+			replaces "\n" with "\\newline \n" such that
+			both LaTeX will know to place a line break
+			at this point as well as the visual formatting
+			is preserved in the LaTeX source (think multi-
+			row table cells)
+	"""
+	text = text.replace(u'\\', u'\\textbackslash')			# requires \usepackage{textcomp} in LaTeX source
+	text = text.replace(u'^', u'\\textasciicircum')			# requires \usepackage{textcomp} in LaTeX source
+	text = text.replace(u'~', u'\\textasciitilde')			# requires \usepackage{textcomp} in LaTeX source
 
 	text = text.replace(u'{', u'\\{')
 	text = text.replace(u'}', u'\\}')
@@ -871,11 +1087,13 @@ def tex_escape_string(text=None, replace_known_unicode=True, replace_eol=False,
 		text = text.replace(u_euro, u'\\EUR')
 
 	return text
+
 #---------------------------------------------------------------------------
 def xetex_escape_string(text=None):
 	# a web search did not reveal anything else for Xe(La)Tex
 	# as opposed to LaTeX, except true unicode chars
 	return tex_escape_string(text = text, replace_known_unicode = False)
+
 #---------------------------------------------------------------------------
 __html_escape_table = {
 	u"&": u"&",
@@ -885,21 +1103,45 @@ __html_escape_table = {
 	u"<": u"<",
 }
 
-def html_escape_string(text=None):
-	return "".join(__html_escape_table.get(char, char) for char in text)
+def html_escape_string(text=None, replace_eol=False, keep_visual_eol=False):
+	text = u''.join(__html_escape_table.get(char, char) for char in text)
+	if replace_eol:
+		if keep_visual_eol:
+			text = text.replace(u'\n', u'<br>\n')
+		else:
+			text = text.replace(u'\n', u'<br>')
+	return text
+
+#---------------------------------------------------------------------------
+def dict2json(obj):
+	return json.dumps(obj, default = json_serialize)
+
+#---------------------------------------------------------------------------
+def json_serialize(obj):
+	if isinstance(obj, pydt.datetime):
+		return obj.isoformat()
+	raise TypeError('cannot json_serialize(%s)' % type(obj))
 
 #---------------------------------------------------------------------------
 #---------------------------------------------------------------------------
 def compare_dict_likes(d1, d2, title1=None, title2=None):
 	_log.info('comparing dict-likes: %s[%s] vs %s[%s]', coalesce(title1, u'', u'"%s" '), type(d1), coalesce(title2, u'', u'"%s" '), type(d2))
-	k1 = frozenset(d1)
-	k2 = frozenset(d2)
+	try:
+		d1 = dict(d1)
+	except TypeError:
+		pass
+	try:
+		d2 = dict(d2)
+	except TypeError:
+		pass
+	keys_d1 = frozenset(d1.keys())
+	keys_d2 = frozenset(d2.keys())
 	different = False
-	if len(k1) != len(k2):
-		_log.info('different number of keys: %s vs %s', len(k1), len(k2))
+	if len(keys_d1) != len(keys_d2):
+		_log.info('different number of keys: %s vs %s', len(keys_d1), len(keys_d2))
 		different = True
-	for key in k1:
-		if key in k2:
+	for key in keys_d1:
+		if key in keys_d2:
 			if type(d1[key]) != type(d2[key]):
 				_log.info(u'%25.25s: type(dict1) = %s = >>>%s<<<' % (key, type(d1[key]), d1[key]))
 				_log.info(u'%25.25s  type(dict2) = %s = >>>%s<<<' % (u'', type(d2[key]), d2[key]))
@@ -914,8 +1156,8 @@ def compare_dict_likes(d1, d2, title1=None, title2=None):
 		else:
 			_log.info(u'%25.25s: %50.50s | <MISSING>' % (key, u'>>>%s<<<' % d1[key]))
 			different = True
-	for key in k2:
-		if key in k1:
+	for key in keys_d2:
+		if key in keys_d1:
 			continue
 		_log.info(u'%25.25s: %50.50s | %.50s' % (key, u'<MISSING>', u'>>>%s<<<' % d2[key]))
 		different = True
@@ -926,6 +1168,155 @@ def compare_dict_likes(d1, d2, title1=None, title2=None):
 	return True
 
 #---------------------------------------------------------------------------
+def format_dict_likes_comparison(d1, d2, title_left=None, title_right=None, left_margin=0, key_delim=u' || ', data_delim=u' | ', missing_string=u'=/=', difference_indicator=u'! ', ignore_diff_in_keys=None):
+
+	_log.info('comparing dict-likes: %s[%s] vs %s[%s]', coalesce(title_left, u'', u'"%s" '), type(d1), coalesce(title_right, u'', u'"%s" '), type(d2))
+	append_type = False
+	if None not in [title_left, title_right]:
+		append_type = True
+		type_left = type(d1)
+		type_right = type(d2)
+	if title_left is None:
+		title_left = u'%s' % type_left
+	if title_right is None:
+		title_right = u'%s' % type_right
+
+	try: d1 = dict(d1)
+	except TypeError: pass
+	try: d2 = dict(d2)
+	except TypeError: pass
+	keys_d1 = d1.keys()
+	keys_d2 = d2.keys()
+	data = {}
+	for key in keys_d1:
+		data[key] = [d1[key], u' ']
+		if key in d2:
+			data[key][1] = d2[key]
+	for key in keys_d2:
+		if key in keys_d1:
+			continue
+		data[key] = [u' ', d2[key]]
+	max1 = max([ len(u'%s' % k) for k in keys_d1 ])
+	max2 = max([ len(u'%s' % k) for k in keys_d2 ])
+	max_len = max(max1, max2, len(_('<type>')))
+	max_key_len_str = u'%' + u'%s.%s' % (max_len, max_len) + u's'
+	max1 = max([ len(u'%s' % d1[k]) for k in keys_d1 ])
+	max2 = max([ len(u'%s' % d2[k]) for k in keys_d2 ])
+	max_data_len = min(max(max1, max2), 100)
+	max_data_len_str = u'%' + u'%s.%s' % (max_data_len, max_data_len) + u's'
+	diff_indicator_len_str = u'%' + u'%s.%s' % (len(difference_indicator), len(difference_indicator)) + u's'
+	line_template = (u' ' * left_margin) + diff_indicator_len_str + max_key_len_str + key_delim + max_data_len_str + data_delim + u'%s'
+
+	lines = []
+	# debugging:
+	#lines.append(u'                                        (40 regular spaces)')
+	#lines.append((u' ' * 40) + u"(u' ' * 40)")
+	#lines.append((u'%40.40s' % u'') + u"(u'%40.40s' % u'')")
+	#lines.append((u'%40.40s' % u' ') + u"(u'%40.40s' % u' ')")
+	#lines.append((u'%40.40s' % u'.') + u"(u'%40.40s' % u'.')")
+	#lines.append(line_template)
+	lines.append(line_template % (u'', u'', title_left, title_right))
+	if append_type:
+		lines.append(line_template % (u'', _('<type>'), type_left, type_right))
+
+	if ignore_diff_in_keys is None:
+		ignore_diff_in_keys = []
+
+	for key in keys_d1:
+		append_type = False
+		txt_left_col = u'%s' % d1[key]
+		try:
+			txt_right_col = u'%s' % d2[key]
+			if type(d1[key]) != type(d2[key]):
+				append_type = True
+		except KeyError:
+			txt_right_col = missing_string
+		lines.append(line_template % (
+			bool2subst (
+				((txt_left_col == txt_right_col) or (key in ignore_diff_in_keys)),
+				u'',
+				difference_indicator
+			),
+			key,
+			shorten_text(txt_left_col, max_data_len),
+			shorten_text(txt_right_col, max_data_len)
+		))
+		if append_type:
+			lines.append(line_template % (
+				u'',
+				_('<type>'),
+				shorten_text(u'%s' % type(d1[key]), max_data_len),
+				shorten_text(u'%s' % type(d2[key]), max_data_len)
+			))
+
+	for key in keys_d2:
+		if key in keys_d1:
+			continue
+		lines.append(line_template % (
+			bool2subst((key in ignore_diff_in_keys), u'', difference_indicator),
+			key,
+			shorten_text(missing_string, max_data_len),
+			shorten_text(u'%s' % d2[key], max_data_len)
+		))
+
+	return lines
+
+#---------------------------------------------------------------------------
+def format_dict_like(d, relevant_keys=None, template=None, missing_key_template=u'<[%(key)s] MISSING>', left_margin=0, tabular=False, value_delimiters=(u'>>>', u'<<<'), eol=u'\n'):
+	if template is not None:
+		# all keys in template better exist in d
+		try:
+			return template % d
+		except KeyError:
+			# or else
+			_log.exception('template contains %%()s key(s) which do not exist in dict')
+		# try to extend dict <d> to contain all required keys,
+		# for that to work <relevant_keys> better list all
+		# keys used in <template>
+		if relevant_keys is not None:
+			for key in relevant_keys:
+				try:
+					d[key]
+				except KeyError:
+					d[key] = missing_key_template % {u'key': key}
+			return template % d
+
+	if relevant_keys is None:
+		relevant_keys = d.keys()
+	lines = []
+	if value_delimiters is None:
+		delim_left = u''
+		delim_right = u''
+	else:
+		delim_left, delim_right = value_delimiters
+	if tabular:
+		max_len = max([ len(i) for i in relevant_keys ])
+		max_len_str = u'%s.%s' % (max_len, max_len)
+		line_template = (u' ' * left_margin) + u'%' + max_len_str + ('s: %s%%s%s' % (delim_left, delim_right))
+	else:
+		line_template = (u' ' * left_margin) + u'%%s: %s%%s%s' % (delim_left, delim_right)
+	for key in relevant_keys:
+		try:
+			lines.append(line_template % (key, d[key]))
+		except KeyError:
+			pass
+	if eol is None:
+		return lines
+	return eol.join(lines)
+
+#---------------------------------------------------------------------------
+def normalize_dict_like(d, required_keys, missing_key_template=u'<[%(key)s] MISSING>'):
+	for key in required_keys:
+		try:
+			d[key]
+		except KeyError:
+			if missing_key_template is None:
+				d[key] = None
+			else:
+				d[key] = missing_key_template % {'key': key}
+	return d
+
+#---------------------------------------------------------------------------
 #---------------------------------------------------------------------------
 def prompted_input(prompt=None, default=None):
 	"""Obtains entry from standard input.
@@ -989,7 +1380,7 @@ def get_icon(wx=None):
 
 	if found_as is None:
 		_log.warning('no icon file found, falling back to builtin (ugly) icon')
-		icon_bmp_data = wx.BitmapFromXPMData(cPickle.loads(zlib.decompress(__icon_serpent)))
+		icon_bmp_data = wx.BitmapFromXPMData(pickle.loads(zlib.decompress(__icon_serpent)))
 		icon.CopyFromBitmap(icon_bmp_data)
 	else:
 		_log.debug('icon found in [%s]', found_as)
@@ -1011,6 +1402,12 @@ if __name__ == '__main__':
 	if sys.argv[1] != 'test':
 		sys.exit()
 
+	# for testing:
+	logging.basicConfig(level = logging.DEBUG)
+	from Gnumed.pycommon import gmI18N
+	gmI18N.activate_locale()
+	gmI18N.install_domain()
+
 	#-----------------------------------------------------------------------
 	def test_input2decimal():
 
@@ -1061,27 +1458,27 @@ if __name__ == '__main__':
 					if result == test[2]:
 						continue
 					else:
-						print "ERROR (conversion result wrong): >%s<, expected >%s<, got >%s<" % (test[0], test[2], result)
+						print("ERROR (conversion result wrong): >%s<, expected >%s<, got >%s<" % (test[0], test[2], result))
 				else:
-					print "ERROR (conversion worked but was expected to fail): >%s<, got >%s<" % (test[0], result)
+					print("ERROR (conversion worked but was expected to fail): >%s<, got >%s<" % (test[0], result))
 			else:
 				if not expected2work:
 					continue
 				else:
-					print "ERROR (conversion failed but was expected to work): >%s<, expected >%s<" % (test[0], test[2])
+					print("ERROR (conversion failed but was expected to work): >%s<, expected >%s<" % (test[0], test[2]))
 	#-----------------------------------------------------------------------
 	def test_input2int():
-		print input2int(0)
-		print input2int('0')
-		print input2int(u'0', 0, 0)
+		print(input2int(0))
+		print(input2int('0'))
+		print(input2int(u'0', 0, 0))
 	#-----------------------------------------------------------------------
 	def test_coalesce():
 
 		import datetime as dt
-		print coalesce(initial = dt.datetime.now(), template_initial = u'-- %s --', function_initial = ('strftime', u'%Y-%m-%d'))
+		print(coalesce(initial = dt.datetime.now(), template_initial = u'-- %s --', function_initial = ('strftime', u'%Y-%m-%d')))
 
-		print 'testing coalesce()'
-		print "------------------"
+		print('testing coalesce()')
+		print("------------------")
 		tests = [
 			[None, 'something other than <None>', None, None, 'something other than <None>'],
 			['Captain', 'Mr.', '%s.'[:4], 'Mr.', 'Capt.'],
@@ -1099,20 +1496,20 @@ if __name__ == '__main__':
 				template_instead = test[3]
 			)
 			if result != test[4]:
-				print "ERROR"
-				print "coalesce: (%s, %s, %s, %s)" % (test[0], test[1], test[2], test[3])
-				print "expected:", test[4]
-				print "received:", result
+				print("ERROR")
+				print("coalesce: (%s, %s, %s, %s)" % (test[0], test[1], test[2], test[3]))
+				print("expected:", test[4])
+				print("received:", result)
 				passed = False
 
 		if passed:
-			print "passed"
+			print("passed")
 		else:
-			print "failed"
+			print("failed")
 		return passed
 	#-----------------------------------------------------------------------
 	def test_capitalize():
-		print 'testing capitalize() ...'
+		print('testing capitalize() ...')
 		success = True
 		pairs = [
 			# [original, expected result, CAPS mode]
@@ -1136,45 +1533,45 @@ if __name__ == '__main__':
 			result = capitalize(pair[0], pair[2])
 			if result != pair[1]:
 				success = False
-				print 'ERROR (caps mode %s): "%s" -> "%s", expected "%s"' % (pair[2], pair[0], result, pair[1])
+				print('ERROR (caps mode %s): "%s" -> "%s", expected "%s"' % (pair[2], pair[0], result, pair[1]))
 
 		if success:
-			print "... SUCCESS"
+			print("... SUCCESS")
 
 		return success
 	#-----------------------------------------------------------------------
 	def test_import_module():
-		print "testing import_module_from_directory()"
+		print("testing import_module_from_directory()")
 		path = sys.argv[1]
 		name = sys.argv[2]
 		try:
 			mod = import_module_from_directory(module_path = path, module_name = name)
 		except:
-			print "module import failed, see log"
+			print("module import failed, see log")
 			return False
 
-		print "module import succeeded", mod
-		print dir(mod)
+		print("module import succeeded", mod)
+		print(dir(mod))
 		return True
 	#-----------------------------------------------------------------------
 	def test_mkdir():
-		print "testing mkdir()"
+		print("testing mkdir(%s)" % sys.argv[1])
 		mkdir(sys.argv[1])
 	#-----------------------------------------------------------------------
 	def test_gmPaths():
-		print "testing gmPaths()"
-		print "-----------------"
+		print("testing gmPaths()")
+		print("-----------------")
 		paths = gmPaths(wx=None, app_name='gnumed')
-		print "user     config dir:", paths.user_config_dir
-		print "system   config dir:", paths.system_config_dir
-		print "local      base dir:", paths.local_base_dir
-		print "system app data dir:", paths.system_app_data_dir
-		print "working directory  :", paths.working_dir
-		print "temp directory     :", paths.tmp_dir
+		print("user     config dir:", paths.user_config_dir)
+		print("system   config dir:", paths.system_config_dir)
+		print("local      base dir:", paths.local_base_dir)
+		print("system app data dir:", paths.system_app_data_dir)
+		print("working directory  :", paths.working_dir)
+		print("temp directory     :", paths.tmp_dir)
 	#-----------------------------------------------------------------------
 	def test_none_if():
-		print "testing none_if()"
-		print "-----------------"
+		print("testing none_if()")
+		print("-----------------")
 		tests = [
 			[None, None, None],
 			['a', 'a', None],
@@ -1189,7 +1586,7 @@ if __name__ == '__main__':
 
 		for test in tests:
 			if none_if(value = test[0], none_equivalent = test[1]) != test[2]:
-				print 'ERROR: none_if(%s) returned [%s], expected [%s]' % (test[0], none_if(test[0], test[1]), test[2])
+				print('ERROR: none_if(%s) returned [%s], expected [%s]' % (test[0], none_if(test[0], test[1]), test[2]))
 
 		return True
 	#-----------------------------------------------------------------------
@@ -1200,29 +1597,29 @@ if __name__ == '__main__':
 		]
 		for test in tests:
 			if bool2str(test[0], test[1], test[2]) != test[3]:
-				print 'ERROR: bool2str(%s, %s, %s) returned [%s], expected [%s]' % (test[0], test[1], test[2], bool2str(test[0], test[1], test[2]), test[3])
+				print('ERROR: bool2str(%s, %s, %s) returned [%s], expected [%s]' % (test[0], test[1], test[2], bool2str(test[0], test[1], test[2]), test[3]))
 
 		return True
 	#-----------------------------------------------------------------------
 	def test_bool2subst():
 
-		print bool2subst(True, 'True', 'False', 'is None')
-		print bool2subst(False, 'True', 'False', 'is None')
-		print bool2subst(None, 'True', 'False', 'is None')
+		print(bool2subst(True, 'True', 'False', 'is None'))
+		print(bool2subst(False, 'True', 'False', 'is None'))
+		print(bool2subst(None, 'True', 'False', 'is None'))
 	#-----------------------------------------------------------------------
 	def test_get_unique_filename():
-		print get_unique_filename()
-		print get_unique_filename(prefix='test-')
-		print get_unique_filename(suffix='tst')
-		print get_unique_filename(prefix='test-', suffix='tst')
-		print get_unique_filename(tmp_dir='/home/ncq/Archiv/')
+		print(get_unique_filename())
+		print(get_unique_filename(prefix='test-'))
+		print(get_unique_filename(suffix='tst'))
+		print(get_unique_filename(prefix='test-', suffix='tst'))
+		print(get_unique_filename(tmp_dir='/home/ncq/Archiv/'))
 	#-----------------------------------------------------------------------
 	def test_size2str():
-		print "testing size2str()"
-		print "------------------"
+		print("testing size2str()")
+		print("------------------")
 		tests = [0, 1, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000, 1000000000000, 10000000000000]
 		for test in tests:
-			print size2str(test)
+			print(size2str(test))
 	#-----------------------------------------------------------------------
 	def test_unwrap():
 
@@ -1234,64 +1631,64 @@ second line\n
 6th
 
 """
-		print unwrap(text = test, max_length = 25)
+		print(unwrap(text = test, max_length = 25))
 	#-----------------------------------------------------------------------
 	def test_wrap():
 		test = 'line 1\nline 2\nline 3'
 
-		print "wrap 5-6-7 initial 0, subsequent 0"
-		print wrap(test, 5)
-		print
-		print wrap(test, 6)
-		print
-		print wrap(test, 7)
-		print "-------"
+		print("wrap 5-6-7 initial 0, subsequent 0")
+		print(wrap(test, 5))
+		print()
+		print(wrap(test, 6))
+		print()
+		print(wrap(test, 7))
+		print("-------")
 		raw_input()
-		print "wrap 5 initial 1-1-3, subsequent 1-3-1"
-		print wrap(test, 5, u' ', u' ')
-		print
-		print wrap(test, 5, u' ', u'   ')
-		print
-		print wrap(test, 5, u'   ', u' ')
-		print "-------"
+		print("wrap 5 initial 1-1-3, subsequent 1-3-1")
+		print(wrap(test, 5, u' ', u' '))
+		print()
+		print(wrap(test, 5, u' ', u'   '))
+		print()
+		print(wrap(test, 5, u'   ', u' '))
+		print("-------")
 		raw_input()
-		print "wrap 6 initial 1-1-3, subsequent 1-3-1"
-		print wrap(test, 6, u' ', u' ')
-		print
-		print wrap(test, 6, u' ', u'   ')
-		print
-		print wrap(test, 6, u'   ', u' ')
-		print "-------"
+		print("wrap 6 initial 1-1-3, subsequent 1-3-1")
+		print(wrap(test, 6, u' ', u' '))
+		print()
+		print(wrap(test, 6, u' ', u'   '))
+		print()
+		print(wrap(test, 6, u'   ', u' '))
+		print("-------")
 		raw_input()
-		print "wrap 7 initial 1-1-3, subsequent 1-3-1"
-		print wrap(test, 7, u' ', u' ')
-		print
-		print wrap(test, 7, u' ', u'   ')
-		print
-		print wrap(test, 7, u'   ', u' ')
+		print("wrap 7 initial 1-1-3, subsequent 1-3-1")
+		print(wrap(test, 7, u' ', u' '))
+		print()
+		print(wrap(test, 7, u' ', u'   '))
+		print()
+		print(wrap(test, 7, u'   ', u' '))
 	#-----------------------------------------------------------------------
 	def test_md5():
-		print 'md5 %s: %s' % (sys.argv[2], file2md5(sys.argv[2]))
-		print 'chunked md5 %s: %s' % (sys.argv[2], file2chunked_md5(sys.argv[2]))
+		print('md5 %s: %s' % (sys.argv[2], file2md5(sys.argv[2])))
+		print('chunked md5 %s: %s' % (sys.argv[2], file2chunked_md5(sys.argv[2])))
 	#-----------------------------------------------------------------------
 	def test_unicode():
-		print u_link_symbol * 10
+		print(u_link_symbol * 10)
 	#-----------------------------------------------------------------------
 	def test_xml_escape():
-		print xml_escape_string(u'<')
-		print xml_escape_string(u'>')
-		print xml_escape_string(u'&')
+		print(xml_escape_string(u'<'))
+		print(xml_escape_string(u'>'))
+		print(xml_escape_string(u'&'))
 	#-----------------------------------------------------------------------
 	def test_tex_escape():
 		tests = [u'\\', u'^', u'~', u'{', u'}', u'%',  u'&', u'#', u'$', u'_', u_euro, u'abc\ndef\n\n1234']
 		tests.append(u'  '.join(tests))
 		for test in tests:
-			print u'%s:' % test, tex_escape_string(test)
+			print(u'%s:' % test, tex_escape_string(test))
 	#-----------------------------------------------------------------------
 	def test_gpg_decrypt():
 		fname = gpg_decrypt_file(filename = sys.argv[2], passphrase = sys.argv[3])
 		if fname is not None:
-			print "successfully decrypted:", fname
+			print("successfully decrypted:", fname)
 	#-----------------------------------------------------------------------
 	def test_strip_trailing_empty_lines():
 		tests = [
@@ -1299,19 +1696,19 @@ second line\n
 			u'one line\nwith embedded\nline\nbreaks\n   '
 		]
 		for test in tests:
-			print 'as list:'
-			print strip_trailing_empty_lines(text = test, eol=u'\n', return_list = True)
-			print 'as string:'
-			print u'>>>%s<<<' % strip_trailing_empty_lines(text = test, eol=u'\n', return_list = False)
+			print('as list:')
+			print(strip_trailing_empty_lines(text = test, eol=u'\n', return_list = True))
+			print('as string:')
+			print(u'>>>%s<<<' % strip_trailing_empty_lines(text = test, eol=u'\n', return_list = False))
 		tests = [
 			['list', 'without', 'empty', 'trailing', 'lines'],
 			['list', 'with', 'empty', 'trailing', 'lines', '', '  ', '']
 		]
 		for test in tests:
-			print 'as list:'
-			print strip_trailing_empty_lines(lines = test, eol = u'\n', return_list = True)
-			print 'as string:'
-			print strip_trailing_empty_lines(lines = test, eol = u'\n', return_list = False)
+			print('as list:')
+			print(strip_trailing_empty_lines(lines = test, eol = u'\n', return_list = True))
+			print('as string:')
+			print(strip_trailing_empty_lines(lines = test, eol = u'\n', return_list = False))
 	#-----------------------------------------------------------------------
 	def test_fname_stem():
 		tests = [
@@ -1326,10 +1723,10 @@ second line\n
 			r'tmp.txt'
 		]
 		for t in tests:
-			print "[%s] -> [%s]" % (t, fname_stem(t))
+			print("[%s] -> [%s]" % (t, fname_stem(t)))
 	#-----------------------------------------------------------------------
 	def test_dir_is_empty():
-		print sys.argv[2], 'empty:', dir_is_empty(sys.argv[2])
+		print(sys.argv[2], 'empty:', dir_is_empty(sys.argv[2]))
 	#-----------------------------------------------------------------------
 	def test_compare_dicts():
 		d1 = {}
@@ -1351,6 +1748,66 @@ second line\n
 		d2 = {1: 1, 2: 2}
 
 		compare_dict_likes(d1, d2, 'same1', 'same2')
+		print(format_dict_like(d1))
+		print(format_dict_like(d2))
+
+	#-----------------------------------------------------------------------
+	def test_format_compare_dicts():
+		d1 = {}
+		d2 = {}
+		d1[1] = 1
+		d1[2] = 2
+		d1[3] = 3
+		# 4
+		d1[5] = 5
+
+		d2[1] = 1
+		d2[2] = None
+		# 3
+		d2[4] = 4
+
+		print(u'\n'.join(format_dict_likes_comparison(d1, d2, u'd1', u'd2')))
+
+		d1 = {1: 1, 2: 2}
+		d2 = {1: 1, 2: 2}
+
+		print(u'\n'.join(format_dict_likes_comparison(d1, d2, u'd1', u'd2')))
+
+	#-----------------------------------------------------------------------
+	def test_rm_dir():
+		rmdir('cx:\windows\system3__2xxxxxxxxxxxxx')
+	#-----------------------------------------------------------------------
+	def test_strip_prefix():
+		tests = [
+			(u'', u'', u''),
+			(u'a', u'a', u''),
+			(u'\.br\MICROCYTES+1\.br\SPHEROCYTES       present\.br\POLYCHROMASIAmoderate\.br\\', u'\.br\\', u'MICROCYTES+1\.br\SPHEROCYTES       present\.br\POLYCHROMASIAmoderate\.br\\')
+		]
+		for test in tests:
+			text, prefix, expect = test
+			result = strip_prefix(text, prefix)
+			if result == expect:
+				continue
+			print('test failed:', test)
+			print('result:', result)
+	#-----------------------------------------------------------------------
+	def test_shorten_text():
+		tst = [
+			('123', 1),
+			('123', 2),
+			('123', 3),
+			('123', 4),
+			('', 1),
+			('1', 1),
+			('12', 1),
+			('', 2),
+			('1', 2),
+			('12', 2),
+			('123', 2)
+		]
+		for txt, lng in tst:
+			print(u'max', lng, 'of', txt, '=', shorten_text(txt, lng))
+
 	#-----------------------------------------------------------------------
 	#test_coalesce()
 	#test_capitalize()
@@ -1366,7 +1823,7 @@ second line\n
 	#test_input2decimal()
 	#test_input2int()
 	#test_unwrap()
-	test_md5()
+	#test_md5()
 	#test_unicode()
 	#test_xml_escape()
 	#test_gpg_decrypt()
@@ -1375,5 +1832,9 @@ second line\n
 	#test_tex_escape()
 	#test_dir_is_empty()
 	#test_compare_dicts()
+	#test_rm_dir()
+	#test_strip_prefix()
+	#test_shorten_text()
+	test_format_compare_dicts()
 
 #===========================================================================
diff --git a/server/sql/country.specific/au/gmDemographics.au.sql b/server/sql/country.specific/au/gmDemographics.au.sql
index fc2456f..bfabbbd 100644
--- a/server/sql/country.specific/au/gmDemographics.au.sql
+++ b/server/sql/country.specific/au/gmDemographics.au.sql
@@ -1,20 +1,12 @@
 -- Project: GNUmed
 -- ===================================================================
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/country.specific/au/gmDemographics.au.sql,v $
--- $Revision: 1.15 $
 -- license: GPL v2 or later
 -- authors: Ian Haywood, Horst Herb, Karsten Hilbert, Richard Terry
 
--- demographics tables specific f�r Australia
-
 -- ===================================================================
 -- force terminate + exit(3) on errors if non-interactive
 \set ON_ERROR_STOP 1
 
-reset client_encoding;
--- ===================================================================
-
-
 -- ===================================================================
 
 -- seeding for occupations list
@@ -92,60 +84,3 @@ INSERT INTO dem.enum_ext_id_types (name, issuer, context) VALUES ('ur_no', 'dbf
 -- do simple schema revision tracking
 delete from gm_schema_revision where filename='$RCSfile: gmDemographics.au.sql,v $';
 INSERT INTO gm_schema_revision (filename, version) VALUES('$RCSfile: gmDemographics.au.sql,v $', '$Revision: 1.15 $');
-
--- ===================================================================
--- $Log: gmDemographics.au.sql,v $
--- Revision 1.15  2006-07-04 14:18:04  ncq
--- - add two ext id types
---
--- Revision 1.14  2006/01/06 10:12:02  ncq
--- - add missing grants
--- - add_table_for_audit() now in "audit" schema
--- - demographics now in "dem" schema
--- - add view v_inds4vaccine
--- - move staff_role from clinical into demographics
--- - put add_coded_term() into "clin" schema
--- - put German things into "de_de" schema
---
--- Revision 1.13  2005/09/19 16:38:51  ncq
--- - adjust to removed is_core from gm_schema_revision
---
--- Revision 1.12  2005/07/14 21:31:42  ncq
--- - partially use improved schema revision tracking
---
--- Revision 1.11  2004/06/17 11:31:07  ihaywood
--- A new form template for the new form markup.
--- Basically @...@ where any Python expression can exist
--- between the "@" signs. The other form templates will be changed over eventually.
---
--- Revision 1.10  2004/03/04 19:41:52  ncq
--- - whitespace, comment
---
--- Revision 1.9  2004/03/04 10:48:06  ncq
--- - don't hardcode primary keys for ext_id_types
---
--- Revision 1.8  2004/03/03 23:50:58  ihaywood
--- external ID types for Australia.
---
--- Revision 1.7  2004/03/02 10:22:41  ihaywood
--- support for martial status and occupations
--- .conf files now use host autoprobing
---
--- Revision 1.6  2004/01/05 00:59:14  ncq
--- - remove ourselves from schema revision table
---
--- Revision 1.5  2003/12/29 15:49:46  uid66147
--- - reset client_encoding
---
--- Revision 1.4  2003/10/01 16:12:01  ncq
--- - AU -> au
---
--- Revision 1.3  2003/10/01 15:45:20  ncq
--- - use add_table_for_audit() instead of inheriting from audit_mark
---
--- Revision 1.2  2003/08/17 00:27:33  ncq
--- - log_ tables removed, now auto-created
---
--- Revision 1.1  2003/08/05 09:24:51  ncq
--- - first checkin
---
diff --git a/server/sql/country.specific/ca/gmDemographics-Data.ca.sql b/server/sql/country.specific/ca/gmDemographics-Data.ca.sql
index 1bc7f1a..579e7bb 100644
--- a/server/sql/country.specific/ca/gmDemographics-Data.ca.sql
+++ b/server/sql/country.specific/ca/gmDemographics-Data.ca.sql
@@ -8,8 +8,6 @@
 --                update 2001; update 2002
 -- Code source:   Canadian Postal Guide
 -- ===================================================================
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/country.specific/ca/gmDemographics-Data.ca.sql,v $
--- $Id: gmDemographics-Data.ca.sql,v 1.5 2006-01-09 13:46:19 ncq Exp $
 -- author: Karsten Hilbert
 -- license: GPL v2 or later
 
@@ -17,7 +15,6 @@
 -- force terminate + exit(3) on errors if non-interactive
 \set ON_ERROR_STOP 1
 
-set client_encoding to 'LATIN1';
 -- ===================================================================
 insert into dem.state (code, country, name) values ('AB', 'CA', i18n.i18n('Alberta'));
 insert into dem.state (code, country, name) values ('BC', 'CA', i18n.i18n('British Columbia'));
@@ -36,9 +33,9 @@ insert into dem.state (code, country, name) values ('YT', 'CA', i18n.i18n('Yukon
 select i18n.upd_tx('fr_CA', 'British Columbia', 'Colombie-Britannique');
 select i18n.upd_tx('fr_CA', 'New Brunswick', 'Nouveau-Brunswick');
 select i18n.upd_tx('fr_CA', 'Newfoundland and Labrador', 'Terre-Neuve-et-Labrador');
-select i18n.upd_tx('fr_CA', 'Nova Scotia', 'Nouvelle-�cosse');
-select i18n.upd_tx('fr_CA', 'Prince Edward Island', '�le-du-Prince-�douard');
-select i18n.upd_tx('fr_CA', 'Quebec', 'Qu�bec');
+select i18n.upd_tx('fr_CA', 'Nova Scotia', 'Nouvelle-Écosse');
+select i18n.upd_tx('fr_CA', 'Prince Edward Island', 'Île-du-Prince-Édouard');
+select i18n.upd_tx('fr_CA', 'Quebec', 'Québec');
 select i18n.upd_tx('fr_CA', 'Northwest Territories', 'Territoires du Nord-Ouest');
 select i18n.upd_tx('fr_CA', 'Yukon Territory', 'Territoire du Yukon');
 
@@ -48,27 +45,3 @@ select dem.gm_upd_default_states();
 -- do simple revision tracking
 delete from gm_schema_revision where filename = '$RCSfile: gmDemographics-Data.ca.sql,v $';
 INSERT INTO gm_schema_revision (filename, version) VALUES('$RCSfile: gmDemographics-Data.ca.sql,v $', '$Revision: 1.5 $');
-
--- ===================================================================
--- $Log: gmDemographics-Data.ca.sql,v $
--- Revision 1.5  2006-01-09 13:46:19  ncq
--- - adjust to schema "i18n" qualification
---
--- Revision 1.4  2006/01/06 10:12:02  ncq
--- - add missing grants
--- - add_table_for_audit() now in "audit" schema
--- - demographics now in "dem" schema
--- - add view v_inds4vaccine
--- - move staff_role from clinical into demographics
--- - put add_coded_term() into "clin" schema
--- - put German things into "de_de" schema
---
--- Revision 1.3  2005/09/19 16:25:41  ncq
--- - update default states
---
--- Revision 1.2  2005/07/14 21:31:43  ncq
--- - partially use improved schema revision tracking
---
--- Revision 1.1  2005/06/07 21:58:58  ncq
--- - Canadian provinces in English and French :-)
---
diff --git a/server/sql/country.specific/de/Impfplan-FSME.sql b/server/sql/country.specific/de/Impfplan-FSME.sql
index 6cf5f19..2ea6074 100644
--- a/server/sql/country.specific/de/Impfplan-FSME.sql
+++ b/server/sql/country.specific/de/Impfplan-FSME.sql
@@ -5,8 +5,6 @@
 
 -- author: Karsten Hilbert <Karsten.Hilbert at gmx.net>
 -- license: GPL v2 or later
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/country.specific/de/Impfplan-FSME.sql,v $
--- $Revision: 1.6 $
 -- =============================================
 -- force terminate + exit(3) on errors if non-interactive
 \set ON_ERROR_STOP 1
@@ -38,7 +36,7 @@ values (
 	'13 months'::interval,
 	'12 years'::interval,
 	'1 month'::interval,
-	'fr�hestm�gliche Serokonversion in 14 Tagen, 1-3 Monate nach 1.Impfung'
+	'frühestmögliche Serokonversion in 14 Tagen, 1-3 Monate nach 1.Impfung'
 );
 
 insert into clin.vaccination_definition
@@ -79,7 +77,7 @@ values (
 	'12 months 7 days'::interval,
 	'12 years'::interval,
 	'7 days'::interval,
-	'am Tag 7 nach 1.Impfung, fr�hestm�gliche Serokonversion in 14 Tagen'
+	'am Tag 7 nach 1.Impfung, frühestmögliche Serokonversion in 14 Tagen'
 );
 
 insert into clin.vaccination_definition
@@ -97,24 +95,3 @@ values (
 -- do simple revision tracking
 delete from gm_schema_revision where filename = '$RCSfile: Impfplan-FSME.sql,v $';
 INSERT INTO gm_schema_revision (filename, version) VALUES('$RCSfile: Impfplan-FSME.sql,v $', '$Revision: 1.6 $');
-
--- =============================================
--- $Log: Impfplan-FSME.sql,v $
--- Revision 1.6  2006-03-04 16:24:39  ncq
--- - adjust to table name changes
---
--- Revision 1.5  2005/11/25 15:07:28  ncq
--- - create schema "clin" and move all things clinical into it
---
--- Revision 1.4  2005/09/19 16:38:51  ncq
--- - adjust to removed is_core from gm_schema_revision
---
--- Revision 1.3  2005/07/14 21:31:43  ncq
--- - partially use improved schema revision tracking
---
--- Revision 1.2  2004/04/14 13:33:04  ncq
--- - need to adjust min_interval for seq_no=1 after tightening interval checks
---
--- Revision 1.1  2004/03/27 18:38:55  ncq
--- - FSME schedule
---
diff --git a/server/sql/country.specific/de/Impfplan-Influenza.sql b/server/sql/country.specific/de/Impfplan-Influenza.sql
index af04149..b27895c 100644
--- a/server/sql/country.specific/de/Impfplan-Influenza.sql
+++ b/server/sql/country.specific/de/Impfplan-Influenza.sql
@@ -5,8 +5,6 @@
 
 -- author: Karsten Hilbert <Karsten.Hilbert at gmx.net>
 -- license: GPL v2 or later
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/country.specific/de/Impfplan-Influenza.sql,v $
--- $Revision: 1.9 $
 -- =============================================
 -- force terminate + exit(3) on errors if non-interactive
 \set ON_ERROR_STOP 1
@@ -33,46 +31,3 @@ values (
 -- =============================================
 -- do simple revision tracking
 select log_script_insertion('$RCSfile: Impfplan-Influenza.sql,v $', '$Revision: 1.9 $');
-
--- =============================================
--- $Log: Impfplan-Influenza.sql,v $
--- Revision 1.9  2006-03-04 16:24:39  ncq
--- - adjust to table name changes
---
--- Revision 1.8  2005/11/25 15:07:28  ncq
--- - create schema "clin" and move all things clinical into it
---
--- Revision 1.7  2005/09/19 16:38:51  ncq
--- - adjust to removed is_core from gm_schema_revision
---
--- Revision 1.6  2005/07/14 21:31:43  ncq
--- - partially use improved schema revision tracking
---
--- Revision 1.5  2004/04/14 13:33:04  ncq
--- - need to adjust min_interval for seq_no=1 after tightening interval checks
---
--- Revision 1.4  2004/03/18 09:58:50  ncq
--- - removed is_booster reference where is false
---
--- Revision 1.3  2003/12/29 15:57:58  uid66147
--- - name cleanup
---
--- Revision 1.2  2003/12/01 22:13:57  ncq
--- - wording change
---
--- Revision 1.1  2003/11/30 12:37:39  ncq
--- - InfectoVac Flu 2003/4
---
--- Revision 1.4  2003/11/28 08:15:57  ncq
--- - PG 7.1/pyPgSQL/mxDateTime returns 0 for interval=1 month,
---   it works with interval=4 weeks, though, so use that
---
--- Revision 1.3  2003/11/26 23:54:51  ncq
--- - lnk_vaccdef2reg does not exist anymore
---
--- Revision 1.2  2003/11/26 00:12:19  ncq
--- - fix fk_recommended_by value
---
--- Revision 1.1  2003/11/26 00:10:45  ncq
--- - Prevenar
---
diff --git a/server/sql/country.specific/de/Impfplan-Prevenar.sql b/server/sql/country.specific/de/Impfplan-Prevenar.sql
index 924c5a8..074dec7 100644
--- a/server/sql/country.specific/de/Impfplan-Prevenar.sql
+++ b/server/sql/country.specific/de/Impfplan-Prevenar.sql
@@ -1,12 +1,10 @@
 -- Projekt GNUmed
--- Impfkalender der Firma Wyeth Lederle f�r Prevenar (Pneumokokken)
+-- Impfkalender der Firma Wyeth Lederle für Prevenar (Pneumokokken)
 
 -- Quellen: Beipackzettel
 
 -- author: Karsten Hilbert <Karsten.Hilbert at gmx.net>
 -- license: GPL v2 or later
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/country.specific/de/Impfplan-Prevenar.sql,v $
--- $Revision: 1.12 $
 -- =============================================
 -- force terminate + exit(3) on errors if non-interactive
 \set ON_ERROR_STOP 1
@@ -153,43 +151,3 @@ values (
 -- do simple revision tracking
 delete from gm_schema_revision where filename like '%Impfplan-Prevenar%';
 INSERT INTO gm_schema_revision (filename, version) VALUES('$RCSfile: Impfplan-Prevenar.sql,v $', '$Revision: 1.12 $');
-
--- =============================================
--- $Log: Impfplan-Prevenar.sql,v $
--- Revision 1.12  2006-03-04 16:24:39  ncq
--- - adjust to table name changes
---
--- Revision 1.11  2005/11/25 15:07:28  ncq
--- - create schema "clin" and move all things clinical into it
---
--- Revision 1.10  2005/09/19 16:38:52  ncq
--- - adjust to removed is_core from gm_schema_revision
---
--- Revision 1.9  2005/07/14 21:31:43  ncq
--- - partially use improved schema revision tracking
---
--- Revision 1.8  2004/04/14 13:33:04  ncq
--- - need to adjust min_interval for seq_no=1 after tightening interval checks
---
--- Revision 1.7  2004/03/18 09:56:12  ncq
--- - is_booster removal
---
--- Revision 1.6  2003/12/29 15:58:32  uid66147
--- - name cleanup
---
--- Revision 1.5  2003/12/01 22:14:24  ncq
--- - improve wording
---
--- Revision 1.4  2003/11/28 08:15:57  ncq
--- - PG 7.1/pyPgSQL/mxDateTime returns 0 for interval=1 month,
---   it works with interval=4 weeks, though, so use that
---
--- Revision 1.3  2003/11/26 23:54:51  ncq
--- - lnk_vaccdef2reg does not exist anymore
---
--- Revision 1.2  2003/11/26 00:12:19  ncq
--- - fix fk_recommended_by value
---
--- Revision 1.1  2003/11/26 00:10:45  ncq
--- - Prevenar
---
diff --git a/server/sql/country.specific/de/Impfplan-Typhus.sql b/server/sql/country.specific/de/Impfplan-Typhus.sql
index ff9b9d8..0ea565b 100644
--- a/server/sql/country.specific/de/Impfplan-Typhus.sql
+++ b/server/sql/country.specific/de/Impfplan-Typhus.sql
@@ -5,8 +5,6 @@
 
 -- author: Karsten Hilbert <Karsten.Hilbert at gmx.net>
 -- license: GPL v2 or later
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/country.specific/de/Impfplan-Typhus.sql,v $
--- $Id: Impfplan-Typhus.sql,v 1.2 2006-03-04 16:24:39 ncq Exp $
 -- =============================================
 -- force terminate + exit(3) on errors if non-interactive
 \set ON_ERROR_STOP 1
@@ -42,13 +40,3 @@ values (
 
 -- =============================================
 select log_script_insertion('$RCSfile: Impfplan-Typhus.sql,v $', '$Revision: 1.2 $');
-
--- =============================================
--- $Log: Impfplan-Typhus.sql,v $
--- Revision 1.2  2006-03-04 16:24:39  ncq
--- - adjust to table name changes
---
--- Revision 1.1  2006/02/27 17:31:30  ncq
--- - Typhus-Impfplan
---
---
\ No newline at end of file
diff --git a/server/sql/country.specific/de/Impfstoffe.sql b/server/sql/country.specific/de/Impfstoffe.sql
index 56f0122..bb3bd4e 100644
--- a/server/sql/country.specific/de/Impfstoffe.sql
+++ b/server/sql/country.specific/de/Impfstoffe.sql
@@ -5,13 +5,10 @@
 
 -- author: Karsten Hilbert <Karsten.Hilbert at gmx.net>
 -- license: GPL v2 or later
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/country.specific/de/Impfstoffe.sql,v $
--- $Revision: 1.26 $
 -- =============================================
 -- force terminate + exit(3) on errors if non-interactive
 \set ON_ERROR_STOP 1
 
-set client_encoding to 'LATIN1';
 -- =============================================
 -- Tetanus --
 -------------
@@ -170,7 +167,7 @@ insert into clin.vaccine (
 	'Flu 03',
 	false,
 	'6 months'::interval,
-	'nur g�ltig Halbjahr 2003/2004'
+	'nur gültig Halbjahr 2003/2004'
 );
 
 -- link to indications
@@ -191,7 +188,7 @@ insert into clin.vaccine (
 	'Flu 04',
 	false,
 	'6 months'::interval,
-	'- nur g�ltig Halbjahr 2004/2005,
+	'- nur gültig Halbjahr 2004/2005,
 	 - Kinder zwischen 6 und 35 Monaten mit 0.25ml impfen'
 );
 
@@ -285,7 +282,7 @@ insert into clin.vaccine (
 	'Repevax',
 	false,
 	'10 years'::interval,
-	'nicht zur Grundimmunisierung verwenden, Tetanus-Diphtherie-azellul�rer-5-Komponenten-Pertussis-inaktivierter Poliomyelitis-Adsorbat-Impfstoff'
+	'nicht zur Grundimmunisierung verwenden, Tetanus-Diphtherie-azellulärer-5-Komponenten-Pertussis-inaktivierter Poliomyelitis-Adsorbat-Impfstoff'
 );
 
 -- link to indications
@@ -418,11 +415,11 @@ insert into clin.vaccine (
 	comment
 ) values (
 	(select id from clin.vacc_route where abbreviation='i.m.'),
-	'Masern-Impfstoff M�rieux',
+	'Masern-Impfstoff Mérieux',
 	'Masern',
 	true,
 	'12 months'::interval,
-	'Masern-Impfstoff M�rieux'
+	'Masern-Impfstoff Mérieux'
 );
 
 -- link to indications
@@ -523,7 +520,7 @@ insert into clin.lnk_vaccine2inds (fk_vaccine, fk_indication)
 values (currval('clin.vaccine_pk_seq'), (select id from clin.vacc_indication where description='haemophilus influenzae b'));
 
 -----------------
--- IPV M�rieux --
+-- IPV Mérieux --
 -----------------
 insert into clin.vaccine (
 	id_route,
@@ -533,7 +530,7 @@ insert into clin.vaccine (
 	min_age
 ) values (
 	(select id from clin.vacc_route where abbreviation='i.m.'),
-	'IPV M�rieux',
+	'IPV Mérieux',
 	'IPV',
 	false,
 	'2 months'::interval
@@ -559,7 +556,7 @@ insert into clin.vaccine (
 	'Typhus',
 	false,
 	'2 years'::interval,
-	'unter 2 Jahren bildet sich kein ad�quater Titer'
+	'unter 2 Jahren bildet sich kein adäquater Titer'
 );
 
 -- link to indications
@@ -569,89 +566,3 @@ values (currval('clin.vaccine_pk_seq'), (select id from clin.vacc_indication whe
 -- =============================================
 -- do simple revision tracking
 select log_script_insertion('$RCSfile: Impfstoffe.sql,v $', '$Revision: 1.26 $');
-
--- =============================================
--- $Log: Impfstoffe.sql,v $
--- Revision 1.26  2006-02-27 17:31:47  ncq
--- - Typhus-Impfstoff hinzugef�gt
---
--- Revision 1.25  2005/12/29 21:48:09  ncq
--- - clin.vaccine.id -> pk
--- - remove clin.vaccine.last_batch_no
--- - add clin.vaccine_batches
--- - adjust test data and country data
---
--- Revision 1.24  2005/11/25 15:07:28  ncq
--- - create schema "clin" and move all things clinical into it
---
--- Revision 1.23  2005/09/19 16:38:52  ncq
--- - adjust to removed is_core from gm_schema_revision
---
--- Revision 1.22  2005/07/14 21:31:43  ncq
--- - partially use improved schema revision tracking
---
--- Revision 1.21  2005/04/03 09:29:57  ncq
--- - when using non-ascii chars must specify encoding ...
---
--- Revision 1.20  2004/12/18 09:56:34  ncq
--- - cleanup
---
--- Revision 1.19  2004/10/01 11:44:51  ncq
--- - InfectoVac Flu 2004/2005
---
--- Revision 1.18  2004/09/10 10:57:45  ncq
--- - IPV Merieux
---
--- Revision 1.17  2004/08/04 10:05:43  ncq
--- - added Meningitec
---
--- Revision 1.16  2004/06/25 10:27:18  ncq
--- - Revaxis/Masern-Impfstoff/Act-HiB
---
--- Revision 1.15  2004/04/30 09:21:54  ncq
--- - min_age must be > 0 years
---
--- Revision 1.14  2004/04/27 17:06:46  ncq
--- - HBVAXPRO
---
--- Revision 1.13  2004/04/19 09:27:34  ncq
--- - add PentaVac
---
--- Revision 1.12  2004/04/14 13:33:04  ncq
--- - need to adjust min_interval for seq_no=1 after tightening interval checks
---
--- Revision 1.11  2004/03/27 18:36:28  ncq
--- - cleanup, added FSME vaccine
---
--- Revision 1.10  2004/02/09 23:57:39  ncq
--- - Priorix (MMR)
---
--- Revision 1.9  2004/01/26 20:18:37  ncq
--- - diphtheria, not diphtherie
---
--- Revision 1.8  2004/01/22 23:45:12  ncq
--- - REPEVAX/FSME Junior
---
--- Revision 1.7  2004/01/18 21:58:22  ncq
--- - remove is_licensed
--- - add Havrix 1440
---
--- Revision 1.6  2004/01/12 13:31:34  ncq
--- - better short_name(s)
--- - add Menjugate
---
--- Revision 1.5  2003/12/29 15:59:24  uid66147
--- - NeisVac C
---
--- Revision 1.4  2003/11/30 10:34:35  ncq
--- - InfectoVac Flu 2003/4
---
--- Revision 1.3  2003/11/26 22:44:46  ncq
--- - added Prvenar
---
--- Revision 1.2  2003/11/22 14:55:51  ncq
--- - Havrix 720 Kinder
---
--- Revision 1.1  2003/10/31 23:15:06  ncq
--- - first version
---
diff --git a/server/sql/country.specific/de/PLZ.sql b/server/sql/country.specific/de/PLZ.sql
index 0108dcf..bc2f7c3 100644
--- a/server/sql/country.specific/de/PLZ.sql
+++ b/server/sql/country.specific/de/PLZ.sql
@@ -2,20 +2,17 @@
 
 -- author: Karsten Hilbert <Karsten.Hilbert at gmx.net>
 -- license: GPL v2 or later
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/country.specific/de/PLZ.sql,v $
--- $Revision: 1.13 $
 
 -- ===================================================================
 -- force terminate + exit(3) on errors if non-interactive
 \set ON_ERROR_STOP 1
 
-set client_encoding to 'LATIN1';
 -- ===================================================================
 delete from dem.urb where id_state = (select id from dem.state where code='SN' and country='DE');
 delete from dem.state where country='DE';
 
--- Deutschland (Bundesl�nder)
-insert into dem.state (code, country, name) values ('BW', 'DE', 'Baden-W�rttemberg');
+-- Deutschland (Bundesländer)
+insert into dem.state (code, country, name) values ('BW', 'DE', 'Baden-Württemberg');
 insert into dem.state (code, country, name) values ('BY', 'DE', 'Bayern');
 insert into dem.state (code, country, name) values ('BE', 'DE', 'Berlin');
 insert into dem.state (code, country, name) values ('BB', 'DE', 'Brandenburg');
@@ -30,20 +27,20 @@ insert into dem.state (code, country, name) values ('SL', 'DE', 'Saarland');
 insert into dem.state (code, country, name) values ('SN', 'DE', 'Sachsen');
 insert into dem.state (code, country, name) values ('ST', 'DE', 'Sachsen-Anhalt');
 insert into dem.state (code, country, name) values ('SH', 'DE', 'Schleswig-Holstein');
-insert into dem.state (code, country, name) values ('TH', 'DE', 'Th�ringen');
+insert into dem.state (code, country, name) values ('TH', 'DE', 'Thüringen');
 
--- �sterreich (Bundesl�nder)
+-- Österreich (Bundesländer)
 insert into dem.state (code, country, name) values ('Wien', 'AT', 'Wien');				-- Vienna
 insert into dem.state (code, country, name) values ('Tirol', 'AT', 'Tirol');			-- the Tyrol
-insert into dem.state (code, country, name) values ('O�', 'AT', 'Ober�sterreich');		-- Upper Austria
-insert into dem.state (code, country, name) values ('N�', 'AT', 'Nieder�sterreich');	-- Lower Austria
+insert into dem.state (code, country, name) values ('OÖ', 'AT', 'Oberösterreich');		-- Upper Austria
+insert into dem.state (code, country, name) values ('NÖ', 'AT', 'Niederösterreich');	-- Lower Austria
 insert into dem.state (code, country, name) values ('Stmk', 'AT', 'Steiermark');		-- Styria
 insert into dem.state (code, country, name) values ('Sbg', 'AT', 'Salzburg');
 insert into dem.state (code, country, name) values ('Vlbg', 'AT', 'Vorarlberg');
 insert into dem.state (code, country, name) values ('Bgld', 'AT', 'Burgenland');
-insert into dem.state (code, country, name) values ('Ktn', 'AT', 'K�rnten');			-- Carinthia
+insert into dem.state (code, country, name) values ('Ktn', 'AT', 'Kärnten');			-- Carinthia
 
--- jo, wos is jetz d�s ?
+-- jo, wos is jetz dös ?
 --INSERT into dem.state(code, country, name) VALUES ('BU','AT',i18n.i18n('Burgenland'));
 --INSERT into dem.state(code, country, name) VALUES ('CA','AT',i18n.i18n('Carinthia'));
 --INSERT into dem.state(code, country, name) VALUES ('NI','AT',i18n.i18n('Niederoesterreich'));
@@ -57,11 +54,11 @@ insert into dem.state (code, country, name) values ('Ktn', 'AT', 'K
 select dem.gm_upd_default_states();
 
 ------------------
--- Gro� S�rchen --
+-- Groß Särchen --
 ------------------
 insert into dem.urb (id_state, name, postcode) values (
 	(select id from dem.state where code = 'SN' and country='DE'),
-	'Gro� S�rchen',
+	'Groß Särchen',
 	'02999'
 );
 
@@ -96,7 +93,7 @@ insert into dem.street (
 
 insert into dem.street (id_urb, name, postcode) values (
 	(select id from dem.urb where name='Leipzig' limit 1),
-	'Riebeckstra�e',
+	'Riebeckstraße',
 	'04317'
 );
 
@@ -108,7 +105,7 @@ insert into dem.street (id_urb, name, postcode) values (
 
 insert into dem.street (id_urb, name, postcode) values (
 	(select id from dem.urb where name='Leipzig' limit 1),
-	'Ferdinand-Jost-Stra�e',
+	'Ferdinand-Jost-Straße',
 	'04299'
 );
 
@@ -126,7 +123,7 @@ insert into dem.street (
 
 insert into dem.street (id_urb, name, postcode) values (
 	(select id from dem.urb where name='Leipzig' limit 1),
-	'Wurzener Stra�e',
+	'Wurzener Straße',
 	'04315'
 );
 
@@ -137,14 +134,14 @@ insert into dem.street (
 	postcode
 ) values (
 	(select id from dem.urb where name='Leipzig' limit 1),
-	'Wurzener Stra�e',
+	'Wurzener Straße',
 	'Sellerhausen',
 	'04318'
 );
 
 insert into dem.street (id_urb, name, postcode) values (
 	(select id from dem.urb where name='Leipzig' limit 1),
-	'Eilenburger Stra�e',
+	'Eilenburger Straße',
 	'04317'
 );
 
@@ -155,7 +152,7 @@ insert into dem.street (
 	postcode
 ) values (
 	(select id from dem.urb where name='Leipzig' limit 1),
-	'Cunnersdorfer Stra�e',
+	'Cunnersdorfer Straße',
 	'Sellerhausen',
 	'04318'
 );
@@ -164,52 +161,3 @@ insert into dem.street (
 -- do simple revision tracking
 delete from gm_schema_revision where filename = '$RCSfile: PLZ.sql,v $';
 INSERT INTO gm_schema_revision (filename, version) VALUES('$RCSfile: PLZ.sql,v $', '$Revision: 1.13 $');
-
--- =============================================
--- $Log: PLZ.sql,v $
--- Revision 1.13  2006-01-09 13:46:19  ncq
--- - adjust to schema "i18n" qualification
---
--- Revision 1.12  2006/01/06 10:12:02  ncq
--- - add missing grants
--- - add_table_for_audit() now in "audit" schema
--- - demographics now in "dem" schema
--- - add view v_inds4vaccine
--- - move staff_role from clinical into demographics
--- - put add_coded_term() into "clin" schema
--- - put German things into "de_de" schema
---
--- Revision 1.11  2005/10/19 11:29:09  ncq
--- - when selecting state pks must give country, too, or else duplicates exist
---
--- Revision 1.10  2005/09/25 17:52:09  ncq
--- - add commented out alternative state information for AT
---
--- Revision 1.9  2005/09/19 16:26:07  ncq
--- - update default states
---
--- Revision 1.8  2005/07/14 21:31:43  ncq
--- - partially use improved schema revision tracking
---
--- Revision 1.7  2005/06/10 07:21:35  ncq
--- - better docs
---
--- Revision 1.6  2005/06/07 20:59:18  ncq
--- - Austrian states
---
--- Revision 1.5  2005/05/24 19:44:31  ncq
--- - use proper state abbreviations
---
--- Revision 1.4  2005/05/17 08:17:53  ncq
--- - Bundesl�nder
---
--- Revision 1.3  2004/09/20 21:17:39  ncq
--- - add a few suburbs
---
--- Revision 1.2  2004/04/07 18:16:06  ncq
--- - move grants into re-runnable scripts
--- - update *.conf accordingly
---
--- Revision 1.1  2003/12/29 15:15:01  uid66147
--- - a few German post codes
---
diff --git a/server/sql/country.specific/de/STIKO-Impfkalender.sql b/server/sql/country.specific/de/STIKO-Impfkalender.sql
index 1eeefb6..12a29a6 100644
--- a/server/sql/country.specific/de/STIKO-Impfkalender.sql
+++ b/server/sql/country.specific/de/STIKO-Impfkalender.sql
@@ -2,19 +2,16 @@
 -- Impfkalender der STIKO (Deutschland)
 
 -- Quellen:
--- Kinder�rztliche Praxis (2002)
+-- Kinderärztliche Praxis (2002)
 -- Sonderheft "Impfen 2002"
 -- Kirchheim-Verlag Mainz
 
 -- author: Karsten Hilbert <Karsten.Hilbert at gmx.net>
 -- license: GPL v2 or later
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/country.specific/de/STIKO-Impfkalender.sql,v $
--- $Revision: 1.20 $
 -- =============================================
 -- force terminate + exit(3) on errors if non-interactive
 \set ON_ERROR_STOP 1
 
-set client_encoding to 'latin1';
 -- =============================================
 delete from clin.vaccination_schedule where name like '%(STIKO)%';
 delete from clin.vaccination_course where fk_recommended_by = (select pk from ref_source where name_short='STIKO');
@@ -30,10 +27,10 @@ insert into ref_source (
 	source
 ) values (
 	'STIKO',
-	'St�ndige Impfkommission, Robert-Koch-Institut',
+	'Ständige Impfkommission, Robert-Koch-Institut',
 	'Juli 2002',
-	'Standardimpfungen f�r S�uglinge, Kinder, Jugendliche und Erwachsene',
-	'"Kinder�rztliche Praxis" (2002), Sonderheft "Impfen 2002", Kirchheim-Verlag Mainz'
+	'Standardimpfungen für Säuglinge, Kinder, Jugendliche und Erwachsene',
+	'"Kinderärztliche Praxis" (2002), Sonderheft "Impfen 2002", Kirchheim-Verlag Mainz'
 );
 
 ------------
@@ -99,7 +96,7 @@ values (
 );
 
 ------------
--- R�teln --
+-- Röteln --
 ------------
 -- Impfplan definieren
 insert into clin.vaccination_course
@@ -147,7 +144,7 @@ insert into clin.lnk_vaccination_course2schedule (fk_course, fk_schedule) values
 	(select pk_course from clin.v_vaccination_courses where indication = 'mumps' and recommended_by_name_short = 'STIKO'),
 	(select pk from clin.vaccination_schedule where name = 'MMR (STIKO)')
 );
--- R�teln
+-- Röteln
 insert into clin.lnk_vaccination_course2schedule (fk_course, fk_schedule) values (
 	(select pk_course from clin.v_vaccination_courses where indication = 'rubella' and recommended_by_name_short = 'STIKO'),
 	(select pk from clin.vaccination_schedule where name = 'MMR (STIKO)')
@@ -213,7 +210,7 @@ values (
 	'10 years'::interval,
 	true,
 	'10 years'::interval,
-	'nach 10 Jahren falls keine Verletzung, nach 7 Jahren bei kleinen Verletzungen, bei gro�en Verletzungen nach 5 Jahren'
+	'nach 10 Jahren falls keine Verletzung, nach 7 Jahren bei kleinen Verletzungen, bei großen Verletzungen nach 5 Jahren'
 );
 
 ----------------
@@ -473,7 +470,7 @@ values (
 	currval('clin.vaccination_course_pk_seq'),
 	1,
 	'18 years'::interval,
-	'j�hrlich neu von WHO empfohlener Impfstoff'
+	'jährlich neu von WHO empfohlener Impfstoff'
 );
 
 insert into clin.vaccination_definition
@@ -484,7 +481,7 @@ values (
 	'19 years'::interval,
 	true,
 	'1 year'::interval,
-	'j�hrlich neu von WHO empfohlener Impfstoff'
+	'jährlich neu von WHO empfohlener Impfstoff'
 );
 
 ------------------
@@ -574,70 +571,3 @@ values (
 -- =============================================
 -- do simple revision tracking
 select log_script_insertion('$RCSfile: STIKO-Impfkalender.sql,v $', '$Revision: 1.20 $');
-
--- =============================================
--- $Log: STIKO-Impfkalender.sql,v $
--- Revision 1.20  2006-03-08 09:25:55  ncq
--- - a bunch of cleanup/rename adjustment
--- - add first aggregate schedule: MMR
---
--- Revision 1.19  2006/03/04 16:24:39  ncq
--- - adjust to table name changes
---
--- Revision 1.18  2006/01/01 20:43:14  ncq
--- - adjust to tightened constraints
---
--- Revision 1.17  2005/11/25 15:07:28  ncq
--- - create schema "clin" and move all things clinical into it
---
--- Revision 1.16  2005/09/19 16:38:52  ncq
--- - adjust to removed is_core from gm_schema_revision
---
--- Revision 1.15  2005/07/14 21:31:43  ncq
--- - partially use improved schema revision tracking
---
--- Revision 1.14  2004/10/12 11:23:31  ncq
--- - fix Polio regime being wrongly linked to HepB indication
---
--- Revision 1.13  2004/04/14 20:03:59  ncq
--- - fix check constraints on intervals
---
--- Revision 1.12  2004/04/14 13:33:04  ncq
--- - need to adjust min_interval for seq_no=1 after tightening interval checks
---
--- Revision 1.11  2004/03/18 09:58:50  ncq
--- - removed is_booster reference where is false
---
--- Revision 1.10  2003/12/29 16:01:21  uid66147
--- - use lnk_vacc2vacc_def
--- - add STIKO gmReference entry
--- - more appropriate vacc_regime.name values
--- - add HiB/HepB
---
--- Revision 1.9  2003/12/03 19:09:46  ncq
--- - NeisVac-C
---
--- Revision 1.8  2003/12/01 23:53:18  ncq
--- - delete more selectively
---
--- Revision 1.7  2003/12/01 22:22:41  ncq
--- - vastly improve strings
---
--- Revision 1.6  2003/11/26 23:19:08  ncq
--- - vacc_def now links to vacc_regime instead of vacc_indication
---
--- Revision 1.5  2003/10/31 23:30:28  ncq
--- - cleanup
---
--- Revision 1.4  2003/10/26 09:41:03  ncq
--- - truncate -> delete from
---
--- Revision 1.3  2003/10/25 16:45:19  ncq
--- - seq_id -> seq_no
---
--- Revision 1.2  2003/10/21 15:04:49  ncq
--- - update vaccination schedules for Germany
---
--- Revision 1.1  2003/10/19 15:17:41  ncq
--- - German vaccination regimes recommended by the STIKO
---
diff --git a/server/sql/country.specific/de/amis-import_data_template.sql b/server/sql/country.specific/de/amis-import_data_template.sql
index 903ce5f..ddab8b7 100644
--- a/server/sql/country.specific/de/amis-import_data_template.sql
+++ b/server/sql/country.specific/de/amis-import_data_template.sql
@@ -3,13 +3,9 @@
 -- information provided by the german AMIS database
 -- into Postgres tables
 
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/country.specific/de/amis-import_data_template.sql,v $
 -- author: Horst Herb, Hilmar Berger, Karsten Hilbert
--- version: $Revision: 1.1 $
 -- license: GPL v2 or later
 
-set client_encoding to 'LATIN1';
-
 -- =====================================================================================
 -- amis_praeparate : table of preparations
 \copy amis_praeparate from 'AMIS_PATH/basis/praepara.ami' using delimiters '$' WITH NULL AS '' 
@@ -93,25 +89,3 @@ CREATE INDEX idx_substance_name ON amis_substances_names (substance_name);
 CREATE INDEX idx_drug_desc_text_key on amis_drug_description (text_key);
 
 -- ===============================================
--- $Log: amis-import_data_template.sql,v $
--- Revision 1.1  2003-10-26 16:07:07  hinnef
--- initial AMIS-schema and data import
---
--- Revision 1.5  2002/11/11 08:22:42  ncq
--- - amis_orig -> amis-orig
---
--- Revision 1.4  2002/11/10 22:31:11  hinnef
--- removed some useless lines
---
--- Revision 1.3  2002/11/10 16:15:06  ncq
--- - added index
---
--- Revision 1.2  2002/11/10 14:13:25  ncq
--- - source dir for taxe_her.ami was wrong
---
--- Revision 1.1  2002/10/24 12:56:38  ncq
--- - initial checkin
--- - split into creation of tables and import of data so people
---   without the data can still import the structure
--- - fix whitespace and typos, make layout more consistent
---
diff --git a/server/sql/country.specific/de/gmATC.sql b/server/sql/country.specific/de/gmATC.sql
index 97984e3..9f4d17f 100644
--- a/server/sql/country.specific/de/gmATC.sql
+++ b/server/sql/country.specific/de/gmATC.sql
@@ -1,6 +1,3 @@
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/country.specific/de/gmATC.sql,v $
--- $Revision: 1.3 $
-
 -- part of GNUmed
 -- GPL v2 or later
 -- author: Karsten Hilbert <Karsten.Hilbert at gmx.net>
@@ -25,68 +22,68 @@ insert into ref_source (
 	source
 ) values (
 	'ATC/DDD-GM-2004',
-	'ATC/DDD-GM; Systematik
; Version 2004
; Amtliche Fassung f�r die Bundesrepublik Deutschland',
+	'ATC/DDD-GM; Systematik
; Version 2004
; Amtliche Fassung für die Bundesrepublik Deutschland',
 	'2004',
 
 'ATC/DDD-GM
 Systematik
 Version 2004
 
-Amtliche Fassung f�r die Bundesrepublik Deutschland
+Amtliche Fassung für die Bundesrepublik Deutschland
 
 Lizenz:
 ========================================================================================================
 Mit dem Download der Dateien kommt ein Erwerbervertrag zwischen Ihnen und DIMDI zustande. Sie
 verpflichten sich dadurch, unsere Abgabebedingungen einzuhalten. Sie umfassen:
 
-�1 Urheberrecht/Nutzungsumfang
+§1 Urheberrecht/Nutzungsumfang
 
  1. Bei den vom DIMDI herausgegebenen amtlichen deutschsprachigen Ausgaben der ATC mit DDD und den
-    "Richtlinien f�r die ATC-Klassifikation und die DDD-Festlegung" handelt es sich um ein "anderes
-    amtliches Werk" i. S. des � 5 Abs. 2 Urheberrechtsgesetz (UrhG).
-    Bei Beachtung des �nderungsverbotes (� 62 UrhG) und des Gebotes der Quellenangabe (� 63 UrhG)
-    verf�gen Sie zeitlich befristet �ber die Nutzungsrechte an diesem Werk.
- 2. Wollen Sie die Daten auszugsweise oder vollst�ndig an Dritte weitergeben (vervielf�ltigen), so
+    "Richtlinien für die ATC-Klassifikation und die DDD-Festlegung" handelt es sich um ein "anderes
+    amtliches Werk" i. S. des § 5 Abs. 2 Urheberrechtsgesetz (UrhG).
+    Bei Beachtung des Änderungsverbotes (§ 62 UrhG) und des Gebotes der Quellenangabe (§ 63 UrhG)
+    verfügen Sie zeitlich befristet über die Nutzungsrechte an diesem Werk.
+ 2. Wollen Sie die Daten auszugsweise oder vollständig an Dritte weitergeben (vervielfältigen), so
     gelten die nachstehenden Vereinbarungen, und Sie verpflichten sich, diese Vereinbarungen ebenfalls
     an Dritte weiterzugeben:
-    Bei der auszugsweisen oder vollst�ndigen Weitergabe der Daten an Dritte sind �nderungen der
-    inhaltlichen Struktur und Normierung der der ATC mit DDD und den "Richtlinien f�r die
+    Bei der auszugsweisen oder vollständigen Weitergabe der Daten an Dritte sind Änderungen der
+    inhaltlichen Struktur und Normierung der der ATC mit DDD und den "Richtlinien für die
     ATC-Klassifikation und die DDD-Festlegung" nicht gestattet. Insbesondere darf das amtliche Werk
     keine kommerzielle Werbung enthalten. Erlaubt sind lediglich werbende Hinweise auf verlagseigene
-    Produkte, jedoch d�rfen auch diese Hinweise nicht im amtlichen Text stehen. Vor der Erstellung einer
-    Druckausgabe und deren Weitergabe m�ssen Sie Kontakt mit DIMDI aufnehmen, weil eine Reihe von
+    Produkte, jedoch dürfen auch diese Hinweise nicht im amtlichen Text stehen. Vor der Erstellung einer
+    Druckausgabe und deren Weitergabe müssen Sie Kontakt mit DIMDI aufnehmen, weil eine Reihe von
     Vorschriften zu beachten ist. In jedes maschinenlesbare Weitergabeexemplar ist die folgende
-    Formulierung aufzunehmen: Die Erstellung erfolgte unter Verwendung der Datentr�ger der amtlichen
-    Fassung der ATC mit DDD und den "Richtlinien f�r die ATC-Klassifikation und die DDD-Festlegung" des
-    Deutschen Instituts f�r medizinische Dokumentation und Information (DIMDI).
-      + F�r die ATC mit DDDs: In der Originalausgabe ver�ffentlicht durch das WHO-Zentrum f�r die
+    Formulierung aufzunehmen: Die Erstellung erfolgte unter Verwendung der Datenträger der amtlichen
+    Fassung der ATC mit DDD und den "Richtlinien für die ATC-Klassifikation und die DDD-Festlegung" des
+    Deutschen Instituts für medizinische Dokumentation und Information (DIMDI).
+      + Für die ATC mit DDDs: In der Originalausgabe veröffentlicht durch das WHO-Zentrum für die
         Erarbeitung der Methodik der Arzneimittelstatistik, Oslo, unter dem Titel ATC-Index mit DDDs
-      + F�r die Richtlinien f�r die ATC-Klassifikation und die DDD-Festlegung: In der Originalausgabe
-        ver�ffentlicht durch das WHO-Zentrum f�r die Erarbeitung der Methodik der Arzneimittelstatistik,
-        Oslo, unter dem Titel Richtlinien f�r die ATC-Klassifikation und die DDD-Festlegung
+      + Für die Richtlinien für die ATC-Klassifikation und die DDD-Festlegung: In der Originalausgabe
+        veröffentlicht durch das WHO-Zentrum für die Erarbeitung der Methodik der Arzneimittelstatistik,
+        Oslo, unter dem Titel Richtlinien für die ATC-Klassifikation und die DDD-Festlegung
  3. Die Nutzung dieser Fassung ist nur in der Bundesrepublik Deutschland gestattet.
 
-�2 Gew�hrleistung und Haftung
+§2 Gewährleistung und Haftung
 
- 1. F�r Sch�den, die durch Fehler bei der Herstellung bzw. Bearbeitung der ATC mit DDD und der
-    "Richtlinien f�r die ATC-Klassifikation und die DDD-Festlegung" entstehen, haftet das DIMDI nur,
-    soweit ihm Vorsatz oder grobe Fahrl�ssigkeit zur Last f�llt. Es wird nur der Ersatz des
+ 1. Für Schäden, die durch Fehler bei der Herstellung bzw. Bearbeitung der ATC mit DDD und der
+    "Richtlinien für die ATC-Klassifikation und die DDD-Festlegung" entstehen, haftet das DIMDI nur,
+    soweit ihm Vorsatz oder grobe Fahrlässigkeit zur Last fällt. Es wird nur der Ersatz des
     unmittelbaren Schadens geschuldet.
- 2. Sie stellen das DIMDI frei von Anspr�chen, die dadurch entstehen, da� Sie die Rechte Dritter bei der
-    Vervielf�ltigung und Weitergabe von Daten nach � 1 Abs. 2 dieses Vertrages verletzen.
+ 2. Sie stellen das DIMDI frei von Ansprüchen, die dadurch entstehen, daß Sie die Rechte Dritter bei der
+    Vervielfältigung und Weitergabe von Daten nach § 1 Abs. 2 dieses Vertrages verletzen.
 
 [*] Ja, ich habe die Download-Bestimmungen gelesen und bin mit ihnen einverstanden.
 ========================================================================================================
 ',
 
-'Herausgegeben vom Deutschen Institut f�r Medizinische Dokumentation und Information, DIMDI
+'Herausgegeben vom Deutschen Institut für Medizinische Dokumentation und Information, DIMDI
 
 downloaded Samstag 26 Jun 2004 22:18:42 CEST
 http://www.dimdi.de/dynamic/de/klassi/download/atc1/index.html
 
 DIMDI
 Waisenhausgasse 36 - 38 a
-50676 K�ln
+50676 Köln
 Tel.: +49 (0) 221 47 24 1
 Fax:  +49 (0) 221 47 24 444
 Mail: posteingang at dimdi.de'
@@ -96,15 +93,3 @@ Mail: posteingang at dimdi.de'
 -- do simple revision tracking
 delete from gm_schema_revision where filename = '$RCSfile: gmATC.sql,v $';
 INSERT INTO gm_schema_revision (filename, version) VALUES('$RCSfile: gmATC.sql,v $', '$Revision: 1.3 $');
-
--- =============================================
--- $Log: gmATC.sql,v $
--- Revision 1.3  2005-09-19 16:38:52  ncq
--- - adjust to removed is_core from gm_schema_revision
---
--- Revision 1.2  2005/07/14 21:31:43  ncq
--- - partially use improved schema revision tracking
---
--- Revision 1.1  2004/06/26 21:14:27  ncq
--- German ATC data
---
diff --git a/server/sql/country.specific/de/gmDemographics.de.sql b/server/sql/country.specific/de/gmDemographics.de.sql
index ce2e8d9..145b186 100644
--- a/server/sql/country.specific/de/gmDemographics.de.sql
+++ b/server/sql/country.specific/de/gmDemographics.de.sql
@@ -1,6 +1,4 @@
 -- GNUmed
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/country.specific/de/gmDemographics.de.sql,v $
--- $Revision: 1.10 $
 
 -- license: GPL v2 or later
 
@@ -14,7 +12,6 @@
 create schema de_de authorization "gm-dbo";
 grant usage on schema de_de to group "gm-doctors";
 
--- set client_encoding to 'LATIN1';
 -- ===================================================================
 -- tables related to the German Krankenversichtenkarte KVK
 create table de_de.kvk (
@@ -25,24 +22,24 @@ create table de_de.kvk (
 		references dem.identity(pk),
 
 	-- eigentliche KVK-Felder
-	-- Datenbereich (020h-0FFh)				--  Feldtag	L�nge	Feldname				Optional
+	-- 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
+	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
+	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
+	Gueltigkeit character(4),				--  0x8D	4		Gültigkeitsdatum		ja
+	CRC character(1) not null,				--  0x8E	1		Prüfsumme				nein
 
 	is_valid_address boolean default true,
 
@@ -162,44 +159,3 @@ 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 $');
-
--- =============================================
--- $Log: gmDemographics.de.sql,v $
--- Revision 1.10  2006-01-06 10:12:02  ncq
--- - add missing grants
--- - add_table_for_audit() now in "audit" schema
--- - demographics now in "dem" schema
--- - add view v_inds4vaccine
--- - move staff_role from clinical into demographics
--- - put add_coded_term() into "clin" schema
--- - put German things into "de_de" schema
---
--- Revision 1.9  2006/01/05 16:04:37  ncq
--- - move auditing to its own schema "audit"
---
--- Revision 1.8  2005/11/25 15:06:25  ncq
--- - create schema de_DE
---
--- Revision 1.7  2005/11/19 13:51:46  ncq
--- - stra�e -> strasse
---
--- Revision 1.6  2005/09/19 16:38:52  ncq
--- - adjust to removed is_core from gm_schema_revision
---
--- Revision 1.5  2005/07/14 21:31:43  ncq
--- - partially use improved schema revision tracking
---
--- Revision 1.4  2005/04/14 16:48:33  ncq
--- - name_gender_map moved to generic demographics script
---
--- Revision 1.3  2005/02/12 13:49:14  ncq
--- - identity.id -> identity.pk
--- - allow NULL for identity.fk_marital_status
--- - subsequent schema changes
---
--- Revision 1.2  2003/12/29 16:02:28  uid66147
--- - client_encoding breakage
---
--- Revision 1.1  2003/08/05 08:16:00  ncq
--- - cleanup/renaming
---
diff --git a/server/sql/country.specific/de/gmDiagnosen.sql b/server/sql/country.specific/de/gmDiagnosen.sql
index bc2adcc..1c6e115 100644
--- a/server/sql/country.specific/de/gmDiagnosen.sql
+++ b/server/sql/country.specific/de/gmDiagnosen.sql
@@ -1,9 +1,6 @@
 -- =============================================
 -- GNUmed: Diagnosen
 
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/country.specific/de/gmDiagnosen.sql,v $
--- $Revision: 1.5 $
-
 -- license: GPL v2 or later
 -- author (of script file): Karsten Hilbert <Karsten.Hilbert at gmx.net>
 
@@ -11,19 +8,18 @@
 -- force terminate + exit(3) on errors if non-interactive
 \set ON_ERROR_STOP 1
 
-set client_encoding to 'LATIN1';
 -- =============================================
 select clin.add_coded_term('Harnwegsinfekt', 'N39.0', 'ICD10-GM 2004');
 select clin.add_coded_term('Pollinosis', 'J30.1', 'ICD-10-GM 2004');
 select clin.add_coded_term('Basedow-Struma', 'E05.0', 'ICD-10-GM 2004');
 select clin.add_coded_term('Strumaresektion', 'Z98.8', 'ICD-10-GM 2004');
-select clin.add_coded_term('Follikul�res Schilddr�senkarzinom', 'C73', 'ICD-10-GM 2004');
-select clin.add_coded_term('Hyperlipid�mie', 'E78.5', 'ICD-10-GM 2004');
+select clin.add_coded_term('Follikuläres Schilddrüsenkarzinom', 'C73', 'ICD-10-GM 2004');
+select clin.add_coded_term('Hyperlipidämie', 'E78.5', 'ICD-10-GM 2004');
 select clin.add_coded_term('Diabetes mellitus nnb', 'E14.9', 'ICD-10-GM 2004');
 select clin.add_coded_term('Reizblase', 'R30.0', 'ICD-10-GM 2004');
 select clin.add_coded_term('Hyperthyreose', 'E05.9', 'ICD-10-GM 2004');
-select clin.add_coded_term('Hypercholesterin�mie', 'E78.0', 'ICD-10-GM 2004');
-select clin.add_coded_term('Hypocalz�mie', 'R79.0', 'ICD-10-GM 2004');
+select clin.add_coded_term('Hypercholesterinämie', 'E78.0', 'ICD-10-GM 2004');
+select clin.add_coded_term('Hypocalzämie', 'R79.0', 'ICD-10-GM 2004');
 select clin.add_coded_term('Strumaresektion', 'E89.-', 'ICD-10-GM 2004');
 select clin.add_coded_term('Lymphangitis', 'I89.1', 'ICD-10-GM 2004');
 select clin.add_coded_term('Check up', 'Z00.-', 'ICD-10-GM 2004');
@@ -46,10 +42,10 @@ select clin.add_coded_term('Mumps', 'B26.2+', 'ICD-10-GM 2004');
 select clin.add_coded_term('Mumps', 'B26.3+', 'ICD-10-GM 2004');
 select clin.add_coded_term('Mumps', 'B26.8', 'ICD-10-GM 2004');
 select clin.add_coded_term('Mumps', 'B26.9', 'ICD-10-GM 2004');
-select clin.add_coded_term('R�teln', 'B06', 'ICD-10-GM 2004');
-select clin.add_coded_term('R�teln', 'B06.0+', 'ICD-10-GM 2004');
-select clin.add_coded_term('R�teln', 'B06.8', 'ICD-10-GM 2004');
-select clin.add_coded_term('R�teln', 'B06.9', 'ICD-10-GM 2004');
+select clin.add_coded_term('Röteln', 'B06', 'ICD-10-GM 2004');
+select clin.add_coded_term('Röteln', 'B06.0+', 'ICD-10-GM 2004');
+select clin.add_coded_term('Röteln', 'B06.8', 'ICD-10-GM 2004');
+select clin.add_coded_term('Röteln', 'B06.9', 'ICD-10-GM 2004');
 select clin.add_coded_term('Tetanus', 'A33', 'ICD-10-GM 2004');
 select clin.add_coded_term('Tetanus', 'A34', 'ICD-10-GM 2004');
 select clin.add_coded_term('Tetanus', 'A35', 'ICD-10-GM 2004');
@@ -93,27 +89,3 @@ select clin.add_coded_term('Meningokokkeninfektion', 'A39.9', 'ICD-10-GM 2004');
 -- do simple revision tracking
 delete from gm_schema_revision where filename = '$RCSfile: gmDiagnosen.sql,v $';
 INSERT INTO gm_schema_revision (filename, version) VALUES ('$RCSfile: gmDiagnosen.sql,v $', '$Revision: 1.5 $');
-
--- =============================================
--- $Log: gmDiagnosen.sql,v $
--- Revision 1.5  2006-02-10 14:10:26  ncq
--- - add what was linked to vacc_indication previously
---
--- Revision 1.4  2006/01/06 10:12:02  ncq
--- - add missing grants
--- - add_table_for_audit() now in "audit" schema
--- - demographics now in "dem" schema
--- - add view v_inds4vaccine
--- - move staff_role from clinical into demographics
--- - put add_coded_term() into "clin" schema
--- - put German things into "de_de" schema
---
--- Revision 1.3  2005/09/19 16:38:52  ncq
--- - adjust to removed is_core from gm_schema_revision
---
--- Revision 1.2  2005/07/14 21:31:43  ncq
--- - partially use improved schema revision tracking
---
--- Revision 1.1  2005/04/06 10:41:19  ncq
--- - add a bunch of diagnoses coded ICD-10-GM
---
diff --git a/server/sql/country.specific/de/gmUebersetzung.sql b/server/sql/country.specific/de/gmUebersetzung.sql
index c56df1b..4176238 100644
--- a/server/sql/country.specific/de/gmUebersetzung.sql
+++ b/server/sql/country.specific/de/gmUebersetzung.sql
@@ -1,9 +1,6 @@
 -- =============================================
 -- GNUmed German translations
 
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/country.specific/de/gmUebersetzung.sql,v $
--- $Revision: 1.13 $
-
 -- license: GPL v2 or later
 -- author (of script file): Karsten Hilbert <Karsten.Hilbert at gmx.net>
 
@@ -14,7 +11,7 @@
 set client_encoding to 'LATIN1';
 -- =============================================
 select i18n.upd_tx('de_DE', 'Germany', 'Deutschland');
-select i18n.upd_tx('de_DE', 'Austria', '�sterreich');
+select i18n.upd_tx('de_DE', 'Austria', 'Österreich');
 select i18n.upd_tx('de_DE', 'Spain', 'Spanien');
 select i18n.upd_tx('de_DE', 'Australia', 'Australien');
 select i18n.upd_tx('de_DE', 'Canada', 'Kanada');
@@ -68,7 +65,7 @@ select i18n.upd_tx
 select i18n.upd_tx
 	('de_DE', 'referral report neuro', 'Arztbrief Neuro');
 select i18n.upd_tx
-	('de_DE', 'referral report radiology', 'Arztbrief R�ntgen');
+	('de_DE', 'referral report radiology', 'Arztbrief Röntgen');
 select i18n.upd_tx
 	('de_DE', 'referral report other', 'sonstiger Arztbrief');
 select i18n.upd_tx
@@ -91,12 +88,12 @@ select i18n.upd_tx
 
 -- =============================================
 -- confidentiality levels
-select i18n.upd_tx ('de_DE', 'public', '�ffentlich');
-select i18n.upd_tx ('de_DE', 'relatives', 'Angeh�rige');
+select i18n.upd_tx ('de_DE', 'public', 'öffentlich');
+select i18n.upd_tx ('de_DE', 'relatives', 'Angehörige');
 select i18n.upd_tx ('de_DE', 'receptionist', 'Personal');
 select i18n.upd_tx ('de_DE', 'clinical staff', 'klinisches Personal');
-select i18n.upd_tx ('de_DE', 'doctors', '�rzte');
-select i18n.upd_tx ('de_DE', 'doctors of practice only', '�rzte dieser Einrichtung');
+select i18n.upd_tx ('de_DE', 'doctors', 'Ärzte');
+select i18n.upd_tx ('de_DE', 'doctors of practice only', 'Ärzte dieser Einrichtung');
 select i18n.upd_tx ('de_DE', 'treating doctor', 'behandelnder Arzt');
 
 -- =============================================
@@ -149,7 +146,7 @@ select i18n.upd_tx('de_DE', 'other encounter', 'anderer Kontakt');
 --select i18n.upd_tx
 --	('de_DE', 'clinician', 'Mediziner');
 --select i18n.upd_tx
---	('de_DE', 'relative', 'Angeh�rige');
+--	('de_DE', 'relative', 'Angehörige');
 --select i18n.upd_tx
 --	('de_DE', 'carer', 'Pflegeperson');
 --select i18n.upd_tx
@@ -160,11 +157,11 @@ select i18n.upd_tx('de_DE', 'other encounter', 'anderer Kontakt');
 -- =============================================
 -- allergy types
 select i18n.upd_tx('de_DE', 'allergy', 'Allergie');
-select i18n.upd_tx('de_DE', 'sensitivity', 'Unvertr�glichkeit');
+select i18n.upd_tx('de_DE', 'sensitivity', 'Unverträglichkeit');
 
 -- =============================================
 -- vaccination routes
-select i18n.upd_tx('de_DE', 'intramuscular', 'intramuskul�r');
+select i18n.upd_tx('de_DE', 'intramuscular', 'intramuskulär');
 select i18n.upd_tx('de_DE', 'subcutaneous', 'subkutan');
 
 -- =============================================
@@ -174,7 +171,7 @@ select i18n.upd_tx
 select i18n.upd_tx
 	('de_DE', 'mumps', 'Mumps');
 select i18n.upd_tx 
-	('de_DE', 'rubella', 'R�teln');
+	('de_DE', 'rubella', 'Röteln');
 select i18n.upd_tx 
 	('de_DE', 'tetanus', 'Tetanus');
 select i18n.upd_tx 
@@ -201,9 +198,9 @@ select i18n.upd_tx
 -- =============================================
 -- Status Laborergebnis
 select i18n.upd_tx ('de_DE', 'pending', 'ausstehend');
-select i18n.upd_tx ('de_DE', 'final', 'endg�ltig');
-select i18n.upd_tx ('de_DE', 'preliminary', 'vorl�ufig');
-select i18n.upd_tx ('de_DE', 'partial', 'unvollst�ndig');
+select i18n.upd_tx ('de_DE', 'final', 'endgültig');
+select i18n.upd_tx ('de_DE', 'preliminary', 'vorläufig');
+select i18n.upd_tx ('de_DE', 'partial', 'unvollständig');
 
 -- =============================================
 -- names of interpersonal relations translated into German
@@ -262,74 +259,32 @@ select i18n.upd_tx('de_DE', 'name', 'Name');
 select i18n.upd_tx('de_DE', 'value', 'Wert');
 
 select i18n.upd_tx('de_DE', 'm', 'm');
-select i18n.upd_tx('de_DE', 'male', 'm�nnlich');
+select i18n.upd_tx('de_DE', 'male', 'männlich');
 select i18n.upd_tx('de_DE', 'f', 'w');
 select i18n.upd_tx('de_DE', 'female', 'weiblich');
 select i18n.upd_tx('de_DE', 'tm', 'tm');
-select i18n.upd_tx('de_DE', 'transsexual phenotype male', 'transsexuell, m�nnlicher Ph�notyp');
+select i18n.upd_tx('de_DE', 'transsexual phenotype male', 'transsexuell, männlicher Phänotyp');
 select i18n.upd_tx('de_DE', 'tf', 'tf');
-select i18n.upd_tx('de_DE', 'transsexual phenotype female', 'transsexuell, weiblicher Ph�notyp');
+select i18n.upd_tx('de_DE', 'transsexual phenotype female', 'transsexuell, weiblicher Phänotyp');
 select i18n.upd_tx('de_DE', 'h', 'h');
 select i18n.upd_tx('de_DE', 'hermaphrodite', 'Hermaphrodit');
 
 select i18n.upd_tx('de_DE', 'doctor', 'Arzt');
 select i18n.upd_tx('de_DE', 'nurse', 'Arzthelferin');
-select i18n.upd_tx('de_DE', 'secretary', 'Sekret�rin');
+select i18n.upd_tx('de_DE', 'secretary', 'Sekretärin');
 
 select i18n.upd_tx('de_DE', 'clinical', 'medizinisch');
-select i18n.upd_tx('de_DE', 'personal', 'pers�nlich');
+select i18n.upd_tx('de_DE', 'personal', 'persönlich');
 select i18n.upd_tx('de_DE', 'administrative', 'Verwaltung');
 select i18n.upd_tx('de_DE', 'review lab', 'Labor durchsehen');
 select i18n.upd_tx('de_DE', 'review docs', 'Dokumente durchsehen');
 select i18n.upd_tx('de_DE', 'FYI', 'zur Kenntnisnahme');
 select i18n.upd_tx('de_DE', 'memo', 'Memo');
 select i18n.upd_tx('de_DE', 'noted at age', 'aufgefallen im Alter von');
-select i18n.upd_tx('de_DE', 'unreviewed documents for patient', 'neue Dokumente f�r Patient');
+select i18n.upd_tx('de_DE', 'unreviewed documents for patient', 'neue Dokumente für Patient');
 
 select i18n.upd_tx('de_DE', ' (closed)', ' (beendet)');
 
 -- =============================================
 -- do simple revision tracking
 select log_script_insertion('$RCSfile: gmUebersetzung.sql,v $', '$Revision: 1.13 $');
-
--- =============================================
--- $Log: gmUebersetzung.sql,v $
--- Revision 1.13  2006-05-24 12:11:00  ncq
--- - missing ;
---
--- Revision 1.12  2006/05/20 18:56:20  ncq
--- - translate "closed" for episodes
---
--- Revision 1.11  2006/05/16 16:01:35  ncq
--- - translate a bunch of strings
---
--- Revision 1.10  2006/01/09 13:46:19  ncq
--- - adjust to schema "i18n" qualification
---
--- Revision 1.9  2005/09/19 16:38:52  ncq
--- - adjust to removed is_core from gm_schema_revision
---
--- Revision 1.8  2005/07/14 21:31:43  ncq
--- - partially use improved schema revision tracking
---
--- Revision 1.7  2005/06/10 07:22:09  ncq
--- - translate Canada to German
---
--- Revision 1.6  2005/06/07 20:58:48  ncq
--- - add some translated countries
---
--- Revision 1.5  2005/05/17 08:18:22  ncq
--- - RFE -> BA
---
--- Revision 1.4  2005/05/04 08:57:33  ncq
--- - translate "Germany"
---
--- Revision 1.3  2005/04/14 18:26:53  ncq
--- - translate gender stuff
---
--- Revision 1.2  2005/04/12 10:08:57  ncq
--- - add some translations
---
--- Revision 1.1  2005/03/31 19:15:41  ncq
--- - consolidate translations
---
diff --git a/server/sql/country.specific/de/gmVornamen.sql b/server/sql/country.specific/de/gmVornamen.sql
index 3e412bf..ef43e40 100644
--- a/server/sql/country.specific/de/gmVornamen.sql
+++ b/server/sql/country.specific/de/gmVornamen.sql
@@ -1,9 +1,6 @@
 -- =============================================
 -- GNUmed first name to gender mappings
 
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/country.specific/de/gmVornamen.sql,v $
--- $Revision: 1.7 $
-
 -- license: GPL v2 or later
 -- author (of script file): Karsten Hilbert <Karsten.Hilbert at gmx.net>
 
@@ -151,7 +148,6 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Aloisia', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Aloys', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Aloysius', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Alpaslan', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('Alph�a', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Alphaea', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Alphonse', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Alrun', 'f');
@@ -189,7 +185,6 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Andizej', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Andja', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Andjela', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Ando', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('Andr�', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Andre', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Andrea', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Andreas', 'm');
@@ -373,7 +368,7 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Baldur', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Baltharsar', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Balwant', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Barbara', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('B�rbel', 'f');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Bärbel', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Barthlomeus', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Bartosz', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Baschira', 'm');
@@ -457,7 +452,7 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Birsen', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Birte', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Birthe', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Bjoern', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('Bj�rn', 'm');
+INSERT into dem.name_gender_map(name,gender) VALUES ('BjÖrn', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Blandine', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Blanka', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Blaz', 'm');
@@ -475,7 +470,6 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Bogumila', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Boguslaw', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Boje', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Bonifortis', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('B�rge', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Boris', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Borko', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Boroujerdi', 'm');
@@ -510,7 +504,7 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Burkhard', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Bururije', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Busra', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Byron', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('C�cilie', 'f');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Cäcilie', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Caecilia', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Caecilie', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Cahide', 'f');
@@ -602,7 +596,7 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Cindy-Jane', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Ciril', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Cirsten', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Claas', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('Cl�re', 'f');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Claire', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Clarissa', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Clas', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Claudia', 'f');
@@ -685,7 +679,6 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Detlef', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Detlev', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Dewi', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Dezso', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('Dezs�', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Diana', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Diane', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Didier', 'm');
@@ -749,9 +742,9 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Dorothea', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Dorothee', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Dorrit', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Dorte', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('D�rte', 'f');
+INSERT into dem.name_gender_map(name,gender) VALUES ('DÖrte', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Dorthe', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('D�rthe', 'f');
+INSERT into dem.name_gender_map(name,gender) VALUES ('DÖrthe', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Douglas', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Dragan', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Dragica', 'f');
@@ -908,7 +901,7 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Erdmuth', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Eremine', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Erguel', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Erguen', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('Erg�n', 'm');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Ergün', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Erhard', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Erharda', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Erhardt', 'm');
@@ -932,7 +925,7 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Erwald', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Erwin', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Erwine', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Eryk', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('Erzs�bet', 'f');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Erzsebet', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Esad', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Eskil', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Esma', 'f');
@@ -965,7 +958,6 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Ewa', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Ewald', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Ewgenija', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Eyup', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('Ey�p', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Eyyiphan', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Fabian', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Fabienne', 'm');
@@ -1192,9 +1184,6 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Giuseppe', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gladys', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gloria', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Goetz', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('G�khan', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('G�kmen', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('G�n�l', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gordon', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gosbert', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Goswin', 'm');
@@ -1202,7 +1191,7 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Gottfried', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gottfrieda', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gotthard', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gottlieb', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('G�tz', 'm');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Götz', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Govind', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gradus', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gratia', 'f');
@@ -1238,11 +1227,6 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Guido', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Guillaume', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Guiseppe', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Guitty', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('G�lsen', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('G�lseren', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('G�ls�m', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('G�ltekin', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('G�lten', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gunda', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gunde', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gundemaris', 'f');
@@ -1251,23 +1235,19 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Gundibalda', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gundibaldis', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gundolf', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gundula', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('G�ner', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gunhilde', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gunnar', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gunter', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('G�nter', 'm');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Günter', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gunthard', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gunther', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('G�nther', 'm');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Günther', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gunthilde', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Guntram', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('G�rkan', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gustav', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Guta', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('G�thner', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gwendolen', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Gyde', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('Habed�n', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Habib', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Habidullah', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Hacer', 'f');
@@ -1319,7 +1299,7 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Hans-Peter', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Hans-Werner', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Hansjoachim', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Hansjoerg', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('Hansj�rg', 'm');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Hansjörg', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Hanz', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Harald', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Hardy', 'm');
@@ -1455,7 +1435,6 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Hiltrud', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Hinnerk', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Hinrich', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Hinrika', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('H�bke', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Holdy', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Holger', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Holm', 'm');
@@ -1473,13 +1452,9 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Huesniye', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Hugo', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Hugolinde', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Hugues', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('H�lya', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Huriye', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('H�segin', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Husein', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Huseyin', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('H�seyin', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('H�sne', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Hussein', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Hydril', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Ian', 'm');
@@ -1681,7 +1656,6 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Jessika', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Jette', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Jil', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Jiri', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('Jo�', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Joachim', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Joan', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Joanina', 'f');
@@ -1707,9 +1681,9 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Jonathan', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Joni', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Jonny', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Jordanis', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('J�rg', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('J�rk', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('J�rn', 'm');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Jörg', 'm');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Jörk', 'm');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Jörn', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Joscha', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Jose', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Josef', 'm');
@@ -1745,8 +1719,8 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Julitta', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Julius', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Jura', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Jurek', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('J�rg', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('J�rgen', 'm');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Jürg', 'm');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Jürgen', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Juri', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Justin', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Justina', 'f');
@@ -1810,10 +1784,10 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Katalin', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Katarina', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Katarzyna', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Katayon', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('K�te', 'f');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Käte', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Katharina', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Katharine', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('K�the', 'f');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Käthe', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Katherina', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Katherine', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Kathi', 'f');
@@ -2277,7 +2251,6 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Mesut', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Meta', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Mete', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Metin', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('Mevl�de', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Mia', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Micha', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Michael', 'm');
@@ -2349,20 +2322,17 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Mouss', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Moussa', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Muammer', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Mubiti', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('M�cella', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Muelluefer', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Muhammed', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Muharem', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Muharrem', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Muhittin', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Mumirna', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('M�nir', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Muradiye', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Murat', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Muriel', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Murielle', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Musa', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('M�slum', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Mussa', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Mustafa', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Mustapha', 'm');
@@ -2510,7 +2480,6 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Odette', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Odilo', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Oettmer', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Oguen', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('Og�n', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Oguzhan', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Okan', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Oktay', 'm');
@@ -2630,7 +2599,7 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Raina', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Rainer', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Raissa', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Ralf', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('Ralf-G�nther', 'm');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Ralf-Günther', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Ralfh', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Ralph', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Ramajana', 'f');
@@ -2715,7 +2684,7 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Riza', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Rob', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Roben', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Robert', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('Robert johannes', 'm');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Robert Johannes', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Roberta', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Roberto', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Robin', 'm');
@@ -2780,14 +2749,13 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Ruby', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Rudhard', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Rudi', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Rudibert', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('R�diger', 'm');
+INSERT into dem.name_gender_map(name,gender) VALUES ('RÜdiger', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Rudolf', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Rudolph', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Rudy', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Ruediger', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Rumen', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Rumi', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('R�na-Magdalena', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Rupert', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Russel', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Rut', 'f');
@@ -2861,7 +2829,6 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Scharareh', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Scharief', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Scharif', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Schikri', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('Sch�kriqe', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Sebasatian', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Sebastean', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Sebastian', 'm');
@@ -3010,18 +2977,15 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Solveig', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Solvejg', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Solvijg', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Sonay', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('S�ng�l', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Sonia', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Sonja', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('S�nke', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('S�nmez', 'm');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Sönke', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Sonnhild', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Sonnhilt', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('S�ntje', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Sophia', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Sophie', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Sophus', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('S�ren', 'm');
+INSERT into dem.name_gender_map(name,gender) VALUES ('Sören', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Stanislaus', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Stanislav', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Stanislaw', 'm');
@@ -3057,14 +3021,9 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Suekren', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Suekrue', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Sueleyman', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Sugandhi', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('S�heyla', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('S�hran', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Sukhuinder', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Suklu', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('S�kran', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('S�kriye', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Suleyman', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('S�leymann', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Suliman', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Sultan', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Sun', 'm');
@@ -3229,7 +3188,6 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Turgay', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Turgut', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Turhan', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Turkan', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('T�rkan', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Tuyetlan', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Ubaldeska', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Udo', 'm');
@@ -3238,7 +3196,6 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Uemit', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Ugur', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Ulf', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Uli', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('�lk�', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Ulla', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Ullrich', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Ulrich', 'm');
@@ -3410,7 +3367,6 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Wolgang', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Wollfgang', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Woplfgang', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Worada', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('W�rz', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Xaver', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Xenia', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Xiaw', 'm');
@@ -3434,10 +3390,8 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Yildiz', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Yildrim', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Yilmaz', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Yoichi', 'm');
-INSERT into dem.name_gender_map(name,gender) VALUES ('Y�cel', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Yueksel', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Yuko', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('Y�ksel', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Yunsu', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Yusuf', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Yves', 'm');
@@ -3472,7 +3426,6 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Zora', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Zoran', 'm');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Zorica', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Zubeyde', 'f');
-INSERT into dem.name_gender_map(name,gender) VALUES ('Z�beyde', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Zumreta', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Zumseta', 'f');
 INSERT into dem.name_gender_map(name,gender) VALUES ('Zvonko', 'm');
@@ -3482,34 +3435,3 @@ INSERT into dem.name_gender_map(name,gender) VALUES ('Zyhra', 'f');
 -- do simple revision tracking
 delete from gm_schema_revision where filename = '$RCSfile: gmVornamen.sql,v $';
 INSERT INTO gm_schema_revision (filename, version) VALUES ('$rcsfile: gmvornamen.sql,v $', '$Revision: 1.7 $');
-
--- =============================================
--- $Log: gmVornamen.sql,v $
--- Revision 1.7  2006-01-06 10:12:02  ncq
--- - add missing grants
--- - add_table_for_audit() now in "audit" schema
--- - demographics now in "dem" schema
--- - add view v_inds4vaccine
--- - move staff_role from clinical into demographics
--- - put add_coded_term() into "clin" schema
--- - put German things into "de_de" schema
---
--- Revision 1.6  2005/09/19 16:38:52  ncq
--- - adjust to removed is_core from gm_schema_revision
---
--- Revision 1.5  2005/07/14 21:31:43  ncq
--- - partially use improved schema revision tracking
---
--- Revision 1.4  2005/04/12 12:13:47  ncq
--- - some manual cleanup
---
--- Revision 1.3  2005/04/12 10:44:26  ncq
--- - converted to "Lower" format
---
--- Revision 1.2  2005/03/01 20:41:49  ncq
--- - use latin1 not latin9 as older servers do not support that, the only
---   difference is the EURO symbol which we do not need here
---
--- Revision 1.1  2005/02/27 18:08:35  ncq
--- - Christoph kindly contributed firstname gender mappings
---
diff --git a/server/sql/country.specific/es/gmDemographics-Data.es.sql b/server/sql/country.specific/es/gmDemographics-Data.es.sql
index 44daffa..2d2e438 100644
--- a/server/sql/country.specific/es/gmDemographics-Data.es.sql
+++ b/server/sql/country.specific/es/gmDemographics-Data.es.sql
@@ -2,8 +2,6 @@
 -- database GIS - spanish counties, according to National Institute of Statistics (http://www.ine.es)
 
 -- ===================================================================
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/country.specific/es/gmDemographics-Data.es.sql,v $
--- $Id: gmDemographics-Data.es.sql,v 1.7 2006-01-09 13:46:19 ncq Exp $
 -- author: Carlos Moro
 -- license: GPL v2 or later
 
@@ -11,9 +9,8 @@
 -- force terminate + exit(3) on errors if non-interactive
 \set ON_ERROR_STOP 1
 
-set client_encoding to 'LATIN1';
 -- ===================================================================
-select i18n.upd_tx('es_ES', 'Spain', 'Espa�a');
+select i18n.upd_tx('es_ES', 'Spain', 'España');
 
 -- Carlos, please reconcile:
 --INSERT into dem.state(code, country, name) VALUES ('AN','ES',i18n.i18n('Andalusia'));
@@ -35,35 +32,35 @@ select i18n.upd_tx('es_ES', 'Spain', 'Espa
 --INSERT into dem.state(code, country, name) VALUES ('VA','ES',i18n.i18n('Valencia'));
 
 -- spanish geographic information (mostly of type 'state')
-INSERT into dem.state(code,country,name) VALUES ('01','ES',i18n.i18n('�lava'));
+INSERT into dem.state(code,country,name) VALUES ('01','ES',i18n.i18n('Álava'));
 INSERT into dem.state(code,country,name) VALUES ('02','ES',i18n.i18n('Albacete'));
 INSERT into dem.state(code,country,name) VALUES ('03','ES',i18n.i18n('Alicante'));
-INSERT into dem.state(code,country,name) VALUES ('04','ES',i18n.i18n('Almer�a'));
+INSERT into dem.state(code,country,name) VALUES ('04','ES',i18n.i18n('Almería'));
 INSERT into dem.state(code,country,name) VALUES ('33','ES',i18n.i18n('Asturias'));
-INSERT into dem.state(code,country,name) VALUES ('05','ES',i18n.i18n('�vila'));
+INSERT into dem.state(code,country,name) VALUES ('05','ES',i18n.i18n('Ávila'));
 INSERT into dem.state(code,country,name) VALUES ('06','ES',i18n.i18n('Badajoz'));
 INSERT into dem.state(code,country,name) VALUES ('07','ES',i18n.i18n('Baleares'));
 INSERT into dem.state(code,country,name) VALUES ('08','ES',i18n.i18n('Barcelona'));
 INSERT into dem.state(code,country,name) VALUES ('09','ES',i18n.i18n('Burgos'));
-INSERT into dem.state(code,country,name) VALUES ('10','ES',i18n.i18n('C�ceres'));
-INSERT into dem.state(code,country,name) VALUES ('11','ES',i18n.i18n('C�diz'));
-INSERT into dem.state(code,country,name) VALUES ('12','ES',i18n.i18n('Castell�n'));
+INSERT into dem.state(code,country,name) VALUES ('10','ES',i18n.i18n('Cáceres'));
+INSERT into dem.state(code,country,name) VALUES ('11','ES',i18n.i18n('Cádiz'));
+INSERT into dem.state(code,country,name) VALUES ('12','ES',i18n.i18n('Castellón'));
 INSERT into dem.state(code,country,name) VALUES ('13','ES',i18n.i18n('Ciudad Real'));
-INSERT into dem.state(code,country,name) VALUES ('14','ES',i18n.i18n('C�rdoba'));
-INSERT into dem.state(code,country,name) VALUES ('15','ES',i18n.i18n('Coru�a'));
+INSERT into dem.state(code,country,name) VALUES ('14','ES',i18n.i18n('Córdoba'));
+INSERT into dem.state(code,country,name) VALUES ('15','ES',i18n.i18n('Coruña'));
 INSERT into dem.state(code,country,name) VALUES ('16','ES',i18n.i18n('Cuenca'));
 INSERT into dem.state(code,country,name) VALUES ('17','ES',i18n.i18n('Gerona'));
 INSERT into dem.state(code,country,name) VALUES ('18','ES',i18n.i18n('Granada'));
 INSERT into dem.state(code,country,name) VALUES ('19','ES',i18n.i18n('Guadalajara'));
-INSERT into dem.state(code,country,name) VALUES ('20','ES',i18n.i18n('Guip�zcoa'));
+INSERT into dem.state(code,country,name) VALUES ('20','ES',i18n.i18n('Guipúzcoa'));
 INSERT into dem.state(code,country,name) VALUES ('21','ES',i18n.i18n('Huelva'));
 INSERT into dem.state(code,country,name) VALUES ('22','ES',i18n.i18n('Huesca'));
-INSERT into dem.state(code,country,name) VALUES ('23','ES',i18n.i18n('Ja�n'));
-INSERT into dem.state(code,country,name) VALUES ('24','ES',i18n.i18n('Le�n'));
-INSERT into dem.state(code,country,name) VALUES ('25','ES',i18n.i18n('L�rida'));
+INSERT into dem.state(code,country,name) VALUES ('23','ES',i18n.i18n('Jaén'));
+INSERT into dem.state(code,country,name) VALUES ('24','ES',i18n.i18n('León'));
+INSERT into dem.state(code,country,name) VALUES ('25','ES',i18n.i18n('Lérida'));
 INSERT into dem.state(code,country,name) VALUES ('27','ES',i18n.i18n('Lugo'));
 INSERT into dem.state(code,country,name) VALUES ('28','ES',i18n.i18n('Madrid'));
-INSERT into dem.state(code,country,name) VALUES ('29','ES',i18n.i18n('M�laga'));
+INSERT into dem.state(code,country,name) VALUES ('29','ES',i18n.i18n('Málaga'));
 INSERT into dem.state(code,country,name) VALUES ('30','ES',i18n.i18n('Murcia'));
 INSERT into dem.state(code,country,name) VALUES ('31','ES',i18n.i18n('Navarra'));
 INSERT into dem.state(code,country,name) VALUES ('32','ES',i18n.i18n('Orense'));
@@ -91,34 +88,3 @@ select dem.gm_upd_default_states();
 -- do simple revision tracking
 delete from gm_schema_revision where filename = '$RCSfile: gmDemographics-Data.es.sql,v $';
 INSERT INTO gm_schema_revision (filename, version) VALUES ('$RCSfile: gmDemographics-Data.es.sql,v $', '$Revision: 1.7 $');
-
--- ===================================================================
--- $Log: gmDemographics-Data.es.sql,v $
--- Revision 1.7  2006-01-09 13:46:19  ncq
--- - adjust to schema "i18n" qualification
---
--- Revision 1.6  2006/01/06 10:12:03  ncq
--- - add missing grants
--- - add_table_for_audit() now in "audit" schema
--- - demographics now in "dem" schema
--- - add view v_inds4vaccine
--- - move staff_role from clinical into demographics
--- - put add_coded_term() into "clin" schema
--- - put German things into "de_de" schema
---
--- Revision 1.5  2005/09/25 17:52:45  ncq
--- - carlos needs to take a look, his data and the data from Jim's file
---   are different
---
--- Revision 1.4  2005/09/19 16:27:05  ncq
--- - update default states
---
--- Revision 1.3  2005/07/14 21:31:43  ncq
--- - partially use improved schema revision tracking
---
--- Revision 1.2  2005/06/10 07:22:53  ncq
--- - translate Spain into Spanish
---
--- Revision 1.1  2005/05/15 12:03:51  ncq
--- - Spanish counties/states
---
diff --git a/server/sql/gmClinicalData.sql b/server/sql/gmClinicalData.sql
index 7862b47..5239825 100644
--- a/server/sql/gmClinicalData.sql
+++ b/server/sql/gmClinicalData.sql
@@ -1,7 +1,5 @@
 -- Project: GNUmed
 -- ===================================================================
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/gmClinicalData.sql,v $
--- $Id: gmClinicalData.sql,v 1.46 2006-05-20 18:56:20 ncq Exp $
 -- license: GPL v2 or later
 -- author: Ian Haywood, Horst Herb
 
@@ -96,7 +94,7 @@ insert into clin.clin_item_type (code, type) values (i18n.i18n('sHxH'), i18n.i18
 -- Leisure activities
 -- Sporting activities (past and present)
 -- Marital status/ Sexuality
--- and a link to spouse�s name, type of work, ethnicity
+-- and a link to spouses name, type of work, ethnicity
 -- Dependents
 -- Diet
 -- Religion
@@ -258,159 +256,3 @@ insert into clin.test_type (
 -- ===================================================================
 -- do simple schema revision tracking
 INSERT INTO gm_schema_revision (filename, version) VALUES('$RCSfile: gmClinicalData.sql,v $', '$Revision: 1.46 $');
-
--- =============================================
--- $Log: gmClinicalData.sql,v $
--- Revision 1.46  2006-05-20 18:56:20  ncq
--- - translate "closed" for episodes
---
--- Revision 1.45  2006/02/10 14:08:58  ncq
--- - factor out EMR structure clinical schema into its own set of files
---
--- Revision 1.44  2006/02/08 15:15:39  ncq
--- - factor our vaccination stuff into its own set of files
--- - remove clin.lnk_vacc_ind2code in favour of clin.coded_term usage
--- - improve comments as discussed on the list
---
--- Revision 1.43  2006/01/09 13:46:19  ncq
--- - adjust to schema "i18n" qualification
---
--- Revision 1.42  2006/01/06 10:12:02  ncq
--- - add missing grants
--- - add_table_for_audit() now in "audit" schema
--- - demographics now in "dem" schema
--- - add view v_inds4vaccine
--- - move staff_role from clinical into demographics
--- - put add_coded_term() into "clin" schema
--- - put German things into "de_de" schema
---
--- Revision 1.41  2006/01/01 17:57:14  ncq
--- - add vaccination indications
---
--- Revision 1.40  2005/11/25 15:07:28  ncq
--- - create schema "clin" and move all things clinical into it
---
--- Revision 1.39  2005/09/19 16:38:51  ncq
--- - adjust to removed is_core from gm_schema_revision
---
--- Revision 1.38  2005/07/14 21:31:42  ncq
--- - partially use improved schema revision tracking
---
--- Revision 1.37  2005/05/17 08:13:49  ncq
--- - prepare "RFE" for translation
---
--- Revision 1.36  2005/05/08 21:50:42  ncq
--- - ranking only makes sense if ranks are different :-)
---
--- Revision 1.35  2005/04/17 16:31:34  ncq
--- - added some strings
---
--- Revision 1.34  2005/03/31 18:02:07  ncq
--- - add more strings for translation
---
--- Revision 1.33  2005/03/31 17:42:43  ncq
--- - soap_cat_ranks, request_status strings
---
--- Revision 1.32  2004/09/29 10:26:40  ncq
--- - basic_unit -> conversion_unit
---
--- Revision 1.31  2004/09/25 13:23:32  ncq
--- - add dummy test orgs for in-house/self-measured/generic external
---
--- Revision 1.30  2004/07/18 11:50:19  ncq
--- - added arbitrary typing of clin_root_items
---
--- Revision 1.29  2004/07/05 18:52:26  ncq
--- - no data for _enum_hx_type needed anymore
---
--- Revision 1.28  2004/05/08 17:37:08  ncq
--- - *_encounter_type -> encounter_type
---
--- Revision 1.27  2004/05/04 09:10:59  ncq
--- - fix your own lab test org
---
--- Revision 1.26  2004/05/04 08:43:28  ncq
--- - meaningful data for test_org "your own practice"
---
--- Revision 1.25  2004/04/30 12:22:31  ihaywood
--- new referral table
--- some changes to old medications tables, but still need more work
---
--- Revision 1.24  2004/04/21 15:35:23  ihaywood
--- new referral table (do we still need gmclinical.form_data then?)
---
--- Revision 1.23  2004/03/18 10:57:20  ncq
--- - several fixes to the data
--- - better constraints on vacc.seq_no/is_booster
---
--- Revision 1.22  2004/03/12 23:15:04  ncq
--- - adjust to id_ -> fk_/pk_
---
--- Revision 1.21  2004/02/18 14:08:29  ncq
--- - add "chart review" encounter type
---
--- Revision 1.20  2004/01/22 23:44:39  ncq
--- - add FSME
---
--- Revision 1.19  2004/01/10 01:29:25  ncq
--- - add test data for test-nurse, test-doctor
---
--- Revision 1.18  2003/12/29 15:29:45  uid66147
--- - staff roles data
--- - more vacc_indications
--- - more vacc_indications -> disease codes
---
--- Revision 1.17  2003/11/22 14:54:33  ncq
--- - add HepA vaccination indication
---
--- Revision 1.16  2003/11/17 11:14:53  sjtan
---
--- (perhaps temporary) extra referencing table for past history.
---
--- Revision 1.15  2003/11/02 10:17:02  ihaywood
--- fixups that crash psql.py
---
--- Revision 1.14  2003/10/26 09:41:03  ncq
--- - truncate -> delete from
---
--- Revision 1.13  2003/10/21 15:04:48  ncq
--- - update vaccination schedules for Germany
---
--- Revision 1.12  2003/10/19 12:58:58  ncq
--- - add vacc route data
---
--- Revision 1.11  2003/08/13 14:31:29  ncq
--- - add some test tyes
---
--- Revision 1.10  2003/07/27 21:57:34  ncq
--- - comment out *semantic* type of coding system ... (what was that intended for anyways?)
---
--- Revision 1.9  2003/05/12 12:43:39  ncq
--- - gmI18N, gmServices and gmSchemaRevision are imported globally at the
---   database level now, don't include them in individual schema file anymore
---
--- Revision 1.8  2003/05/05 12:44:33  ncq
--- - table databases does not exist anymore
---
--- Revision 1.7  2003/05/04 23:59:35  ncq
--- - add comment on encounter types
---
--- Revision 1.6  2003/04/28 20:56:16  ncq
--- - unclash "allergy" in hx type and type of allergic reaction + translations
--- - some useful indices
---
--- Revision 1.5  2003/04/25 13:05:49  ncq
--- - adapt to frontend hookup for encounter types
---
--- Revision 1.4  2003/04/12 15:43:17  ncq
--- - adapted to new gmclinical.sql
---
--- Revision 1.3  2003/04/09 13:50:29  ncq
--- - typos
---
--- Revision 1.2  2003/04/09 13:08:21  ncq
--- - _clinical_ -> _clin_
---
--- Revision 1.1  2003/02/14 10:54:19  ncq
--- - breaking out enumerated data
---
diff --git a/server/sql/gmCountryZones.sql b/server/sql/gmCountryZones.sql
index 0cfc97f..530fc10 100644
--- a/server/sql/gmCountryZones.sql
+++ b/server/sql/gmCountryZones.sql
@@ -6,16 +6,11 @@
 -- as an external database taken from 'tealow_zencart'.
 
 -- license: GPL v2 or later (details at http://gnu.org)
-
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/gmCountryZones.sql,v $
--- $Id: gmCountryZones.sql,v 1.4 2006-01-09 13:46:19 ncq Exp $
 -- ===================================================================
 -- force terminate + exit(3) on errors if non-interactive
 \set ON_ERROR_STOP 1
 
 -- ===================================================================
-set client_encoding to latin1;
-
 select i18n.i18n('state/territory/province/region not available');
 
 -- country AD
@@ -516,10 +511,10 @@ INSERT into dem.state(code, country, name) VALUES ('BE','CH',i18n.i18n('Bern'));
 INSERT into dem.state(code, country, name) VALUES ('FR','CH',i18n.i18n('Freiburg'));
 INSERT into dem.state(code, country, name) VALUES ('GE','CH',i18n.i18n('Geneve'));
 INSERT into dem.state(code, country, name) VALUES ('GL','CH',i18n.i18n('Glarus'));
-INSERT into dem.state(code, country, name) VALUES ('GR','CH',i18n.i18n('Graub�nden'));
+INSERT into dem.state(code, country, name) VALUES ('GR','CH',i18n.i18n('Graubünden'));
 INSERT into dem.state(code, country, name) VALUES ('JU','CH',i18n.i18n('Jura'));
 INSERT into dem.state(code, country, name) VALUES ('LU','CH',i18n.i18n('Luzern'));
-INSERT into dem.state(code, country, name) VALUES ('NE','CH',i18n.i18n('Neuch�tel'));
+INSERT into dem.state(code, country, name) VALUES ('NE','CH',i18n.i18n('Neuchatel'));
 INSERT into dem.state(code, country, name) VALUES ('NW','CH',i18n.i18n('Nidwalden'));
 INSERT into dem.state(code, country, name) VALUES ('OW','CH',i18n.i18n('Obwalden'));
 INSERT into dem.state(code, country, name) VALUES ('SG','CH',i18n.i18n('Sankt Gallen'));
@@ -678,7 +673,7 @@ INSERT into dem.state(code, country, name) VALUES ('RO','DK',i18n.i18n('Roskilde
 INSERT into dem.state(code, country, name) VALUES ('SO','DK',i18n.i18n('Sonderjylland'));
 INSERT into dem.state(code, country, name) VALUES ('ST','DK',i18n.i18n('Storstrom'));
 INSERT into dem.state(code, country, name) VALUES ('VE','DK',i18n.i18n('Vejle'));
-INSERT into dem.state(code, country, name) VALUES ('VJ','DK',i18n.i18n('Vestj�lland'));
+INSERT into dem.state(code, country, name) VALUES ('VJ','DK',i18n.i18n('Vestjælland'));
 INSERT into dem.state(code, country, name) VALUES ('VI','DK',i18n.i18n('Viborg'));
 -- country DM
 INSERT into dem.state(code, country, name) VALUES ('DM-1','DM',i18n.i18n('Dominica territory'));
@@ -2442,25 +2437,3 @@ INSERT into dem.state(code, country, name) VALUES ('MI','ZW',i18n.i18n('Midlands
 -- =============================================
 -- do simple schema revision tracking
 select log_script_insertion('$RCSfile: gmCountryZones.sql,v $', '$Revision: 1.4 $');
-
--- =============================================
--- $Log: gmCountryZones.sql,v $
--- Revision 1.4  2006-01-09 13:46:19  ncq
--- - adjust to schema "i18n" qualification
---
--- Revision 1.3  2006/01/06 10:12:02  ncq
--- - add missing grants
--- - add_table_for_audit() now in "audit" schema
--- - demographics now in "dem" schema
--- - add view v_inds4vaccine
--- - move staff_role from clinical into demographics
--- - put add_coded_term() into "clin" schema
--- - put German things into "de_de" schema
---
--- Revision 1.2  2005/10/12 22:29:11  ncq
--- - comment out states/add in countries which (would) error out
---
--- Revision 1.1  2005/09/25 17:45:16  ncq
--- - we now got states for pretty much every country
---
---
diff --git a/server/sql/test-data/test_data-James_Kirk.sql b/server/sql/test-data/test_data-James_Kirk.sql
index 41967f6..b17b1c6 100644
--- a/server/sql/test-data/test_data-James_Kirk.sql
+++ b/server/sql/test-data/test_data-James_Kirk.sql
@@ -3,8 +3,6 @@
 
 -- author: Karsten Hilbert <Karsten.Hilbert at gmx.net>
 -- license: GPL v2 or later
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/test-data/test_data-James_Kirk.sql,v $
--- $Revision: 1.81 $
 -- =============================================
 -- force terminate + exit(3) on errors if non-interactive
 \set ON_ERROR_STOP 1
@@ -144,7 +142,6 @@ insert into blobs.doc_obj (doc_id, seq_idx, comment, fk_intended_reviewer, data)
 	'a small picture of Kirk',
 	(select pk_staff from dem.v_staff where firstnames='Leonard Horatio' and lastnames='McCoy' and dob='1920-1-20+2:00'),
 	E'GIF89a0\\0000\\000\\325\\000\\000\\377\\377\\377\\275\\234\\234\\224sk\\275\\204s\\326\\275\\265\\224{s\\275\\214{\\245{k\\214cR\\275\\234\\214{ZJ\\255{c\\316\\255\\234\\306\\224{\\245sZ\\234kRcB1\\204R91!\\030\\347\\316\\275\\306\\255\\234cJ9\\265\\204cB)\\030Z9!\\316\\255\\224\\306\\245\\214\\265\\224{sR9\\214cBsZBB1!)\\030\\010\\336\\306\\255\\275\\245\\21491)\\234\\204k\\214sZ\\020\\010\\000B)\\010\\326\\306\\255RB)cZJ\\357\\347\\326RJ9\\214{R\\255\\234kskR\\275\\255{\\214\\204Zss [...]
---	'GIF89a0\\0000\\000�\\000\\000����\\234\\234\\224sk�\\204sֽ�\\224{s�\\214{�{k\\214cR�\\234\\214{ZJ�{cέ\\234�\\224{�sZ\\234kRcB1\\204R91!\\030�νƭ\\234cJ9�\\204cB)\\030Z9!έ\\224ƥ\\214�\\224{sR9\\214cBsZBB1!)\\030\\010�ƭ��\\21491)\\234\\204k\\214sZ\\020\\010\\000B)\\010�ƭRB)cZJ���RJ9\\214{R�\\234kskR��{\\214\\204Zsskkkc))!\\234\\234{\\030\\030\\020BJ!��\\224��\\23419J\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000,\\000\\000\\000\\0000\\0000\\000@\\006�@\\204P [...]
 );
 set client_encoding = 'latin1';
 
@@ -733,287 +730,3 @@ insert into dem.provider_inbox (
 -- do simple schema revision tracking
 select log_script_insertion('$RCSfile: test_data-James_Kirk.sql,v $', '$Revision: 1.81 $');
 
--- =============================================
--- $Log: test_data-James_Kirk.sql,v $
--- Revision 1.81  2006-07-17 18:51:10  ncq
--- - Kirk was born in Canada so adjust for the proper time zone
---
--- Revision 1.80  2006/06/18 18:19:14  ncq
--- - newer PGs teach us to use proper encoding (!) when inserting (!) binary data ...
---
--- Revision 1.79  2006/05/28 15:23:33  ncq
--- - add a couple more episodes, also trigger duplicate narrative bug
---   so we can debug it
---
--- Revision 1.78  2006/05/16 08:22:39  ncq
--- - unreviewed docs auto-create virtual inbox messages
---   now so remove explicit one
---
--- Revision 1.77  2006/05/10 13:05:22  ncq
--- - add two more intox messages
--- - set ufk_context to Kirk ID on "review docs" message
---
--- Revision 1.76  2006/04/29 18:19:38  ncq
--- - comment more columns
--- - add fk_encounter/fk_episode to doc_med
--- - trigger to make sure episode is linked to doc in doc_med OR lnk_doc_med2episode only
--- - doc_med.data now TEXT ! not timestamp (needs to be able to be fuzzy)
--- - adjust test BLOBs to new situation
---
--- Revision 1.75  2006/03/06 09:45:17  ncq
--- - cleanup
---
--- Revision 1.74  2006/03/04 16:25:41  ncq
--- - adjust to vaccination schema changes
---
--- Revision 1.73  2006/02/27 22:39:33  ncq
--- - spell out rfe/aoe
---
--- Revision 1.72  2006/02/27 11:30:27  ncq
--- - add post-AE state health issue which also is an operation
---
--- Revision 1.71  2006/02/19 13:47:14  ncq
--- - add review comment to blobs reviews
---
--- Revision 1.70  2006/02/13 08:49:07  ncq
--- - add some reviews
---
--- Revision 1.69  2006/01/27 22:27:57  ncq
--- - fk_intended_reviewer in doc_obj now references dem.staff(pk)
---
--- Revision 1.68  2006/01/23 22:10:57  ncq
--- - staff.sign -> .short_alias
---
--- Revision 1.67  2006/01/22 18:14:43  ncq
--- - add McCoy provider inbox message about Kirk Vietnam holiday pics
---
--- Revision 1.66  2006/01/13 13:56:29  ncq
--- - doc_obj must have non-null .data even if just a dummy
---
--- Revision 1.65  2006/01/11 13:31:20  ncq
--- - id -> pk
---
--- Revision 1.64  2006/01/06 10:12:03  ncq
--- - add missing grants
--- - add_table_for_audit() now in "audit" schema
--- - demographics now in "dem" schema
--- - add view v_inds4vaccine
--- - move staff_role from clinical into demographics
--- - put add_coded_term() into "clin" schema
--- - put German things into "de_de" schema
---
--- Revision 1.63  2005/12/29 21:48:09  ncq
--- - clin.vaccine.id -> pk
--- - remove clin.vaccine.last_batch_no
--- - add clin.vaccine_batches
--- - adjust test data and country data
---
--- Revision 1.62  2005/12/06 13:26:55  ncq
--- - clin.clin_encounter -> clin.encounter
--- - also id -> pk
---
--- Revision 1.61  2005/12/05 19:06:38  ncq
--- - clin.clin_episode -> clin.episode
---
--- Revision 1.60  2005/12/04 09:48:57  ncq
--- - add fk_intended_reviewer values to doc_obj and test_results
--- - adjust to renamed clin.health_issue
---
--- Revision 1.59  2005/11/25 15:07:28  ncq
--- - create schema "clin" and move all things clinical into it
---
--- Revision 1.58  2005/11/11 23:08:15  ncq
--- - test_result.technically_abnormal is now abnormality_indicator
--- - blobs live in schema blobs now
---
--- Revision 1.57  2005/10/24 19:13:00  ncq
--- - blobs.* schema qualification
---
--- Revision 1.56  2005/09/22 15:42:38  ncq
--- - remove fk_provider
---
--- Revision 1.55  2005/09/19 16:27:48  ncq
--- - adjust to rfe/aoe
---
--- Revision 1.54  2005/07/14 21:31:43  ncq
--- - partially use improved schema revision tracking
---
--- Revision 1.53  2005/04/08 10:01:28  ncq
--- - adapt to changed coding of narrative
---
--- Revision 1.52  2005/03/21 20:11:36  ncq
--- - adjust family history
---
--- Revision 1.51  2005/03/20 18:10:30  ncq
--- - adjust family history
---
--- Revision 1.50  2005/03/14 14:47:37  ncq
--- - adjust to id_patient -> pk_patient
--- - add family history on Kirk's brother
---
--- Revision 1.49  2005/03/01 20:42:21  ncq
--- - cleanup, basically
---
--- Revision 1.48  2005/02/20 09:46:08  ihaywood
--- demographics module with load a patient with no exceptions
---
--- Revision 1.47  2005/02/15 18:27:24  ncq
--- - test_result.id -> pk
---
--- Revision 1.46  2005/02/13 15:08:23  ncq
--- - add names of actors and some comments
---
--- Revision 1.45  2005/02/12 13:49:14  ncq
--- - identity.id -> identity.pk
--- - allow NULL for identity.fk_marital_status
--- - subsequent schema changes
---
--- Revision 1.44  2004/12/18 09:58:13  ncq
--- - vaccinate according to Starfleet rules
---
--- Revision 1.43  2004/11/28 14:38:18  ncq
--- - some more deletes
--- - use new method of episode naming
--- - this actually bootstraps again
---
--- Revision 1.42  2004/11/24 15:42:00  ncq
--- - need clin_narrative with is_episode_name *before* inserting clin_root_items
---   which signal changes since the trigger crawls v_pat_episodes for the
---   patient PK and unnamed episodes don't show up there
---
--- Revision 1.41  2004/11/21 21:01:44  ncq
--- - episode: is_active -> is_open
---
--- Revision 1.40  2004/11/16 18:59:57  ncq
--- - adjust to episode naming changes
---
--- Revision 1.39  2004/10/11 19:36:32  ncq
--- - id -> pk
---
--- Revision 1.38  2004/09/29 10:31:11  ncq
--- - test_type.id -> pk
--- - basic_unit -> conversion_unit
---
--- Revision 1.37  2004/09/25 13:25:56  ncq
--- - is_significant -> clinically_relevant
---
--- Revision 1.36  2004/09/20 21:18:26  ncq
--- - add small picture for Kirk
---
--- Revision 1.35  2004/09/17 20:32:27  ncq
--- - IF there is a health issue it MUST have a label, there is no default
---
--- Revision 1.34  2004/09/17 20:18:10  ncq
--- - clin_episode_id_seq -> *_pk_seq
---
--- Revision 1.33  2004/09/02 00:43:20  ncq
--- - add Star Fleet Staff Code as external_id
---
--- Revision 1.32  2004/08/18 08:28:56  ncq
--- - put Kirk on some vaccination schedules
---
--- Revision 1.31  2004/07/28 15:47:00  ncq
--- - improve data
---
--- Revision 1.30  2004/07/12 17:24:02  ncq
--- - code diagnoses with new structure now
---
--- Revision 1.29  2004/07/02 15:00:10  ncq
--- - bring rfe/aoe/diag/coded_diag tables/views up to snuff and use them
---
--- Revision 1.28  2004/07/02 00:28:54  ncq
--- - clin_working_diag -> clin_coded_diag + index fixes therof
--- - v_pat_diag rewritten for clin_coded_diag, more useful now
--- - v_patient_items.id_item -> pk_item
--- - grants fixed
--- - clin_rfe/aoe folded into clin_narrative, that enhanced by
---   is_rfe/aoe with appropriate check constraint logic
--- - test data adapted to schema changes
---
--- Revision 1.27  2004/06/26 23:45:50  ncq
--- - cleanup, id_* -> fk/pk_*
---
--- Revision 1.26  2004/06/26 07:33:55  ncq
--- - id_episode -> fk/pk_episode
---
--- Revision 1.25  2004/06/02 13:46:46  ncq
--- - setting default session timezone has incompatible syntax
---   across version range 7.1-7.4, henceforth specify timezone
---   directly in timestamp values, which works
---
--- Revision 1.24  2004/06/02 00:14:46  ncq
--- - add time zone setting
---
--- Revision 1.23  2004/06/01 10:15:18  ncq
--- - fk_patient, not id_patient in allergy_state
---
--- Revision 1.22  2004/05/30 21:03:29  ncq
--- - encounter_type.id -> encounter_type.pk
---
--- Revision 1.21  2004/05/13 00:10:24  ncq
--- - test data for regression testing lab handling added
---
--- Revision 1.20  2004/05/08 17:37:08  ncq
--- - *_encounter_type -> encounter_type
---
--- Revision 1.19  2004/05/06 23:32:44  ncq
--- - internal_name now local_name
--- - technically_abnormal now text
---
--- Revision 1.18  2004/05/02 19:26:31  ncq
--- - add diagnoses
---
--- Revision 1.17  2004/04/17 11:54:16  ncq
--- - v_patient_episodes -> v_pat_episodes
---
--- Revision 1.16  2004/03/23 17:34:50  ncq
--- - support and use optionally cross-provider unified test names
---
--- Revision 1.15  2004/03/23 02:34:17  ncq
--- - fix dates on test results
--- - link test results to lab requests
---
--- Revision 1.14  2004/03/19 10:56:46  ncq
--- - allergy now has reaction -> narrative
---
--- Revision 1.13  2004/03/18 18:33:05  ncq
--- - added some lab results
---
--- Revision 1.12  2004/03/18 11:07:56  ncq
--- - fix integrity violations
---
--- Revision 1.11  2004/03/18 10:57:20  ncq
--- - several fixes to the data
--- - better constraints on vacc.seq_no/is_booster
---
--- Revision 1.10  2004/01/15 14:52:10  ncq
--- - fix id_patient breakage
---
--- Revision 1.9  2004/01/14 10:42:05  ncq
--- - use xlnk_identity
---
--- Revision 1.8  2004/01/06 23:44:40  ncq
--- - __default__ -> xxxDEFAULTxxx
---
--- Revision 1.7  2003/12/29 16:06:10  uid66147
--- - adjust to new tables: use fk_provider, lnk_vacc2vacc_def
--- - add document BLOBs (data needs to be imported separately)
---
--- Revision 1.6  2003/11/27 00:18:47  ncq
--- - vacc_def links to vacc_regime now
---
--- Revision 1.5  2003/11/23 23:35:11  ncq
--- - names.title -> identity.title
---
--- Revision 1.4  2003/11/16 19:32:17  ncq
--- - clin_when in clin_root_item
---
--- Revision 1.3  2003/11/13 09:47:29  ncq
--- - use clin_date instead of date_given in vaccination
---
--- Revision 1.2  2003/11/09 17:58:46  ncq
--- - add an allergy
---
--- Revision 1.1  2003/10/31 22:53:27  ncq
--- - started collection of test data
---
diff --git a/server/sql/test-data/test_data-Kirk_hospital_stay-dynamic.sql b/server/sql/test-data/test_data-Kirk_hospital_stay-dynamic.sql
index 60cd698..c1d29ee 100644
--- a/server/sql/test-data/test_data-Kirk_hospital_stay-dynamic.sql
+++ b/server/sql/test-data/test_data-Kirk_hospital_stay-dynamic.sql
@@ -6,16 +6,11 @@
 -- author: Karsten Hilbert <Karsten.Hilbert at gmx.net>
 -- license: GPL v2 or later
 --
--- $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/server/sql/test-data/test_data-Kirk_hospital_stay-dynamic.sql,v $
--- $Revision: 1.2 $
 -- =============================================
 
 -- force terminate + exit(3) on errors if non-interactive
 \set ON_ERROR_STOP 1
 
-set default_transaction_read_only to off;
-
---begin;
 -- =============================================
 delete from clin.episode where
 	fk_encounter in (
@@ -89,19 +84,3 @@ insert into clin.hospital_stay (
 -- =============================================
 -- do simple schema revision tracking
 select gm.log_script_insertion('$RCSfile: test_data-Kirk_hospital_stay-dynamic.sql,v $', '$Revision: 1.2 $');
-
--- comment out the "rollback" if you want to
--- really store the above patient data
---rollback;
---commit;
-
--- =============================================
--- $Log: test_data-Kirk_hospital_stay-dynamic.sql,v $
--- Revision 1.2  2009-07-09 16:50:01  ncq
--- - cleanup
--- - properly detect episode
---
--- Revision 1.1  2009/05/13 10:34:58  ncq
--- - add a hospital stay
---
---
\ No newline at end of file
diff --git a/server/sql/v14-v15/python/v15-import-atc.py b/server/sql/v14-v15/python/v15-import-atc.py
index bf05b50..56542ea 100644
--- a/server/sql/v14-v15/python/v15-import-atc.py
+++ b/server/sql/v14-v15/python/v15-import-atc.py
@@ -7,7 +7,8 @@
 # Author: karsten.hilbert at gmx.net
 # 
 #==============================================================
-import os, codecs
+import os
+import io
 
 from Gnumed.pycommon import gmPG2
 from Gnumed.pycommon import gmTools
@@ -101,7 +102,7 @@ def run(conn=None):
 	data_sources = rows[0]
 
 	data_fname = os.path.join('..', 'sql', 'v14-v15', 'data', 'atc_only-utf8.csv')
-	csv_file = codecs.open(data_fname, 'rU', 'utf8', 'replace')
+	csv_file = io.open(data_fname, mode = 'rt', encoding = 'utf8', errors = 'replace')
 	atc_reader = gmTools.unicode_csv_reader(csv_file, delimiter = ",", quotechar = '"', dict = True, fieldnames = [u'atc', u'en', u'fr', u'de'])
 
 	for atc_line in atc_reader:
diff --git a/server/sql/v19-v20/dynamic/v20-release_notes-dynamic.sql b/server/sql/v19-v20/dynamic/v20-release_notes-dynamic.sql
index a5525b0..aa6f4fd 100644
--- a/server/sql/v19-v20/dynamic/v20-release_notes-dynamic.sql
+++ b/server/sql/v19-v20/dynamic/v20-release_notes-dynamic.sql
@@ -17,18 +17,14 @@ INSERT INTO dem.message_inbox (
 ) VALUES (
 	(select pk from dem.staff where db_user = 'any-doc'),
 	(select pk_type from dem.v_inbox_item_type where type = 'memo' and category = 'administrative'),
-	'Release Notes for GNUmed 1.5.10 (database v20.10)',
+	'Release Notes for GNUmed 1.5.10 (database v20.11)',
 	'GNUmed 1.5.10 Release Notes:
 
-	1.5.10
+	20.11
 
-FIX: patient merging, again [thanks Marc]
-
-	20.10
-
-FIX: pg_trgm placement and use
-FIX: clin.substance_intake.fk_episode SET NOT NULL
+FIX: better REINDEXing before upgrade [thanks Jim]
+FIX: clin.procedure.is_ongoing=FALSE IF clin.procedure.clin_end < now() [thanks pg_upgrade]
 ');
 
 -- --------------------------------------------------------------
-select gm.log_script_insertion('v20-release_notes-dynamic.sql', '20.10');
+select gm.log_script_insertion('v20-release_notes-dynamic.sql', '20.11');
diff --git a/server/sql/v19-v20/fixups/v20-clin-procedure-fixup.sql b/server/sql/v19-v20/fixups/v20-clin-procedure-fixup.sql
new file mode 100644
index 0000000..148f37b
--- /dev/null
+++ b/server/sql/v19-v20/fixups/v20-clin-procedure-fixup.sql
@@ -0,0 +1,23 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+update clin.procedure set
+	is_ongoing = False
+where
+	is_ongoing is True
+		and
+	clin_end is not null
+		and
+	clin_end < (now() + '15 minutes'::interval)
+;
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v20-clin-procedure-fixup.sql', '20.11');
diff --git a/server/sql/v20-v21/data/v21-Begleitbrief.tex b/server/sql/v20-v21/data/v21-Begleitbrief.tex
new file mode 100644
index 0000000..66737c4
--- /dev/null
+++ b/server/sql/v20-v21/data/v21-Begleitbrief.tex
@@ -0,0 +1,176 @@
+%------------------------------------------------------------------
+% Based on:
+%
+% Deutsche LaTeX Briefvorlage von Jan-Philip Gehrcke
+% http://gehrcke.de -- jgehrcke at googlemail.com
+% November 2009, Aktualisierung Januar 2013
+%
+% Stark angepaßt von Karsten.Hilbert at gmx.net für GNUmed.
+%
+% use with pdflatex, NOT xelatex
+%
+% License: GPL v2 or later
+%------------------------------------------------------------------
+
+\documentclass[
+	paper=a4,
+	BCOR=0mm,							% keine BindeCORrektur
+	DIN,
+	version=last,
+	enlargefirstpage=on,
+	fontsize=11pt,
+	foldmarks=true,
+	foldmarks=HP,
+	parskip=full,						% Absätze mit Leerzeilen trennen, kein Einzug
+	fromurl=false,						% explizit in der Fußzeile
+	fromemail=false,					% explizit in der Fußzeile
+	fromfax=false,						% explizit in der Fußzeile
+	fromphone=false,					% explizit in der Fußzeile
+	fromlogo=true,
+	fromalign=center,
+	fromrule=afteraddress,
+	symbolicnames=true,
+	headsepline=true,
+	footsepline=true,
+	pagenumber=footright
+]{scrlttr2}
+\usepackage{scrlayer-scrpage}			% Kopf- und Fußzeilen
+\usepackage[cjkjis,graphics]{ucs}		% lots of UTF8 symbols, breaks with xelatex
+\usepackage[utf8x]{inputenc}			% content is UTF8, breaks with xelatex
+\usepackage[T1]{fontenc}				% fonts are T1
+\usepackage[ngerman]{babel}				% Deutsch und Trennung
+\usepackage{marvosym}					% Symbole: Handy, Telefon, E-Mail
+\usepackage{textcomp}					% Symbole für Textmodus zum Escapen
+\usepackage{lmodern}					% sans serif Latin Modern
+\usepackage{longtable}					% Tabellen über mehrere Seiten
+\usepackage{tabu}						% bessere Tabellen
+\usepackage{graphicx}					% Grafiken laden (Logo und Unterschrift)
+\usepackage[space]{grffile}				% besserer Zugriff auf Grafikdateien
+\usepackage{lastpage}					% easy access to page number of last page
+\usepackage{calc}						% \widthof (für signature)
+\usepackage{hyperref}					% aktive URLs
+
+
+% Definiere Grundschrift: sans serif Latin Modern
+\renewcommand*\familydefault{\sfdefault}
+
+
+\begin{document}
+
+
+% Kopfzeile ab zweiter Seite
+\lehead{$<title::::>$ $<lastname::::>$, $<firstname::::>$ ($<date_of_birth::%d.%B %Y::>$)}
+\lohead{$<title::::>$ $<lastname::::>$, $<firstname::::>$ ($<date_of_birth::%d.%B %Y::>$)}
+\cehead{}
+\cohead{}
+\rehead{Seite \thepage/\pageref{LastPage}}
+\rohead{Seite \thepage/\pageref{LastPage}}
+
+
+% Absenderdetails
+\setkomavar{fromname}{$<current_provider::::>$, FA für $<current_provider_external_id::Fachgebiet//Ärztekammer::50>$}
+\setkomavar{fromaddress}{\small
+	$<praxis::%(praxis)s, %(branch)s::120>$\\
+	$<praxis_address::%(street)s %(number)s (%(subunit)s), %(postcode)s %(urb)s::60>$
+}
+\setkomavar{fromlogo}{$<data_snippet::praxis-logo//\includegraphics[width=30mm]{%s}//image/png//.png::250>$}%$
+\setkomavar{backaddress}{$<current_provider::::>$\\$<praxis_address::%(street)s %(number)s\\%(postcode)s %(urb)s::60>$}
+
+
+% Geschäftszeile
+\setkomavar{yourref}{$<free_text::Angabe in "Ihr Zeichen"::40>$}
+\setkomavar{yourmail}{$<free_text::Angabe in "Ihr Schreiben vom"::20>$}
+\setkomavar{myref}{$<free_text::Angabe in "Unser Zeichen"::40>$}
+\setkomavar{date}{$<today::%d.%B %Y::50>$}
+\setkomavar{place}{$<praxis_address::%(urb)s::120>$}
+
+
+% Betreff, nämlich Patientendaten
+\setkomavar{subject}[]{
+	$<free_text::Betreff für den Brief::120>$\\
+	Patient: $<title::::>$ $<firstname::::>$ $<lastname::::>$ (geb $<date_of_birth::%d.%B %Y::>$)\\
+	Adresse: $<adr_street::home::>$ $<adr_number::home::>$, $<adr_postcode::home::>$ $<adr_location::home::>$
+}
+
+
+% Unterschrift
+\setkomavar{signature}{
+	\centering
+	$<data_snippet::autograph-$<<current_provider::::>>$//\includegraphics[width=30mm]{%s}\\//image/png//.png::250>$\rule{\widthof{\tiny (Der Unterzeichner haftet nicht für unsignierte Änderungen des Inhalts.)}}{.1pt}\\
+	$<current_provider::::>$\\
+	{\tiny (Der Unterzeichner haftet nicht für unsignierte Änderungen des Inhalts.)}
+}
+\renewcommand*{\raggedsignature}{\raggedright}
+\makeatletter
+\@setplength{sigbeforevskip}{1.8cm}							% Definiere vertikalen Abstand vor der Unterschrift
+\makeatother
+
+
+% Fußzeile 1.Seite
+\setkomavar{firstfoot}{%
+	\rule{\textwidth}{.3pt}
+	\parbox[t]{\textwidth}{
+		\tiny
+		\begin{tabular}[t]{ll}%
+%			\multicolumn{2}{l}{Erreichbarkeit:}\\
+			\Telefon       & $<praxis_comm::workphone::60>$\\
+			\FAX           & $<praxis_comm::fax::60>$\\
+			\Email         & \href{mailto:$<praxis_comm::email::60>$}{$<praxis_comm::email::60>$}\\
+			\ComputerMouse & \href{http://$<praxis_comm::web::60>$}{$<praxis_comm::web::60>$}\\
+		\end{tabular}%
+		\hfill
+		\begin{tabular}[t]{ll}%
+			\multicolumn{2}{l}{FA für $<current_provider_external_id::Fachgebiet//Ärztekammer::50>$}\\
+			BSNR       & $<praxis_id::KV-BSNR//KV//%(value)s::25>$\\
+			LANR       & $<current_provider_external_id::KV-LANR//KV::25>$\\
+			\multicolumn{2}{l}{GNUmed $<client_version::::>$ (\href{http://www.gnumed.org}{www.gnumed.org})}\\
+		\end{tabular}%
+		\hfill
+		\begin{tabular}[t]{ll}%
+			\multicolumn{2}{l}{$<praxis_id::Bankname//Bank//%(value)s::60>$}\\
+			IBAN       & $<praxis_id::IBAN//Bank//%(value)s::30>$\\
+			BIC        & $<praxis_id::BIC//Bank//%(value)s::30>$\\
+			\multicolumn{2}{l}{Vorlage $<form_name_long::::60>$ v$<form_version::::20>$}\\
+		\end{tabular}%
+	}
+}
+
+
+% Fußzeile ab zweiter Seite
+\lefoot{{\tiny $<current_provider::::>$, $<praxis::%(praxis)s: %(branch)s::120>$}}
+\lofoot{{\tiny $<current_provider::::>$, $<praxis::%(praxis)s: %(branch)s::120>$}}
+\cefoot{}
+\cofoot{}
+\refoot{{\tiny $<today::%d.%B %Y::50>$}}
+\rofoot{{\tiny $<today::%d.%B %Y::50>$}}
+
+
+% Definiere Brief und Empfaenger
+\begin{letter}{%
+	$<receiver_name::::>$\\
+	$<receiver_street::::>$\ $<receiver_number::::>$\ $<receiver_subunit::::>$\\
+	$<receiver_postcode::::>$\ $<receiver_location::::>$\\
+	$<receiver_country::::>$
+}%
+
+
+% Anrede
+\opening{Sehr $<gender_mapper::geehrter Herr//geehrte Frau//Hallo::>$ $<receiver_name::::>$,}
+
+
+% Brieftext
+\selectlanguage{ngerman}
+$<free_text::Der eigentliche Brieftext (in LaTeX !)::>$
+
+\closing{$<free_text::Grußformel, z.B. "Mit freundlichen Grüßen" (ohne Komma am Ende)::140>$,}
+
+% Anlagen
+%\setkomavar*{enclseparator}[Anlage(n)]					% Titel für Anlagebereich
+\encl{$<free_text::Liste von Anlagen::300>$}
+
+% kein Verteiler
+%\cc{}
+
+\end{letter}
+
+\end{document}
diff --git a/server/sql/v20-v21/data/v21-Medikationsplan_AMTS-2.0-nicht_konform.tex b/server/sql/v20-v21/data/v21-Medikationsplan_AMTS-2.0-nicht_konform.tex
new file mode 100644
index 0000000..7fd6203
--- /dev/null
+++ b/server/sql/v20-v21/data/v21-Medikationsplan_AMTS-2.0-nicht_konform.tex
@@ -0,0 +1,383 @@
+%------------------------------------------------------------------
+% Medikationsplan gemäß AMTS 2.0 für GNUmed (http://www.gnumed.de)
+%
+% License: GPL v2 or later
+%
+% Author: karsten.hilbert at gmx.net
+% Thanks to: G.Hellmann
+%
+% requires pdflatex to be run with -recorder option
+%------------------------------------------------------------------
+
+% debugging
+\listfiles
+\errorcontextlines 10000
+
+\documentclass[
+	version=last,
+	paper=landscape,
+	paper=a4,
+	DIV=9,									% help typearea find a good Satzspiegel
+	BCOR=0mm,								% keine BindeCORrektur
+	fontsize=12pt,							% per spec
+	parskip=full,							% Absätze mit Leerzeilen trennen, kein Einzug
+	headsepline=off,
+	footsepline=off,
+	titlepage=false
+]{scrartcl}
+
+%------------------------------------------------------------------
+% packages
+\usepackage{scrlayer-scrpage}				% Kopf- und Fußzeilen
+\usepackage{geometry}						% setup margins
+\usepackage{microtype}						% micro-adjustments to typesetting
+\usepackage[cjkjis,graphics]{ucs}			% lots of UTF8 symbols, breaks with xelatex
+\usepackage[T1]{fontenc}					% fonts are T1
+\usepackage[ngerman]{babel}					% Deutsch und Trennung
+\usepackage[utf8x]{inputenc}				% content is UTF8, breaks with xelatex
+\usepackage{textcomp}						% Symbole für Textmodus zum Escapen
+\usepackage{ragged2e}						% improved alignment, needed for raggedleft in header table cell
+\usepackage{tabularx}						% bessere Tabellen
+\usepackage{tabu}							% bessere Tabellen
+\usepackage{longtable}						% Tabellen über mehrere Seiten
+\usepackage{helvet}							% Arial alike Helvetica
+\usepackage{lastpage}						% easy access to page number of last page
+\usepackage{embedfile}						% store copy of data file for producing data matrix inside PDF
+\usepackage{array}							% improved column styles
+\usepackage[abspath]{currfile}				% generically refer to input file
+\usepackage{graphicx}						% Grafiken laden (datamatrix)
+\usepackage[space]{grffile}					% besserer Zugriff auf Grafikdateien
+\usepackage[export]{adjustbox}				% improved options for \includegraphics
+%\usepackage[ocgcolorlinks=true]{hyperref}	% aktive URLs, needs to be loaded last, most of the time
+\usepackage{hyperref}						% aktive URLs, needs to be loaded last, most of the time
+
+% debugging:
+%\usepackage{showkeys}
+
+%\usepackage{marvosym}					% Symbole: Handy, Telefon, E-Mail
+%\usepackage{calc}						% \widthof (für signature)
+
+%------------------------------------------------------------------
+% setup:
+% - debugging
+%\tracingtabu=2
+%\hypersetup{debug=true}
+
+
+% - placeholder handler options
+% switch on ellipsis handling:
+$<ph_cfg::ellipsis//…//%% <%(name)s> set to [%(value)s]::>$
+
+
+% - PDF metadata
+\hypersetup{
+	pdftitle = {Medikationsplan: $<name::%(firstnames)s %(lastnames)s::>$, $<date_of_birth::%d.%b %Y::>$},
+	pdfauthor = {$<current_provider::::>$, $<praxis::%(branch)s, %(praxis)s::>$},
+	pdfsubject = {Medikationsplan (AMTS, NICHT KONFORM)},
+	pdfproducer = {GNUmed $<client_version::::>$, Vorlage $<form_name_long::::>$ ($<form_version::::>$)},
+	pdfdisplaydoctitle = true
+}
+
+
+% - precise positioning of things to satisfy spec
+\setlength{\tabcolsep}{0pt}
+\setlength{\parskip}{0pt}
+\setlength{\topskip}{0pt}
+\setlength{\marginparwidth}{0pt}
+\setlength{\marginparsep}{0pt}
+
+
+% - page
+\geometry{
+	verbose,
+	% debugging:
+%	showframe,											% show page frames
+%	showcrop,											% show crop marks
+	a4paper,
+	landscape,
+	includehead=true,
+	headheight=4cm,
+	headsep=0pt,
+	includefoot=true,									% make margins absolute
+	footskip=1cm,										% per spec
+	left=0.8cm,right=0.8cm,top=0.8cm,bottom=0.8cm		% per spec
+}
+
+% - font: Arial (Helvetica)
+\renewcommand{\rmdefault}{phv}
+\renewcommand{\sfdefault}{phv}
+
+
+% - header = top part
+\lohead{
+	\upshape
+	% debugging (with vertical lines):
+	%\begin{tabu} to \textwidth {>{\raggedleft\arraybackslash}p{7cm}|X[-1,L]|@{\hspace{1cm}}|X[-1,R]|p{4.6cm}}
+	\begin{tabu} to \textwidth {>{\raggedleft\arraybackslash}p{7cm}@{\hspace{1.5mm}}X[-1,L]@{\hspace{1cm}}X[-1,R]p{4.3cm}}
+			{\fontsize{20pt}{22pt}\selectfont \textbf{\href{http://www.akdae.de/AMTS/Medikationsplan/}{Medikationsplan}}} \newline
+			\ \newline
+			{\fontsize{14pt}{16pt}\selectfont Seite \thepage\ von \pageref{LastPage}} \newline
+			% as long as we don't have certification or claim conformance we can put here any image we want :-)
+			\includegraphics[scale=5,max height=2.4cm,center]{$<patient_photo::%s//image/png//.png::>$}
+		&
+			% line 1
+			\fontsize{14pt}{16pt}\selectfont
+			$<ph_cfg::ellipsis//NONE//%% <%(name)s> set to [%(value)s]::>$		% switch off ellipsis handling so first range of name does not get one if too long
+			für:\ \textbf{$<name::%(firstnames)s %(lastnames)s::1-37>$} \newline
+			$<ph_cfg::ellipsis//…//%% <%(name)s> set to [%(value)s]::>$			% but reenable in case second line of name still too long so that we need an ellipsis
+			% line 2
+			$<name::\textbf{%(firstnames)s %(lastnames)s}::38-90>$\  \newline
+			% line 3
+			ausgedruckt von: $<current_provider::::30>$ \newline
+			% line 4
+			\href{http://$<praxis_comm::web::>$}{$<praxis::%(branch)s, %(praxis)s::50>$} \newline
+			% line 5: use \mbox{TEXT} to prevent TEXT from getting hyphenated
+			$<ph_cfg::argumentsdivider//||//%% <%(name)s> set to [%(value)s]::>$
+			$<praxis_address::\href{http://nominatim.openstreetmap.org/search/$<<<url_escape::$<<praxis_address::%(country)s::>>$::>>>$/$<<<url_escape::$<<praxis_address::%(urb)s::>>$::>>>$/$<<<url_escape::$<<praxis_address::%(street)s::>>$::>>>$/$<<<url_escape::$<<praxis_address::%(number)s::>>$::>>>$?limit=3}{\mbox{$<<praxis_address::%(street)s %(number)s %(subunit)s,%(postcode)s %(urb)s::55>>$}}::>$
+			$<ph_cfg::argumentsdivider//DEFAULT//%% <%(name)s> set to [%(value)s]::>$
+			\ \newline
+			% line 6
+			$<<praxis_comm::workphone//\href{tel:$<praxis_comm::workphone::>$}{$<praxis_comm::workphone::50>$}::>>$\  \newline
+			% line 7
+			$<<praxis_comm::email//{\fontsize{12pt}{14pt}\selectfont \href{mailto:$<praxis_comm::email::>$}{$<praxis_comm::email::80>$}}::>>$\ 
+		&
+			\fontsize{14pt}{16pt}\selectfont			% alle Zeilen
+			% line 1
+			geb.\ am: \textbf{$<date_of_birth::%d.%b %Y::>$}\newline
+			% line 2
+			\ \newline
+			% line 3
+			\ \newline
+			% line 4			%$<allergy_state::::15>$
+			Allergie: Seite \pageref{LastPage}\ \hyperref[AnchorAllergieDetails]{unten}\newline
+			% line 5
+			\ \newline											%Gewicht: 125 kg\newline		::25
+			% line 6
+			\ \newline											%schwanger / stillend\newline	::25
+			% line 7: soll eigentlich linksbündig ...
+			ausgedruckt am: $<today::%d.%b %Y::>$
+		&
+			\includegraphics[valign=t,raise=6ex,max height=4cm,max width=4cm,center]{$<<amts_png_file_current_page::::>>$}
+%		\tabularnewline
+	\end{tabu}
+}
+%\lehead{test}
+%\cehead{}
+%\cohead{}
+%\rehead{}
+%\rohead{}
+
+
+% footer setup = bottom part
+\lofoot{{
+	\begin{tabular}[t]{p{6cm}p{17cm}p{5cm}}
+		\hline
+		{	% left side: Versionsinformationen
+			\raggedright
+			\fontsize{10pt}{12pt}\selectfont
+			\upshape
+			%DE-DE-Version 2.0 vom 15.12.2014
+			NICHT KONFORM (2.0)
+		} & {
+			% middle part: Herstellerfeld
+			\parbox[t][1cm][t]{17cm}{
+				\centering
+				GNUmed $<client_version::::>$ --- \href{http://www.gnumed.org}{www.gnumed.org}
+			}
+		} & {
+			% right side: Freifeld, must be empty
+			% debugging:
+			%---Freifeld---
+		}
+	\end{tabular}
+}}
+\lefoot{{
+	\begin{tabular}[t]{p{6cm}p{17cm}p{5cm}}
+		\hline
+		{	% left side: Versionsinformationen
+			\raggedright
+			\fontsize{10pt}{12pt}\selectfont
+			\upshape
+			%DE-DE-Version 2.0 vom 15.12.2014
+			NICHT KONFORM (2.0)
+		} & {
+			% middle part: Herstellerfeld
+			\parbox[t][1cm][t]{17cm}{
+				\centering
+				GNUmed $<client_version::::>$ --- \href{http://www.gnumed.org}{www.gnumed.org}
+			}
+		} & {
+			% right side: Freifeld, must be empty
+			% debugging:
+			%---Freifeld---
+		}
+	\end{tabular}
+}}
+\cefoot{}
+\cofoot{}
+\refoot{}
+\rofoot{}
+
+%------------------------------------------------------------------
+\begin{document}
+
+% middle part: Medikationsliste
+\begin{longtable} {|
+	% column definition
+	p{4cm}|									% Wirkstoff
+	p{4.4cm}|								% Handelsname
+	>{\RaggedLeft}p{1.8cm}|					% Stärke
+	p{1.8cm}|								% Form
+	p{0.8cm}|								% Dosierung: morgens
+	p{0.8cm}|								% Dosierung: mittags
+	p{0.8cm}|								% Dosierung: abends
+	p{0.8cm}|								% Dosierung: zur Nacht
+	p{2.0cm}|								% Einheit
+	p{6.4cm}|								% Hinweise
+	p{4.3cm}|								% Grund
+}
+	% Tabellenkopf:
+	\hline
+	\rule{0pt}{4.5mm}						% vertical strut to ensure 14pt doesn't touch top \hline
+	\fontsize{14pt}{16pt}\selectfont \centering Wirkstoff &
+	\fontsize{14pt}{16pt}\selectfont \centering Handelsname &
+	\fontsize{14pt}{16pt}\selectfont \centering Stärke &
+	\fontsize{14pt}{16pt}\selectfont \centering Form &
+	\fontsize{14pt}{16pt}\selectfont \centering Mo &
+	\fontsize{14pt}{16pt}\selectfont \centering Mi &
+	\fontsize{14pt}{16pt}\selectfont \centering Ab &
+	\fontsize{14pt}{16pt}\selectfont \centering zN &
+	\fontsize{14pt}{16pt}\selectfont \centering Einheit &
+	\fontsize{14pt}{16pt}\selectfont \centering Hinweise &
+	\fontsize{14pt}{16pt}\selectfont \centering Grund
+	\endhead
+	% Tabellenende auf 1. und 2. Seite
+	\endfoot
+	% Tabellenende auf letzter (3.) Seite
+	\endlastfoot
+	% Tabelleninhalt:
+\hline
+$<current_meds_AMTS_enhanced::::>$
+\end{longtable}
+
+%------------------------------------------------------------------
+% include data in PDF for easier processing:
+
+% VCF of creator
+\IfFileExists{$<praxis_vcf::::>$}{
+	\embedfile[
+		desc=01) digitale Visitenkarte des Erstellers des Medikationsplans,
+		mimetype=text/vcf,
+		ucfilespec=AMTS-Medikationsplan-Ersteller.vcf
+	]{$<praxis_vcf::::>$}
+}{\typeout{[$<praxis_vcf::::>$] not found}}
+
+% LaTeX source code from which the PDF was produced
+\embedfile[
+	desc=02) LaTeX-Quellcode des Medikationsplans (übersetzbar mit "pdflatex -recorder -interaction=nonstopmode \currfilename\ "),
+	mimetype=text/plain,
+	ucfilespec=\currfilename
+]{\currfileabspath}
+
+% enhanced QR code
+\IfFileExists{$<<amts_png_file_utf8::::>>$}{
+	\embedfile[
+		desc=03) QR-Code (Bild) für alle Seiten (lesbar mit "dmtxread -v $<<amts_png_file_utf8::::>>$ > $<<amts_png_file_utf8::::>>$.txt"),
+		mimetype=image/png,
+		ucfilespec=AMTS-QR-Code-utf8-alle-Seiten.png
+	]{$<<amts_png_file_utf8::::>>$}
+}{\typeout{[$<<amts_png_file_utf8::::>>$] (all pages) not found}}
+
+\IfFileExists{$<<amts_data_file_utf8::::>>$}{
+	\embedfile[
+		desc=04) QR-Code (Daten) für alle Seiten (übersetzbar mit "dmtxwrite -e a -m 2 -f PNG -o $<<amts_data_file_utf8::::>>$.png -s s -v $<<amts_data_file_utf8::::>>$"),
+		mimetype=image/png,
+		ucfilespec=AMTS-QR-Code-utf8-alle-Seiten.txt
+	]{$<<amts_data_file_utf8::::>>$}
+}{\typeout{[$<<amts_data_file_utf8::::>>$] (all pages) not found}}
+
+% per-page QR codes
+% page 1
+\IfFileExists{$<<amts_png_file_1::::>>$}{
+	\embedfile[
+		desc=05) QR-Code (Bild) für Seite 1 (lesbar mit "dmtxread -U -v $<<amts_png_file_1::::>>$ > $<<amts_png_file_1::::>>$.txt"),
+		mimetype=image/png,
+		ucfilespec=AMTS-QR-Code-Seite-1.png
+	]{$<<amts_png_file_1::::>>$}
+}{\typeout{[$<<amts_png_file_1::::>>$] (page 1) not found}}
+
+\IfFileExists{$<<amts_data_file_1::::>>$}{
+	\embedfile[
+		desc=06) QR-Code (Daten) für Seite 1 (übersetzbar mit "dmtxwrite -e a -m 2 -f PNG -o $<<amts_data_file_1::::>>$.png -s s -v $<<amts_data_file_1::::>>$"),
+		mimetype=text/plain,
+		ucfilespec=AMTS-QR-Code-Daten-Seite-1.txt
+	]{$<<amts_data_file_1::::>>$}
+}{\typeout{[$<<amts_data_file_1::::>>$] (page 1) not found}}
+
+% page 2
+\IfFileExists{$<<amts_png_file_2::::>>$}{
+	\embedfile[
+		desc=07) QR-Code (Bild) für Seite 2 (lesbar mit "dmtxread -U -v $<<amts_png_file_1::::>>$ > $<<amts_png_file_2::::>>$.txt"),
+		mimetype=image/png,
+		ucfilespec=AMTS-QR-Code-Seite-2.png
+	]{$<<amts_png_file_2::::>>$}
+}{\typeout{[$<<amts_png_file_2::::>>$] (page 2) not found}}
+
+\IfFileExists{$<<amts_data_file_2::::>>$}{
+	\embedfile[
+		desc=08) QR-Code (Daten) für Seite 2 (übersetzbar mit "dmtxwrite -e a -m 2 -f PNG -o $<<amts_data_file_2::::>>$.png -s s -v $<<amts_data_file_2::::>>$"),
+		mimetype=text/plain,
+		ucfilespec=AMTS-QR-Code-Daten-Seite-2.txt
+	]{$<<amts_data_file_2::::>>$}
+}{\typeout{[$<<amts_data_file_2::::>>$] (page 2) not found}}
+
+% page 3
+\IfFileExists{$<<amts_png_file_3::::>>$}{
+	\embedfile[
+		desc=09) QR-Code (Bild) für Seite 3 (lesbar mit "dmtxread -U -v $<<amts_png_file_1::::>>$ > $<<amts_png_file_3::::>>$.txt"),
+		mimetype=image/png,
+		ucfilespec=AMTS-QR-Code-Seite-3.png
+	]{$<<amts_png_file_3::::>>$}
+}{\typeout{[$<<amts_png_file_3::::>>$] (page 3) not found}}
+
+\IfFileExists{$<<amts_data_file_3::::>>$}{
+	\embedfile[
+		desc=10) QR-Code (Daten) für Seite 3 (übersetzbar mit "dmtxwrite -e a -m 2 -f PNG -o $<<amts_data_file_3::::>>$.png -s s -v $<<amts_data_file_3::::>>$"),
+		mimetype=text/plain,
+		ucfilespec=AMTS-QR-Code-Daten-Seite-3.txt
+	]{$<<amts_data_file_3::::>>$}
+}{\typeout{[$<<amts_data_file_3::::>>$] (page 3) not found}}
+
+% patient photo
+\IfFileExists{$<patient_photo::%s//image/png//.png::>$}{
+	\embedfile[
+		desc=11) Patientenphoto,
+		mimetype=image/png,
+		ucfilespec=Patientenphoto.png
+	]{$<patient_photo::%s//image/png//.png::>$}
+}{\typeout{[$<patient_photo::%s//image/png//.png::>$] (patient photo) not found}}
+
+% patient vcf -- really a good idea ? (it would tell more
+% about the patient than is defined by the Medikationsplan specs)
+\IfFileExists{$<patient_vcf::::>$}{
+	\embedfile[
+		desc=12) digitale Visitenkarte des Patienten,
+		mimetype=text/vcf,
+		ucfilespec=Patient.vcf
+	]{$<patient_vcf::::>$}
+}{\typeout{[$<patient_vcf::::>$] (patient VCF) not found}}
+
+% patient gdt -- really a good idea ? (it would tell more
+% about the patient than is defined by the Medikationsplan specs)
+\IfFileExists{$<patient_gdt::::>$}{
+	\embedfile[
+		desc=13) GDT-Datei des Patienten,
+		mimetype=text/plain,
+		ucfilespec=Patient.gdt
+	]{$<patient_gdt::::>$}
+}{\typeout{[$<patient_gdt::::>$] (patient GDT) not found}}
+
+%------------------------------------------------------------------
+
+\end{document}
+%------------------------------------------------------------------
diff --git a/server/sql/v20-v21/data/v21-Medikationsplan_AMTS-2.0.tex b/server/sql/v20-v21/data/v21-Medikationsplan_AMTS-2.0.tex
new file mode 100644
index 0000000..00694d2
--- /dev/null
+++ b/server/sql/v20-v21/data/v21-Medikationsplan_AMTS-2.0.tex
@@ -0,0 +1,381 @@
+%------------------------------------------------------------------
+% Medikationsplan gemäß AMTS 2.0 für GNUmed (http://www.gnumed.de)
+%
+% License: GPL v2 or later
+%
+% Author: karsten.hilbert at gmx.net
+% Thanks to: G.Hellmann
+%
+% requires pdflatex to be run with -recorder option
+%------------------------------------------------------------------
+
+% debugging
+\listfiles
+\errorcontextlines 10000
+
+\documentclass[
+	version=last,
+	paper=landscape,
+	paper=a4,
+	DIV=9,									% help typearea find a good Satzspiegel
+	BCOR=0mm,								% keine BindeCORrektur
+	fontsize=12pt,							% per spec
+	parskip=full,							% Absätze mit Leerzeilen trennen, kein Einzug
+	headsepline=off,
+	footsepline=off,
+	titlepage=false
+]{scrartcl}
+
+%------------------------------------------------------------------
+% packages
+\usepackage{scrlayer-scrpage}				% Kopf- und Fußzeilen
+\usepackage{geometry}						% setup margins
+\usepackage{microtype}						% micro-adjustments to typesetting
+\usepackage[cjkjis,graphics]{ucs}			% lots of UTF8 symbols, breaks with xelatex
+\usepackage[T1]{fontenc}					% fonts are T1
+\usepackage[ngerman]{babel}					% Deutsch und Trennung
+\usepackage[utf8x]{inputenc}				% content is UTF8, breaks with xelatex
+\usepackage{textcomp}						% Symbole für Textmodus zum Escapen
+\usepackage{ragged2e}						% improved alignment, needed for raggedleft in header table cell
+\usepackage{tabularx}						% bessere Tabellen
+\usepackage{tabu}							% bessere Tabellen
+\usepackage{longtable}						% Tabellen über mehrere Seiten
+\usepackage{helvet}							% Arial alike Helvetica
+\usepackage{lastpage}						% easy access to page number of last page
+\usepackage{embedfile}						% store copy of data file for producing data matrix inside PDF
+\usepackage{array}							% improved column styles
+\usepackage[abspath]{currfile}				% generically refer to input file
+\usepackage{graphicx}						% Grafiken laden (datamatrix)
+\usepackage[space]{grffile}					% besserer Zugriff auf Grafikdateien
+\usepackage[export]{adjustbox}				% improved options for \includegraphics
+%\usepackage[ocgcolorlinks=true]{hyperref}	% aktive URLs, needs to be loaded last, most of the time
+\usepackage{hyperref}						% aktive URLs, needs to be loaded last, most of the time
+
+% debugging:
+%\usepackage{showkeys}
+
+%\usepackage{marvosym}					% Symbole: Handy, Telefon, E-Mail
+%\usepackage{calc}						% \widthof (für signature)
+
+%------------------------------------------------------------------
+% setup:
+% - debugging
+%\tracingtabu=2
+%\hypersetup{debug=true}
+
+
+% - placeholder handler options
+% switch on ellipsis handling:
+$<ph_cfg::ellipsis//…//%% <%(name)s> set to [%(value)s]::>$
+
+
+% - PDF metadata
+\hypersetup{
+	pdftitle = {Medikationsplan: $<name::%(firstnames)s %(lastnames)s::>$, $<date_of_birth::%d.%m.%Y::>$},
+	pdfauthor = {$<current_provider::::>$, $<praxis::%(branch)s, %(praxis)s::>$},
+	pdfsubject = {Medikationsplan (AMTS)},
+	pdfproducer = {GNUmed $<client_version::::>$, Vorlage $<form_name_long::::>$ ($<form_version::::>$)},
+	pdfdisplaydoctitle = true
+}
+
+
+% - precise positioning of things to satisfy spec
+\setlength{\tabcolsep}{0pt}
+\setlength{\parskip}{0pt}
+\setlength{\topskip}{0pt}
+\setlength{\marginparwidth}{0pt}
+\setlength{\marginparsep}{0pt}
+
+
+% - page
+\geometry{
+	verbose,
+	% debugging:
+%	showframe,											% show page frames
+%	showcrop,											% show crop marks
+	a4paper,
+	landscape,
+	includehead=true,
+	headheight=4cm,
+	headsep=0pt,
+	includefoot=true,									% make margins absolute
+	footskip=1cm,										% per spec
+	left=0.8cm,right=0.8cm,top=0.8cm,bottom=0.8cm		% per spec
+}
+
+% - font: Arial (Helvetica)
+\renewcommand{\rmdefault}{phv}
+\renewcommand{\sfdefault}{phv}
+
+
+% - header = top part
+\lohead{
+	\upshape
+	% debugging (with vertical lines):
+	%\begin{tabu} to \textwidth {>{\raggedleft\arraybackslash}p{7cm}|X[-1,L]|@{\hspace{1cm}}|X[-1,R]|p{4.6cm}}
+	\begin{tabu} to \textwidth {>{\raggedleft\arraybackslash}p{7cm}@{\hspace{1.5mm}}X[-1,L]@{\hspace{1cm}}X[-1,R]p{4.3cm}}
+			{\fontsize{20pt}{22pt}\selectfont \textbf{\href{http://www.akdae.de/AMTS/Medikationsplan/}{Medikationsplan}}} \newline
+			\ \newline
+			{\fontsize{14pt}{16pt}\selectfont Seite \thepage\ von \pageref{LastPage}} \newline
+			% after certification we would replace this with the certification image...
+			%\includegraphics[scale=5,max height=2.4cm,center]{certification-image}
+		&
+			% line 1
+			\fontsize{14pt}{16pt}\selectfont
+			$<ph_cfg::ellipsis//NONE//%% <%(name)s> set to [%(value)s]::>$		% switch off ellipsis handling so first range of name does not get one if too long
+			für:\ \textbf{$<name::%(firstnames)s %(lastnames)s::1-37>$} \newline
+			$<ph_cfg::ellipsis//…//%% <%(name)s> set to [%(value)s]::>$			% but reenable in case second line of name still too long so that we need an ellipsis
+			% line 2
+			$<name::\textbf{%(firstnames)s %(lastnames)s}::38-90>$\  \newline
+			% line 3
+			ausgedruckt von: $<current_provider::::30>$ \newline
+			% line 4
+			\href{http://$<praxis_comm::web::>$}{$<praxis::%(branch)s, %(praxis)s::50>$} \newline
+			% line 5: use \mbox{TEXT} to prevent TEXT from getting hyphenated
+			$<ph_cfg::argumentsdivider//||//%% <%(name)s> set to [%(value)s]::>$
+			$<praxis_address::\href{http://nominatim.openstreetmap.org/search/$<<<url_escape::$<<praxis_address::%(country)s::>>$::>>>$/$<<<url_escape::$<<praxis_address::%(urb)s::>>$::>>>$/$<<<url_escape::$<<praxis_address::%(street)s::>>$::>>>$/$<<<url_escape::$<<praxis_address::%(number)s::>>$::>>>$?limit=3}{\mbox{$<<praxis_address::%(street)s %(number)s %(subunit)s,%(postcode)s %(urb)s::55>>$}}::>$
+			$<ph_cfg::argumentsdivider//DEFAULT//%% <%(name)s> set to [%(value)s]::>$
+			\ \newline
+			% line 6
+			$<<praxis_comm::workphone//\href{tel:$<praxis_comm::workphone::>$}{$<praxis_comm::workphone::20>$}::>>$\  \newline
+			% line 7
+			$<<praxis_comm::email//{\fontsize{12pt}{14pt}\selectfont \href{mailto:$<praxis_comm::email::>$}{$<praxis_comm::email::80>$}}::>>$\ 
+		&
+			\fontsize{14pt}{16pt}\selectfont			% alle Zeilen
+			% line 1
+			geb.\ am: \textbf{$<date_of_birth::%d.%m.%Y::10>$}\newline
+			% line 2
+			\ \newline
+			% line 3
+			\ \newline
+			% line 4			%$<allergy_state::::15>$
+			Allergie: Seite \pageref{LastPage}\ \hyperref[AnchorAllergieDetails]{unten}\newline
+			% line 5
+			\ \newline											%Gewicht: 125 kg\newline		::25
+			% line 6
+			\ \newline											%schwanger / stillend\newline	::25
+			% line 7: soll eigentlich linksbündig ...
+			ausgedruckt am: $<today::%d.%m.%Y::10>$
+		&
+			\includegraphics[valign=t,raise=6ex,max height=4cm,max width=4cm,center]{$<<amts_png_file_current_page::::>>$}
+%		\tabularnewline
+	\end{tabu}
+}
+%\lehead{test}
+%\cehead{}
+%\cohead{}
+%\rehead{}
+%\rohead{}
+
+
+% footer setup = bottom part
+\lofoot{{
+	\begin{tabular}[t]{p{6cm}p{17cm}p{5cm}}
+		\hline
+		{	% left side: Versionsinformationen
+			\raggedright
+			\fontsize{10pt}{12pt}\selectfont
+			\upshape
+			DE-DE-Version 2.0 vom 15.12.2014
+		} & {
+			% middle part: Herstellerfeld
+			\parbox[t][1cm][t]{17cm}{
+				\centering
+				GNUmed $<client_version::::>$ --- \href{http://www.gnumed.org}{www.gnumed.org}
+			}
+		} & {
+			% right side: Freifeld, must be empty
+			% debugging:
+			%---Freifeld---
+		}
+	\end{tabular}
+}}
+\lefoot{{
+	\begin{tabular}[t]{p{6cm}p{17cm}p{5cm}}
+		\hline
+		{	% left side: Versionsinformationen
+			\raggedright
+			\fontsize{10pt}{12pt}\selectfont
+			\upshape
+			DE-DE-Version 2.0 vom 15.12.2014
+		} & {
+			% middle part: Herstellerfeld
+			\parbox[t][1cm][t]{17cm}{
+				\centering
+				GNUmed $<client_version::::>$ --- \href{http://www.gnumed.org}{www.gnumed.org}
+			}
+		} & {
+			% right side: Freifeld, must be empty
+			% debugging:
+			%---Freifeld---
+		}
+	\end{tabular}
+}}
+\cefoot{}
+\cofoot{}
+\refoot{}
+\rofoot{}
+
+%------------------------------------------------------------------
+\begin{document}
+
+% middle part: Medikationsliste
+\begin{longtable} {|
+	% column definition
+	p{4cm}|									% Wirkstoff
+	p{4.4cm}|								% Handelsname
+	>{\RaggedLeft}p{1.8cm}|					% Stärke
+	p{1.8cm}|								% Form
+	p{0.8cm}|								% Dosierung: morgens
+	p{0.8cm}|								% Dosierung: mittags
+	p{0.8cm}|								% Dosierung: abends
+	p{0.8cm}|								% Dosierung: zur Nacht
+	p{2.0cm}|								% Einheit
+	p{6.4cm}|								% Hinweise
+	p{4.3cm}|								% Grund
+}
+	% Tabellenkopf:
+	\hline
+	\rule{0pt}{4.5mm}						% vertical strut to ensure 14pt doesn't touch top \hline
+	\fontsize{14pt}{16pt}\selectfont \centering Wirkstoff &
+	\fontsize{14pt}{16pt}\selectfont \centering Handelsname &
+	\fontsize{14pt}{16pt}\selectfont \centering Stärke &
+	\fontsize{14pt}{16pt}\selectfont \centering Form &
+	\fontsize{14pt}{16pt}\selectfont \centering Mo &
+	\fontsize{14pt}{16pt}\selectfont \centering Mi &
+	\fontsize{14pt}{16pt}\selectfont \centering Ab &
+	\fontsize{14pt}{16pt}\selectfont \centering zN &
+	\fontsize{14pt}{16pt}\selectfont \centering Einheit &
+	\fontsize{14pt}{16pt}\selectfont \centering Hinweise &
+	\fontsize{14pt}{16pt}\selectfont \centering Grund
+	\endhead
+	% Tabellenende auf 1. und 2. Seite
+	\endfoot
+	% Tabellenende auf letzter (3.) Seite
+	\endlastfoot
+	% Tabelleninhalt:
+\hline
+$<current_meds_AMTS::::999999999>$
+\end{longtable}
+
+%------------------------------------------------------------------
+% include data in PDF for easier processing:
+
+% VCF of creator
+\IfFileExists{$<praxis_vcf::::>$}{
+	\embedfile[
+		desc=01) digitale Visitenkarte des Erstellers des Medikationsplans,
+		mimetype=text/vcf,
+		ucfilespec=AMTS-Medikationsplan-Ersteller.vcf
+	]{$<praxis_vcf::::>$}
+}{\typeout{[$<praxis_vcf::::>$] not found}}
+
+% LaTeX source code from which the PDF was produced
+\embedfile[
+	desc=02) LaTeX-Quellcode des Medikationsplans (übersetzbar mit "pdflatex -recorder -interaction=nonstopmode \currfilename\ "),
+	mimetype=text/plain,
+	ucfilespec=\currfilename
+]{\currfileabspath}
+
+% enhanced QR code
+\IfFileExists{$<<amts_png_file_utf8::::>>$}{
+	\embedfile[
+		desc=03) QR-Code (Bild) für alle Seiten (lesbar mit "dmtxread -v $<<amts_png_file_utf8::::>>$ > $<<amts_png_file_utf8::::>>$.txt"),
+		mimetype=image/png,
+		ucfilespec=AMTS-QR-Code-utf8-alle-Seiten.png
+	]{$<<amts_png_file_utf8::::>>$}
+}{\typeout{[$<<amts_png_file_utf8::::>>$] (all pages) not found}}
+
+\IfFileExists{$<<amts_data_file_utf8::::>>$}{
+	\embedfile[
+		desc=04) QR-Code (Daten) für alle Seiten (übersetzbar mit "dmtxwrite -e a -m 2 -f PNG -o $<<amts_data_file_utf8::::>>$.png -s s -v $<<amts_data_file_utf8::::>>$"),
+		mimetype=image/png,
+		ucfilespec=AMTS-QR-Code-utf8-alle-Seiten.txt
+	]{$<<amts_data_file_utf8::::>>$}
+}{\typeout{[$<<amts_data_file_utf8::::>>$] (all pages) not found}}
+
+% per-page QR codes
+% page 1
+\IfFileExists{$<<amts_png_file_1::::>>$}{
+	\embedfile[
+		desc=05) QR-Code (Bild) für Seite 1 (lesbar mit "dmtxread -U -v $<<amts_png_file_1::::>>$ > $<<amts_png_file_1::::>>$.txt"),
+		mimetype=image/png,
+		ucfilespec=AMTS-QR-Code-Seite-1.png
+	]{$<<amts_png_file_1::::>>$}
+}{\typeout{[$<<amts_png_file_1::::>>$] (page 1) not found}}
+
+\IfFileExists{$<<amts_data_file_1::::>>$}{
+	\embedfile[
+		desc=06) QR-Code (Daten) für Seite 1 (übersetzbar mit "dmtxwrite -e a -m 2 -f PNG -o $<<amts_data_file_1::::>>$.png -s s -v $<<amts_data_file_1::::>>$"),
+		mimetype=text/plain,
+		ucfilespec=AMTS-QR-Code-Daten-Seite-1.txt
+	]{$<<amts_data_file_1::::>>$}
+}{\typeout{[$<<amts_data_file_1::::>>$] (page 1) not found}}
+
+% page 2
+\IfFileExists{$<<amts_png_file_2::::>>$}{
+	\embedfile[
+		desc=07) QR-Code (Bild) für Seite 2 (lesbar mit "dmtxread -U -v $<<amts_png_file_1::::>>$ > $<<amts_png_file_2::::>>$.txt"),
+		mimetype=image/png,
+		ucfilespec=AMTS-QR-Code-Seite-2.png
+	]{$<<amts_png_file_2::::>>$}
+}{\typeout{[$<<amts_png_file_2::::>>$] (page 2) not found}}
+
+\IfFileExists{$<<amts_data_file_2::::>>$}{
+	\embedfile[
+		desc=08) QR-Code (Daten) für Seite 2 (übersetzbar mit "dmtxwrite -e a -m 2 -f PNG -o $<<amts_data_file_2::::>>$.png -s s -v $<<amts_data_file_2::::>>$"),
+		mimetype=text/plain,
+		ucfilespec=AMTS-QR-Code-Daten-Seite-2.txt
+	]{$<<amts_data_file_2::::>>$}
+}{\typeout{[$<<amts_data_file_2::::>>$] (page 2) not found}}
+
+% page 3
+\IfFileExists{$<<amts_png_file_3::::>>$}{
+	\embedfile[
+		desc=09) QR-Code (Bild) für Seite 3 (lesbar mit "dmtxread -U -v $<<amts_png_file_1::::>>$ > $<<amts_png_file_3::::>>$.txt"),
+		mimetype=image/png,
+		ucfilespec=AMTS-QR-Code-Seite-3.png
+	]{$<<amts_png_file_3::::>>$}
+}{\typeout{[$<<amts_png_file_3::::>>$] (page 3) not found}}
+
+\IfFileExists{$<<amts_data_file_3::::>>$}{
+	\embedfile[
+		desc=10) QR-Code (Daten) für Seite 3 (übersetzbar mit "dmtxwrite -e a -m 2 -f PNG -o $<<amts_data_file_3::::>>$.png -s s -v $<<amts_data_file_3::::>>$"),
+		mimetype=text/plain,
+		ucfilespec=AMTS-QR-Code-Daten-Seite-3.txt
+	]{$<<amts_data_file_3::::>>$}
+}{\typeout{[$<<amts_data_file_3::::>>$] (page 3) not found}}
+
+% patient photo
+\IfFileExists{$<patient_photo::%s//image/png//.png::>$}{
+	\embedfile[
+		desc=11) Patientenphoto,
+		mimetype=image/png,
+		ucfilespec=Patientenphoto.png
+	]{$<patient_photo::%s//image/png//.png::>$}
+}{\typeout{[$<patient_photo::%s//image/png//.png::>$] (patient photo) not found}}
+
+% patient vcf -- not a good idea as it would tell more about
+% the patient than is defined by the Medikationsplan specs
+%\IfFileExists{$<patient_vcf::::>$}{
+%	\embedfile[
+%		desc=12) digitale Visitenkarte des Patienten,
+%		mimetype=text/vcf,
+%		ucfilespec=Patient.vcf
+%	]{$<patient_vcf::::>$}
+%}{\typeout{[$<patient_vcf::::>$] (patient VCF) not found}}
+
+% patient gdt -- not a good idea ? as it would tell more
+% about the patient than is defined by the Medikationsplan specs
+%\IfFileExists{$<patient_gdt::::>$}{
+%	\embedfile[
+%		desc=13) GDT-Datei des Patienten,
+%		mimetype=text/plain,
+%		ucfilespec=Patient.gdt
+%	]{$<patient_gdt::::>$}
+%}{\typeout{[$<patient_gdt::::>$] (patient GDT) not found}}
+
+%------------------------------------------------------------------
+
+\end{document}
+%------------------------------------------------------------------
diff --git a/server/sql/v20-v21/data/v21-aktuelle-Medikationsliste.tex b/server/sql/v20-v21/data/v21-aktuelle-Medikationsliste.tex
new file mode 100644
index 0000000..d8e02a4
--- /dev/null
+++ b/server/sql/v20-v21/data/v21-aktuelle-Medikationsliste.tex
@@ -0,0 +1,102 @@
+%------------------------------------------------------------------
+% Author: Karsten Hilbert
+% License: GPL v2 or later
+%------------------------------------------------------------------
+
+\listfiles
+
+%\documentclass[english]{article}
+\documentclass{article}
+
+\usepackage[cjkjis,graphics]{ucs}			% lots of UTF8 symbols, breaks with xelatex
+\usepackage[T1]{fontenc}
+\usepackage[utf8x]{inputenc}
+\usepackage{longtable}
+\usepackage{tabu}
+%\usepackage{ragged2e}
+\usepackage{tabularx}
+\usepackage{afterpage}
+\usepackage{fancyhdr}
+\usepackage[a4paper]{geometry}
+\usepackage{lastpage}
+\usepackage[ngerman]{babel}					% Deutsch und Trennung
+\usepackage{hyperref}
+
+
+\geometry{verbose,lmargin=2.54cm}
+\pagestyle{fancy}
+
+\setlength{\headheight}{13.6pt}
+\setlength{\parskip}{\medskipamount}
+\setlength{\parindent}{0pt}
+
+
+\lhead[]{}
+\rhead[]{}
+\lfoot[\thepage\ / \pageref{LastPage}]{{\tiny \href{http://www.gnumed.org}{GNUmed} $<client_version::::>$: $<form_name_long::::60>$ v$<form_version::::20>$}}
+\cfoot[]{}
+\rfoot[{\tiny \href{http://www.gnumed.org}{GNUmed} $<client_version::::>$: $<form_name_long::::60>$ v$<form_version::::20>$}]{\thepage\ / \pageref{LastPage}}
+
+\begin{document}
+
+\afterpage{\lhead[Medikamentenliste von $<lastname::::>$, $<firstname::::>$ ($<date_of_birth::%Y %B %d::>$)]{Medikamentenliste von $<lastname::::>$, $<firstname::::>$ ($<date_of_birth::%Y %B %d::>$}}
+\afterpage{\rhead[$<today::%Y %B %d::>$]{$<today::%Y %B %d::>$}}
+
+
+\noindent \begin{center}
+{\LARGE	Aktuelle Medikamente} \\
+{\large
+	Gedruckt: $<today::%Y %B %d::>$ \\
+	Arzt: $<current_provider::::>$
+}
+\end{center}
+
+\noindent
+Patient: $<lastname::::>$, $<firstname::::>$ \\
+Geburtsdatum: $<date_of_birth::%Y %B %d::>$ \\
+{\footnotesize
+	$<adr_street::home::>$ $<adr_number::home::>$ \\
+	$<adr_postcode::home::>$ $<adr_location::home::>$
+}
+
+%\vspace*{\medskipamount}
+
+%------------------------------------------------------------------
+$<current_meds_table::latex::>$
+
+$<current_meds_notes::latex::>$
+
+%------------------------------------------------------------------
+$<free_text::Hinweise an den Patienten::9999>$
+%------------------------------------------------------------------
+
+% uncomment, if and as needed, the next lines to append text below the table
+%{\footnotesize			% start smaller font
+% <any line(s) of info you wish to always be printed immediately below the table>
+%}						% end smaller font
+%------------------------------------------------------------------
+
+\vfill{}
+
+%------------------------------------------------------------------
+\noindent Bislang bekannte Allergien:
+
+\noindent $<allergy_state::::>$
+
+\noindent \begin{tabularx}{\textwidth}{|l|l|X|}
+\hline
+Auslöser & Typ & Reaktion\tabularnewline
+\hline
+$<allergies::%(descriptor)s & %(l10n_type)s & {\footnotesize %(reaction)s} \tabularnewline \hline::>$
+\end{tabularx}
+%------------------------------------------------------------------
+
+\medskip{}
+
+
+\noindent \begin{flushright}
+\texttt{\textsl{\footnotesize Stempel / Unterschrift}}
+\par\end{flushright}
+\end{document}
+
+%------------------------------------------------------------------
diff --git a/server/sql/v20-v21/data/v21-gm2gpl-plot_one_test.gpl b/server/sql/v20-v21/data/v21-gm2gpl-plot_one_test.gpl
new file mode 100644
index 0000000..005e22d
--- /dev/null
+++ b/server/sql/v20-v21/data/v21-gm2gpl-plot_one_test.gpl
@@ -0,0 +1,59 @@
+#----------------------------------------------------
+# GNUmed gnuplot graphing script example:
+#
+# plot one test result type very space efficient
+#----------------------------------------------------
+
+# uncomment for debugging:
+#gm2gpl_datafile = './x-data.txt'
+
+
+# general
+#set title "your special title for this template"
+set grid xtics noytics
+set autoscale
+set datafile missing '<?>'
+set key off
+set key tmargin center horizontal Left autotitle columnheader
+set bmargin 7
+
+
+# x axis
+set xtics rotate by -45
+set xdata time
+set timefmt "%Y-%m-%d_%H:%M"
+
+
+# plot
+plot gm2gpl_datafile using 1:2:(valid(4) ? column(4) : column(2)):(valid(5) ? column(5) : column(2)):xticlabels(10) index 0 with yerrorbars pointtype 2, \
+     gm2gpl_datafile using 1:2:(sprintf("%s%s", stringcolumn(2), stringcolumn(3))) index 0 notitle with labels offset 0, 1
+
+
+# detect and adjust x range by 10% of entire time span
+time_span = GPVAL_X_MAX - GPVAL_X_MIN
+range_offset = time_span * 10 / 100
+set xrange [(GPVAL_X_MIN - range_offset):(GPVAL_X_MAX + range_offset)]
+
+
+# detect and adjust y range by 5%
+five_percent = abs(GPVAL_Y_MIN * 5 / 100)
+loffset = (GPVAL_Y_MIN == 0) ? 1 : five_percent
+hoffset = (GPVAL_Y_MAX == 0) ? 1 : five_percent
+set yrange [(GPVAL_Y_MIN - loffset):(GPVAL_Y_MAX + hoffset)]
+
+
+# redraw with adjusted ranges
+replot
+
+# comment out for debugging
+exit
+
+# .png output:
+set terminal png enhanced transparent nointerlace truecolor #medium #crop
+set output "./gnumed-lab.png"
+replot
+
+# ASCII art output:
+set terminal dumb size 120,40 enhanced
+set output "./gnumed-lab.txt"
+replot
diff --git a/server/sql/v20-v21/data/v21-gm2gpl-plot_two_tests.gpl b/server/sql/v20-v21/data/v21-gm2gpl-plot_two_tests.gpl
new file mode 100644
index 0000000..3c914a4
--- /dev/null
+++ b/server/sql/v20-v21/data/v21-gm2gpl-plot_two_tests.gpl
@@ -0,0 +1,73 @@
+#----------------------------------------------------
+# GNUmed gnuplot graphing script example:
+#
+# plot two test result types into one plot
+#----------------------------------------------------
+
+# uncomment for debugging:
+#gm2gpl_datafile = './x-data-2.txt'
+
+
+# general
+#set title "your special title for this template"
+set grid xtics noytics
+#set grid xtics ytics y2tics
+set autoscale
+set datafile missing '<?>'
+set key off
+set key tmargin center vertical Left autotitle columnheader
+set bmargin 7
+
+
+# x axis
+set xtics rotate by -45
+set xdata time
+set timefmt "%Y-%m-%d_%H:%M"
+
+
+# y2 axis
+set autoscale y2
+set ytics nomirror
+set y2tics
+
+
+# plot
+plot gm2gpl_datafile using 1:2:(valid(4) ? column(4) : column(2)):(valid(5) ? column(5) : column(2)):xticlabels(10) index 0 with yerrorbars pointtype 2, \
+     gm2gpl_datafile using 1:2:(sprintf("%s%s", stringcolumn(2), stringcolumn(3))) index 0 notitle with labels offset 0, 1 , \
+     gm2gpl_datafile using 1:2:(valid(4) ? column(4) : $2):(valid(5) ? column(5) : $2):xticlabels(10) index 1 with yerrorbars pointtype 3 axes x1y2, \
+     gm2gpl_datafile using 1:2:(sprintf("%s%s", stringcolumn(2), stringcolumn(3))) index 1 notitle with labels offset 0, 1 axes x1y2
+
+
+# detect and adjust x range by 10% of entire time span
+time_span = GPVAL_X_MAX - GPVAL_X_MIN
+range_offset = time_span * 10 / 100
+set xrange [(GPVAL_X_MIN - range_offset):(GPVAL_X_MAX + range_offset)]
+
+
+# detect and adjust y range by 5%
+five_percent = abs(GPVAL_Y_MIN * 5 / 100)
+loffset = (GPVAL_Y_MIN == 0) ? 1 : five_percent
+hoffset = (GPVAL_Y_MAX == 0) ? 1 : five_percent
+set yrange [(GPVAL_Y_MIN - loffset):(GPVAL_Y_MAX + hoffset)]
+
+five_percent = abs(GPVAL_Y2_MIN * 5 / 100)
+loffset = (GPVAL_Y2_MIN == 0) ? 1 : five_percent
+hoffset = (GPVAL_Y2_MAX == 0) ? 1 : five_percent
+set y2range [(GPVAL_Y2_MIN - loffset):(GPVAL_Y2_MAX + hoffset)]
+
+
+# redraw with adjusted ranges
+replot
+
+# comment out for debugging
+exit
+
+# .png output:
+set terminal png enhanced transparent nointerlace truecolor #medium #crop
+set output "./gnumed-lab.png"
+replot
+
+# ASCII art output:
+set terminal dumb size 120,40 enhanced
+set output "./gnumed-lab.txt"
+replot
diff --git a/server/sql/v20-v21/dynamic/v21-HIT_risk.sql b/server/sql/v20-v21/dynamic/v21-HIT_risk.sql
new file mode 100644
index 0000000..cbb5f5f
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-HIT_risk.sql
@@ -0,0 +1,65 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+-- 
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+delete from ref.keyword_expansion where keyword = 'algo-HIT';
+
+insert into ref.keyword_expansion (
+	fk_staff,
+	keyword,
+	textual_data
+) values (
+	null,
+	'algo-HIT',
+'HIT risk assessment
+-----------------------------------------------------------
+Chest / 141 / 2 / February, 212 Supplement / e499S
+"Treatment and Prevention of Heparin-Induced Thrombocytopenia"
+
+Indication: $[indication for Hep/LMWH]$
+Exposure >4d: $[>4d exposure: Yes/No]$
+Substance: $[name of Hep/LWMH]$
+
+HIT risk in postoperative patients:
+   1-5% -- Heparin, any dose
+ 0.1-1% -- Heparin, flushes (case reports only)
+ 0.1-1% -- LMWH, any dose
+   1-3% -- cardiac surgery (?Heparin)
+
+HIT risk in non-surgical patients:
+     1% -- cancer (?Heparin)
+ 0.1-1% -- Heparin, any dose
+  <0.1% -- Heparin, flushes
+   0.6% -- LMWH, any dose
+   0.4% -- ICU (?Heparin)
+  <0.1% -- Obstetrics (?Heparin)
+
+(risk of HIT from Heparin generally 10x that of HIT from LMWH)
+
+Risk estimate: $[risk estimate]$
+
+If risk > 1% platelet monitoring every 2-3 days from
+day 4 to day 14 or until exposure stops is suggested.
+
+No monitoring is suggested if the risk is < 1%.
+
+Monitor: $[Monitor ?  Yes/No]$
+
+Diagnostic hints:
+ typically at 5-10 days after begin of exposure platelets fall to
+   < 150x10^9/l
+     (occurs in 85-90% of patients developing HIT)
+ or to
+   30-50% of pre-exposure value even if > 150x10^9/l
+     (occurs in 90-95% of patients developing HIT)
+');
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-HIT_risk.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-audit-constraints.sql b/server/sql/v20-v21/dynamic/v21-audit-constraints.sql
new file mode 100644
index 0000000..75d38e5
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-audit-constraints.sql
@@ -0,0 +1,117 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+set check_function_bodies to on;
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+-- audit.audit_fields
+-- actually, there's an INSERT trigger on child tables already
+-- which forces .modified_when to now()
+alter table audit.audit_fields
+	drop constraint if exists
+		audit_audit_fields_sane_modified_when cascade;
+
+alter table audit.audit_fields
+	add constraint audit_audit_fields_sane_modified_when check
+		((modified_when <= clock_timestamp()) IS TRUE)
+;
+
+
+-- add a foreign key which is, however, NOT ENFORCED
+-- this should cue in pg_dump about the needed order
+-- of dumping dem.staff vs other tables ...
+--
+-- actually, this needs to be put into all child tables
+-- and link against dem.staff.db_user (but not be enforced)
+--
+--alter table audit.audit_fields
+--	drop constraint if exists fk_audit_audit_fields_dem_staff_db_user cascade
+--;
+--
+--alter table audit.audit_fields
+--	add constraint fk_audit_audit_fields_dem_staff_db_user
+--		foreign key (modified_by)
+--		references dem.staff(db_user)
+--		on update restrict
+--		on delete restrict
+--		not valid
+--;
+
+
+create or replace function gm.account_is_dbowner_or_staff(_account name)
+	returns boolean
+	language plpgsql
+	as '
+DECLARE
+	_is_owner boolean;
+BEGIN
+	-- is _account member of current db group ?
+--	PERFORM 1 FROM pg_auth_members
+--	WHERE
+--		roleid = (SELECT oid FROM pg_roles WHERE rolname = current_database())
+--			AND
+--		member = (SELECT oid FROM pg_roles WHERE rolname = _account)
+--	;
+--	IF FOUND THEN
+--		-- should catch people on staff, gm-dbo, and postgres
+--		RETURN TRUE;
+--	END IF;
+
+	-- postgres
+	IF _account = ''postgres'' THEN
+		RETURN TRUE;
+	END IF;
+
+	-- on staff list
+	PERFORM 1 FROM dem.staff WHERE db_user = _account;
+	IF FOUND THEN
+		RETURN TRUE;
+	END IF;
+
+	-- owner
+	SELECT pg_catalog.pg_get_userbyid(datdba) = _account INTO STRICT _is_owner FROM pg_catalog.pg_database WHERE datname = current_database();
+	IF _is_owner IS TRUE THEN
+		RETURN TRUE;
+	END IF;
+
+	RETURN FALSE;
+END;';
+
+-- --------------------------------------------------------------
+-- audit.audit_trail
+alter table audit.audit_trail
+	drop constraint if exists
+		audit_audit_trail_sane_orig_when cascade;
+
+alter table audit.audit_trail
+	add constraint audit_audit_trail_sane_orig_when check
+		((orig_when <= clock_timestamp()) IS TRUE)
+;
+
+
+alter table audit.audit_trail
+	drop constraint if exists
+		audit_audit_trail_sane_audit_when cascade;
+
+alter table audit.audit_trail
+	add constraint audit_audit_trail_sane_audit_when check
+		((audit_when <= clock_timestamp()) IS TRUE)
+;
+
+alter table audit.audit_trail
+	drop constraint if exists
+		audit_audit_trail_orig_before_audit_when cascade;
+
+alter table audit.audit_trail
+	add constraint audit_audit_trail_orig_before_audit_when check
+		((orig_when <= audit_when) IS TRUE)
+;
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-audit-audit_constraints.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-blobs-doc_med-dynamic.sql b/server/sql/v20-v21/dynamic/v21-blobs-doc_med-dynamic.sql
new file mode 100644
index 0000000..95398d2
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-blobs-doc_med-dynamic.sql
@@ -0,0 +1,92 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+-- .fk_org_unit
+comment on column blobs.doc_med.fk_org_unit is
+'Optional link to the org unit this document originates from.\n
+Note that the document may contain data from several units but\n
+there will always be one "sender".';
+
+alter table blobs.doc_med
+	drop constraint if exists fk_blobs_doc_med_dem_org_unit_pk cascade
+;
+
+alter table blobs.doc_med
+	add constraint fk_blobs_doc_med_dem_org_unit_pk
+		foreign key (fk_org_unit)
+		references dem.org_unit(pk)
+		on update cascade
+		on delete restrict
+;
+
+-- --------------------------------------------------------------
+drop view if exists blobs.v_doc_med cascade;
+
+create or replace view blobs.v_doc_med as
+select
+	--(select fk_patient from clin.encounter where pk = b_dm.fk_encounter)
+	c_enc.fk_patient
+		as pk_patient,
+	b_dm.pk
+		as pk_doc,
+	b_dm.clin_when
+		as clin_when,
+	b_dt.name
+		as type,
+	_(b_dt.name)
+		as l10n_type,
+	b_dm.ext_ref
+		as ext_ref,
+	b_dm.comment
+		as comment,
+	c_epi.description
+		as episode,
+	c_hi.description
+		as health_issue,
+	c_epi.is_open
+		as episode_open,
+	d_ou.description
+		as unit,
+	d_o.description
+		as organization,
+	b_dm.fk_type
+		as pk_type,
+	b_dm.fk_encounter
+		as pk_encounter,
+	b_dm.fk_episode
+		as pk_episode,
+	c_epi.fk_health_issue
+		as pk_health_issue,
+	b_dm.fk_org_unit
+		as pk_org_unit,
+	d_ou.fk_org
+		as pk_org,
+	b_dm.modified_when
+		as modified_when,
+	b_dm.modified_by
+		as modified_by,
+	b_dm.xmin
+		as xmin_doc_med
+from
+	blobs.doc_med b_dm
+		inner join blobs.doc_type b_dt on (b_dm.fk_type = b_dt.pk)
+		inner join clin.encounter c_enc on (b_dm.fk_encounter = c_enc.pk)
+		inner join clin.episode c_epi on (b_dm.fk_episode = c_epi.pk)
+			-- there are episodes w/o issue link so LEFT join is needed
+			left join clin.health_issue c_hi on (c_hi.pk = c_epi.fk_health_issue)
+		left join dem.org_unit d_ou on (b_dm.fk_org_unit = d_ou.pk)
+			left join dem.org d_o on (d_ou.fk_org = d_o.pk)
+;
+
+GRANT SELECT ON blobs.v_doc_med TO GROUP "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-blobs-doc_med-dynamic.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-blobs-v_doc_desc.sql b/server/sql/v20-v21/dynamic/v21-blobs-v_doc_desc.sql
new file mode 100644
index 0000000..1df0c2c
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-blobs-v_doc_desc.sql
@@ -0,0 +1,32 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+--
+-- ==============================================================
+drop view if exists blobs.v_doc_desc cascade;
+
+create view blobs.v_doc_desc as
+select
+	vdm.pk_patient as pk_patient,
+	dd.fk_doc as pk_doc,
+	dd.text as description,
+	vdm.pk_encounter as pk_encounter,
+	vdm.pk_episode as pk_episode,
+	vdm.pk_health_issue as pk_health_issue,
+	dd.pk as pk_doc_desc
+from
+	blobs.doc_desc dd,
+	blobs.v_doc_med vdm
+where
+	dd.fk_doc = vdm.pk_doc
+;
+
+comment on view blobs.v_doc_desc is
+	'aggregates some document data descriptions';
+
+grant select on blobs.v_doc_desc to group "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-blobs-v_doc_desc.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-blobs-v_doc_med_journal.sql b/server/sql/v20-v21/dynamic/v21-blobs-v_doc_med_journal.sql
new file mode 100644
index 0000000..d38c20b
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-blobs-v_doc_med_journal.sql
@@ -0,0 +1,93 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+
+-- --------------------------------------------------------------
+drop view if exists blobs.v_doc_med_journal cascade;
+
+create view blobs.v_doc_med_journal as
+select
+	c_enc.fk_patient
+		as pk_patient,
+	b_dm.modified_when
+		as modified_when,
+	b_dm.clin_when
+		as clin_when,
+	coalesce (
+		(select short_alias from dem.staff where db_user = b_dm.modified_by),
+		'<' || b_dm.modified_by || '>'
+	)
+		as modified_by,
+	null::text
+		as soap_cat,
+	'"' || (_(b_dt.name) || '" '
+		|| _('with') || ' ' || (select count(1) from blobs.doc_obj b_do where b_do.fk_doc = b_dm.pk) || ' ' || _('part(s)') || E'\n'
+		|| ' ' || to_char(b_dm.clin_when, 'YYYY-MM-DD HH24:MI') || E'\n'
+		|| coalesce(' [' || b_dm.ext_ref || ']', '') || coalesce(' @ ' || d_ou.description || ' ' || _('of') || ' ' || d_o.description, '') || E'\n'
+		|| coalesce(' ' || b_dm.comment, '')
+	)	as narrative,
+	b_dm.fk_encounter
+		as pk_encounter,
+	b_dm.fk_episode
+		as pk_episode,
+	c_epi.fk_health_issue
+		as pk_health_issue,
+	b_dm.pk
+		as src_pk,
+	'blobs.doc_med'::text
+		as src_table,
+	b_dm.row_version,
+
+	-- issue
+	c_hi.description
+		as health_issue,
+	c_hi.laterality
+		as issue_laterality,
+	c_hi.is_active
+		as issue_active,
+	c_hi.clinically_relevant
+		as issue_clinically_relevant,
+	c_hi.is_confidential
+		as issue_confidential,
+
+	-- episode
+	c_epi.description
+		as episode,
+	c_epi.is_open
+		as episode_open,
+
+	-- encounter
+	c_enc.started
+		as encounter_started,
+	c_enc.last_affirmed
+		as encounter_last_affirmed,
+	c_ety.description
+		as encounter_type,
+	_(c_ety.description)
+		as encounter_l10n_type
+
+from
+	blobs.doc_med b_dm
+		inner join clin.encounter c_enc on (b_dm.fk_encounter = c_enc.pk)
+			inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+				inner join blobs.doc_type b_dt on (b_dm.fk_type = b_dt.pk)
+					inner join clin.episode c_epi on (b_dm.fk_episode = c_epi.pk)
+						left join clin.health_issue c_hi on (c_epi.fk_health_issue = c_hi.pk)
+							left join dem.org_unit d_ou on (b_dm.fk_org_unit = d_ou.pk)
+								left join dem.org d_o on (d_ou.fk_org = d_o.pk)
+;
+
+
+grant select on blobs.v_doc_med_journal TO GROUP "gm-doctors";
+
+-- --------------------------------------------------------------
+select i18n.upd_tx('de', 'part(s)', 'Teil(e)');
+select i18n.upd_tx('de', 'with', 'mit');
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-blobs-v_doc_med_journal.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-blobs-v_latest_mugshot.sql b/server/sql/v20-v21/dynamic/v21-blobs-v_latest_mugshot.sql
new file mode 100644
index 0000000..abc22ec
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-blobs-v_latest_mugshot.sql
@@ -0,0 +1,52 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+-- 
+-- ==============================================================
+\set ON_ERROR_STOP 1
+
+-- --------------------------------------------------------------
+-- remember to handle dependant objects possibly dropped by CASCADE
+drop view if exists blobs.v_latest_mugshot cascade;
+
+create view blobs.v_latest_mugshot as
+select
+	vo4d.pk_patient as pk_patient,
+	vo4d.doc_comment as doc_comment,
+	vo4d.date_generated as date_taken,
+	vo4d.ext_ref as ext_ref,
+	vo4d.seq_idx as obj_seq_idx,
+	vo4d.obj_comment as obj_comment,
+	vo4d.pk_doc as pk_doc,
+	vo4d.pk_obj as pk_obj,
+	bdo.data as image
+from
+	blobs.v_obj4doc_no_data vo4d,
+	blobs.doc_obj bdo
+where
+	vo4d.type = 'patient photograph'
+		and
+	vo4d.seq_idx = (
+		select max(vo4d1.seq_idx)
+		from blobs.v_obj4doc_no_data vo4d1
+		where
+			vo4d1.pk_patient = vo4d.pk_patient
+				and
+			vo4d1.type = 'patient photograph'
+		group by date_generated
+		order by date_generated desc limit 1
+	)
+		and
+	bdo.pk = vo4d.pk_obj
+;
+
+comment on view blobs.v_latest_mugshot is
+	'shows the latest picture of the patient, currently the highest
+	 seq_idx of the newest document of type "patient photograph"';
+
+grant select on blobs.v_latest_mugshot to group "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-blobs-v_latest_mugshot.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-blobs-v_obj4doc_no_data.sql b/server/sql/v20-v21/dynamic/v21-blobs-v_obj4doc_no_data.sql
new file mode 100644
index 0000000..773fe45
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-blobs-v_obj4doc_no_data.sql
@@ -0,0 +1,77 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+--
+-- ==============================================================
+drop view if exists blobs.v_obj4doc_no_data cascade;
+
+create view blobs.v_obj4doc_no_data as
+select
+	b_vdm.pk_patient
+		as pk_patient,
+	b_do.pk
+		as pk_obj,
+	b_do.seq_idx
+		as seq_idx,
+	octet_length(coalesce(b_do.data, ''))
+		as size,
+	b_vdm.clin_when
+		as date_generated,
+	b_vdm.type
+		as type,
+	b_vdm.l10n_type
+		as l10n_type,
+	b_vdm.ext_ref
+		as ext_ref,
+	b_vdm.episode
+		as episode,
+	b_vdm.comment
+		as doc_comment,
+	b_do.comment
+		as obj_comment,
+	b_do.filename
+		as filename,
+	b_do.fk_intended_reviewer
+		as pk_intended_reviewer,
+	exists(select 1 from blobs.reviewed_doc_objs where fk_reviewed_row = b_do.pk)
+		as reviewed,
+	exists (
+		select 1 from blobs.reviewed_doc_objs
+		where
+			fk_reviewed_row = b_do.pk and
+			fk_reviewer = (select pk from dem.staff where db_user = current_user)
+		) as reviewed_by_you,
+	exists (
+		select 1 from blobs.reviewed_doc_objs
+		where
+			fk_reviewed_row = b_do.pk and
+			fk_reviewer = b_do.fk_intended_reviewer
+		) as reviewed_by_intended_reviewer,
+	b_vdm.pk_doc
+		as pk_doc,
+	b_vdm.pk_type
+		as pk_type,
+	b_vdm.pk_encounter
+		as pk_encounter,
+	b_vdm.pk_episode
+		as pk_episode,
+	b_vdm.pk_health_issue
+		as pk_health_issue,
+	b_do.xmin
+		as xmin_doc_obj
+from
+	blobs.v_doc_med b_vdm
+		inner join blobs.doc_obj b_do on (b_do.fk_doc = b_vdm.pk_doc)
+where
+	b_vdm.pk_doc = b_do.fk_doc
+;
+
+comment on view blobs.v_obj4doc_no_data is
+	'denormalized metadata for blobs.doc_obj but without the data itself';
+
+GRANT SELECT ON blobs.v_obj4doc_no_data TO GROUP "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-blobs-v_obj4doc_no_data.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-blobs-v_reviewed_doc_objects.sql b/server/sql/v20-v21/dynamic/v21-blobs-v_reviewed_doc_objects.sql
new file mode 100644
index 0000000..c8c103a
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-blobs-v_reviewed_doc_objects.sql
@@ -0,0 +1,45 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+--
+-- ==============================================================
+-- remember to handle dependant objects possibly dropped by CASCADE
+drop view if exists blobs.v_reviewed_doc_objects cascade;
+
+create view blobs.v_reviewed_doc_objects as
+select
+	rdo.fk_reviewed_row as pk_doc_obj,
+	coalesce (
+		(select short_alias from dem.staff where pk=rdo.fk_reviewer),
+		'<#' || rdo.fk_reviewer || '>'
+	) as reviewer,
+	rdo.is_technically_abnormal as is_technically_abnormal,
+	rdo.clinically_relevant as clinically_relevant,
+	exists(select 1 from blobs.doc_obj where pk=rdo.fk_reviewed_row and fk_intended_reviewer=rdo.fk_reviewer)
+		as is_review_by_responsible_reviewer,
+	exists(select 1 from dem.staff where pk=rdo.fk_reviewer and db_user=CURRENT_USER)
+		as is_your_review,
+	rdo.comment,
+	rdo.modified_when as reviewed_when,
+	rdo.modified_by as modified_by,
+	rdo.pk as pk_review_root,
+	rdo.fk_reviewer as pk_reviewer,
+	(select pk_patient from blobs.v_obj4doc_no_data where pk_obj=rdo.fk_reviewed_row)
+		as pk_patient,
+	(select pk_encounter from blobs.v_obj4doc_no_data where pk_obj=rdo.fk_reviewed_row)
+		as pk_encounter,
+	(select pk_episode from blobs.v_obj4doc_no_data where pk_obj=rdo.fk_reviewed_row)
+		as pk_episode,
+	(select pk_health_issue from blobs.v_obj4doc_no_data where pk_obj=rdo.fk_reviewed_row)
+		as pk_health_issue
+from
+	blobs.reviewed_doc_objs rdo
+;
+
+
+grant select on blobs.v_reviewed_doc_objects to group "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-blobs-v_reviewed_doc_objects.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-cfg-cfg_str_array-dynamic.sql b/server/sql/v20-v21/dynamic/v21-cfg-cfg_str_array-dynamic.sql
new file mode 100644
index 0000000..1ea4fa4
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-cfg-cfg_str_array-dynamic.sql
@@ -0,0 +1,52 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+update cfg.cfg_str_array set
+	value = '{"gmProviderInboxPlugin","gmWaitingListPlugin","gmPatientOverviewPlugin","gmNotebookedPatientEditionPlugin","gmEMRBrowserPlugin","gmEMRListJournalPlugin","gmSoapPlugin","gmCurrentSubstancesPlugin","gmMeasurementsPlugin","gmShowMedDocs","gmScanIdxMedDocsPlugin","gmPACSPlugin","gmExportAreaPlugin","gmEMRTimelinePlugin","gmPrintManagerPlugin","gmDataMiningPlugin","gmSimpleSoapPlugin","gmEMRJournalPlugin","gmBillingPlugin","gmKOrganizerPlugin","gmXdtViewer"}'
+where
+	fk_item in (
+		select pk_cfg_item
+		from cfg.v_cfg_options
+		where
+			workplace = 'GNUmed Default'
+			and option = 'horstspace.notebook.plugin_load_order'
+		)
+;
+
+-- --------------------------------------------------------------
+update cfg.cfg_str_array set
+	value = '{"gmProviderInboxPlugin","gmWaitingListPlugin","gmPatientOverviewPlugin","gmNotebookedPatientEditionPlugin","gmEMRBrowserPlugin","gmEMRListJournalPlugin","gmSoapPlugin","gmEMRListJournalPlugin","gmCurrentSubstancesPlugin","gmMeasurementsPlugin","gmShowMedDocs","gmPACSPlugin","gmScanIdxMedDocsPlugin","gmExportAreaPlugin","gmEMRTimelinePlugin","gmDataMiningPlugin","gmSimpleSoapPlugin","gmEMRJournalPlugin","gmBillingPlugin","gmPrintManagerPlugin"}'
+where
+	fk_item in (
+		select pk_cfg_item
+		from cfg.v_cfg_options
+		where
+			workplace = 'Clinician'
+			and option = 'horstspace.notebook.plugin_load_order'
+		)
+;
+
+-- --------------------------------------------------------------
+update cfg.cfg_str_array set
+	value = '{"gmProviderInboxPlugin","gmWaitingListPlugin","gmNotebookedPatientEditionPlugin","gmPrintManagerPlugin","gmScanIdxMedDocsPlugin","gmExportAreaPlugin","gmKOrganizerPlugin"}'
+where
+	fk_item in (
+		select pk_cfg_item
+		from cfg.v_cfg_options
+		where
+			workplace = 'Front Desk'
+	 			and
+			option = 'horstspace.notebook.plugin_load_order'
+		)
+;
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-cfg-cfg_str_array-dynamic.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-procedure-dynamic.sql b/server/sql/v20-v21/dynamic/v21-clin-procedure-dynamic.sql
new file mode 100644
index 0000000..56297a4
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-procedure-dynamic.sql
@@ -0,0 +1,54 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+update clin.procedure set
+	is_ongoing = False
+where
+	is_ongoing is True
+		and
+	clin_end is not null
+		and
+	clin_end < (now() + '15 minutes'::interval)
+;
+
+-- --------------------------------------------------------------
+alter table clin.procedure
+	drop constraint if exists
+		procedure_sane_ongoing
+;
+
+-- --------------------------------------------------------------
+drop function if exists clin.trf_normalize_proc_is_ongoing() cascade;
+
+create function clin.trf_normalize_proc_is_ongoing()
+	returns trigger
+	language 'plpgsql'
+	as '
+BEGIN
+	if NEW.clin_end > clock_timestamp() then
+		NEW.is_ongoing := TRUE;
+	else
+		NEW.is_ongoing := FALSE;
+	end if;
+
+	return NEW;
+END;';
+
+
+create trigger tr_normalize_proc_is_ongoing
+	before update or insert on clin.procedure
+	for each row
+	when (NEW.clin_end IS NOT NULL)
+	execute procedure clin.trf_normalize_proc_is_ongoing()
+;
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-procedure-dynamic.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-sanity_checks.sql b/server/sql/v20-v21/dynamic/v21-clin-sanity_checks.sql
new file mode 100644
index 0000000..cb1e3b3
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-sanity_checks.sql
@@ -0,0 +1,122 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+set check_function_bodies to on;
+
+-- --------------------------------------------------------------
+create or replace function gm.create_enc_epi_sanity_check_trigger(_schema_name name, _table_name name, _fk_encounter_col name, _fk_episode_col name)
+	returns boolean
+	language plpgsql
+	as '
+DECLARE
+	_qualified_table2check text;
+	_msg text;
+	_cmd text;
+BEGIN
+	_qualified_table2check := _schema_name || ''.'' || _table_name;
+	raise notice ''gm.create_enc_epi_sanity_check_trigger(): % (.% vs .%)'', _qualified_table2check, _fk_encounter_col, _fk_episode_col;
+
+	-- verify table exists
+	if not exists(select 1 from information_schema.tables where table_schema = _schema_name and table_name = _table_name) then
+		raise warning ''gm.create_enc_epi_sanity_check_trigger(): table <%> does not exist'', _qualified_table2check;
+		raise exception undefined_table;
+		return false;
+	end if;
+
+	-- verify that it points to clin.encounter.pk
+	if not exists (
+		select 1
+		from
+			pg_catalog.pg_constraint fk_tbl
+		where
+			fk_tbl.contype = ''f''
+				AND
+			fk_tbl.confrelid = ''clin.encounter''::regclass
+				AND
+			fk_tbl.conrelid = _qualified_table2check::regclass
+				AND
+			fk_tbl.confkey[1] = (
+				select attnum from pg_catalog.pg_attribute col_tbl
+				where
+					col_tbl.attname = ''pk''
+						AND
+					col_tbl.attrelid = ''clin.encounter''::regclass
+			)
+				AND
+			fk_tbl.conkey[1] = (
+				select attnum from pg_catalog.pg_attribute col_tbl
+				where
+					col_tbl.attname = _fk_encounter_col
+						AND
+					col_tbl.attrelid = _qualified_table2check::regclass
+			)
+	) then
+		raise exception
+			''gm.create_enc_epi_sanity_check_trigger(): <%.%> does not point to clin.encounter.pk'', _qualified_table2check, _fk_encounter_col
+			USING ERRCODE = ''invalid_foreign_key''
+		;
+		return false;
+	end if;
+
+	-- verify that it points to clin.episode.pk
+	if not exists (
+		select 1
+		from
+			pg_catalog.pg_constraint fk_tbl
+		where
+			fk_tbl.contype = ''f''
+				AND
+			fk_tbl.confrelid = ''clin.episode''::regclass
+				AND
+			fk_tbl.conrelid = _qualified_table2check::regclass
+				AND
+			fk_tbl.confkey[1] = (
+				select attnum from pg_catalog.pg_attribute col_tbl
+				where
+					col_tbl.attname = ''pk''
+						AND
+					col_tbl.attrelid = ''clin.episode''::regclass
+			)
+				AND
+			fk_tbl.conkey[1] = (
+				select attnum from pg_catalog.pg_attribute col_tbl
+				where
+					col_tbl.attname = _fk_episode_col
+						AND
+					col_tbl.attrelid = _qualified_table2check::regclass
+			)
+	) then
+		raise exception
+			''gm.create_enc_epi_sanity_check_trigger(): <%.%> does not point to clin.episode.pk'', _qualified_table2check, _fk_episode_col
+			USING ERRCODE = ''invalid_foreign_key''
+		;
+		return false;
+	end if;
+
+	-- re-create trigger
+	_cmd := ''drop trigger if exists tr_sanity_check_enc_epi_ins_upd on '' || _qualified_table2check || '' cascade'';
+	execute _cmd;
+	_cmd := ''create trigger tr_sanity_check_enc_epi_ins_upd '';
+	_cmd := _cmd || ''before insert or update '';
+	_cmd := _cmd || ''on '' || _qualified_table2check || '' '';
+	_cmd := _cmd || ''for each row when (NEW.fk_episode is not null) '';
+	_cmd := _cmd || ''execute procedure clin.trf_sanity_check_enc_epi_ins_upd('''''' || _fk_encounter_col || '''''', '''''' || _fk_episode_col || '''''')'';
+	execute _cmd;
+
+	return True;
+END;
+';
+
+
+comment on function gm.create_enc_epi_sanity_check_trigger(_schema_name name, _table_name name, _fk_encounter_col name, _fk_episode_col name) is
+	'This function can be run on any table in order to add enccounter <-> episode sanity check triggers to that table.';
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-sanity_checks.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-substance_intake-dynamic.sql b/server/sql/v20-v21/dynamic/v21-clin-substance_intake-dynamic.sql
new file mode 100644
index 0000000..ab54a3e
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-substance_intake-dynamic.sql
@@ -0,0 +1,337 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+set check_function_bodies to on;
+
+-- --------------------------------------------------------------
+comment on column clin.substance_intake.comment_on_start is 'Comment (uncertainty level) on .clin_when = started. "?" = "entirely unknown".';
+
+alter table clin.substance_intake
+	alter column comment_on_start
+		set default NULL;
+
+alter table clin.substance_intake
+	drop constraint if exists clin_substance_intake_sane_start_comment;
+
+alter table clin.substance_intake
+	add constraint clin_substance_intake_sane_start_comment check (
+		gm.is_null_or_non_empty_string(comment_on_start)
+	);
+
+-- --------------------------------------------------------------
+comment on column clin.substance_intake.harmful_use_type is
+	'NULL=not considered=medication, 0=no or not considered harmful, 1=presently harmful use, 2=presently addicted, 3=previously addicted';
+
+
+alter table clin.substance_intake
+	drop constraint if exists clin_patient_sane_use_type;
+
+alter table clin.substance_intake
+	add constraint clin_patient_sane_use_type check (
+		(harmful_use_type IS NULL)
+			OR
+		(harmful_use_type between 0 and 3)
+	);
+
+-- --------------------------------------------------------------
+-- .fk_substance / .fk_drug_component
+drop function if exists clin.trf_update_intake_updates_all_drug_components() cascade;
+drop function if exists clin.trf_upd_intake_updates_all_drug_components() cascade;
+
+create or replace function clin.trf_upd_intake_updates_all_drug_components()
+	returns trigger
+	language 'plpgsql'
+	as '
+DECLARE
+	_pk_brand integer;
+	_component_count integer;
+	_pk_patient integer;
+BEGIN
+	-- which drug ?
+	select fk_brand into _pk_brand
+	from ref.lnk_substance2brand
+	where pk = NEW.fk_drug_component;
+
+	-- how many components therein ?
+	select count(1) into _component_count
+	from ref.lnk_substance2brand
+	where fk_brand = _pk_brand;
+
+	-- only one component ?
+	if _component_count = 1 then
+		return NEW;
+	end if;
+
+	-- which patient ?
+	select fk_patient into _pk_patient
+	from clin.encounter
+	where pk = NEW.fk_encounter;
+
+	-- update all substance instake fields shared by drug components ...
+	update clin.substance_intake set
+		clin_when = NEW.clin_when,				-- started
+		fk_encounter = NEW.fk_encounter,
+		soap_cat = NEW.soap_cat,
+		schedule = NEW.schedule,
+		duration = NEW.duration,
+		intake_is_approved_of = NEW.intake_is_approved_of,
+		is_long_term = NEW.is_long_term,
+		discontinued = NEW.discontinued
+	where
+		-- ... which belong to this drug ...
+		fk_drug_component in (
+			select pk from ref.lnk_substance2brand where fk_brand = _pk_brand
+		)
+			AND
+		-- ... but are not THIS component ...
+		fk_drug_component != NEW.fk_drug_component
+			AND
+		-- ... this patient ...
+		fk_encounter in (
+			select pk from clin.encounter where fk_patient = _pk_patient
+		)
+			AND
+		-- ... are different in value (this will stop recursion as soon as all are equal)
+		(
+			clin_when is distinct from NEW.clin_when
+				OR
+			fk_encounter is distinct from NEW.fk_encounter
+				OR
+			soap_cat is distinct from NEW.soap_cat
+				OR
+			schedule is distinct from NEW.schedule
+				OR
+			duration is distinct from NEW.duration
+				OR
+			intake_is_approved_of is distinct from NEW.intake_is_approved_of
+				OR
+			is_long_term is distinct from NEW.is_long_term
+				OR
+			discontinued is distinct from NEW.discontinued
+		)
+	;
+	return NEW;
+END;';
+
+comment on function clin.trf_upd_intake_updates_all_drug_components() is
+	'If a drug component substance intake is updated all sibling components must receive some values thereof.';
+
+create constraint trigger tr_upd_intake_updates_all_drug_components
+	after update on clin.substance_intake
+		deferrable
+		initially deferred
+	for each row when (
+		(pg_trigger_depth() = 0)
+			and
+		(NEW.fk_drug_component is not null)
+	)
+	execute procedure clin.trf_upd_intake_updates_all_drug_components();
+
+-- --------------------------------------------------------------
+drop function if exists clin.trf_insert_update_intake_prevent_duplicate_substance_links() cascade;
+drop function if exists clin.trf_ins_upd_intake_prevent_duplicate_substance_links() cascade;
+
+create or replace function clin.trf_ins_upd_intake_prevent_duplicate_substance_links()
+	returns trigger
+	language 'plpgsql'
+	as '
+DECLARE
+	_pk_patient integer;
+	_link_count integer;
+	_msg text;
+BEGIN
+	-- which patient ?
+	select fk_patient into _pk_patient
+	from clin.encounter
+	where pk = NEW.fk_encounter;
+
+	-- more than one link ?
+	select count(1) into _link_count
+	from clin.substance_intake
+	where
+		-- for this substance
+		fk_substance = NEW.fk_substance
+			and
+		-- either already linked as component OR
+		-- already linked as substance
+		fk_drug_component IS NOT DISTINCT FROM NEW.fk_drug_component
+			and
+		-- in this one patient
+		fk_encounter in (
+			select pk from clin.encounter where fk_patient = _pk_patient
+		)
+	;
+
+	if _link_count > 1 then
+		_msg := ''[clin.trf_ins_upd_intake_prevent_duplicate_substance_links]: substance ref.consumable_substance.pk=('' || NEW.fk_substance || '') ''
+			|| ''already linked to patient=('' || _pk_patient || '') '';
+		raise exception unique_violation using message = _msg;
+	end if;
+
+	return NEW;
+END;';
+
+comment on function clin.trf_ins_upd_intake_prevent_duplicate_substance_links() is
+	'Prevent patient from being put on a particular substance more than once.';
+
+create constraint trigger tr_ins_upd_intake_prevent_duplicate_substance_links
+	after insert or update on clin.substance_intake
+	deferrable
+	initially deferred
+		for each row execute procedure clin.trf_ins_upd_intake_prevent_duplicate_substance_links()
+;
+
+-- --------------------------------------------------------------
+drop function if exists clin.trf_ins_intake_set_substance_from_component() cascade;
+
+create function clin.trf_ins_intake_set_substance_from_component()
+	returns trigger
+	language 'plpgsql'
+	as '
+BEGIN
+	-- load fk_substance from drug_component table
+	select
+		r_ls2b.fk_substance into strict NEW.fk_substance
+	from
+		ref.lnk_substance2brand r_ls2b
+	where
+		r_ls2b.pk = NEW.fk_drug_component
+	;
+	return NEW;
+END;';
+
+comment on function clin.trf_ins_intake_set_substance_from_component() is
+	'On INSERT of a substance intake set fk_substance from fk_drug_component if the latter is NOT NULL.';
+
+create trigger tr_ins_intake_set_substance_from_component
+	before INSERT on clin.substance_intake
+	for each row when (NEW.fk_drug_component is not null)
+	execute procedure clin.trf_ins_intake_set_substance_from_component();
+
+-- --------------------------------------------------------------
+drop function if exists clin.trf_upd_intake_set_substance_from_component() cascade;
+
+create function clin.trf_upd_intake_set_substance_from_component()
+	returns trigger
+	language 'plpgsql'
+	as '
+BEGIN
+	-- load fk_substance from drug_component table
+	select
+		r_ls2b.fk_substance into strict NEW.fk_substance
+	from
+		ref.lnk_substance2brand r_ls2b
+	where
+		r_ls2b.pk = NEW.fk_drug_component
+	;
+	return NEW;
+END;';
+
+comment on function clin.trf_upd_intake_set_substance_from_component() is
+	'On UPDATE of a substance intake set fk_substance from fk_drug_component if the latter changes.';
+
+create trigger tr_upd_intake_set_substance_from_component
+	before UPDATE on clin.substance_intake
+	for each row when (
+		(NEW.fk_drug_component is not null)
+			and
+		(NEW.fk_drug_component is distinct from OLD.fk_drug_component)
+	)
+	execute procedure clin.trf_upd_intake_set_substance_from_component();
+
+-- --------------------------------------------------------------
+alter table clin.substance_intake
+	drop constraint if exists clin_subst_intake_either_drug_or_substance cascade;
+
+-- --------------------------------------------------------------
+-- normalize existing records
+update clin.substance_intake set
+	fk_substance = (
+		select r_ls2b.fk_substance
+		from ref.lnk_substance2brand r_ls2b
+		where r_ls2b.pk = fk_drug_component
+	)
+where
+	fk_substance is null
+;
+
+-- --------------------------------------------------------------
+alter table clin.substance_intake
+	alter column fk_substance
+		set not null;
+
+-- --------------------------------------------------------------
+-- DELETE substance intake
+drop function if exists clin.trf_delete_intake_document_deleted() cascade;
+
+create function clin.trf_delete_intake_document_deleted()
+	returns trigger
+	language 'plpgsql'
+	as '
+DECLARE
+	_row record;
+	_pk_episode integer;
+BEGIN
+	select
+		* into _row
+	from
+		clin.v_substance_intake_journal
+	where
+		src_pk = OLD.pk;
+
+	_pk_episode := _row.pk_episode;
+
+	-- create episode if needed
+	if _pk_episode is null then
+		select pk into _pk_episode
+		from clin.episode
+		where
+			description = _(''Medication history'')
+				and
+			fk_encounter in (
+				select pk from clin.encounter where fk_patient = _row.pk_patient
+			);
+		if not found then
+			insert into clin.episode (
+				description,
+				is_open,
+				fk_encounter
+			) values (
+				_(''Medication history''),
+				FALSE,
+				OLD.fk_encounter
+			) returning pk into _pk_episode;
+		end if;
+	end if;
+
+	insert into clin.clin_narrative (
+		fk_encounter,
+		fk_episode,
+		soap_cat,
+		narrative
+	) values (
+		_row.pk_encounter,
+		_pk_episode,
+		NULL,
+		_(''Deletion of'') || '' '' || _row.narrative
+	);
+
+	return OLD;
+END;';
+
+comment on function clin.trf_delete_intake_document_deleted() is
+	'Document the deletion of a substance intake.';
+
+create trigger tr_delete_intake_document_deleted
+	before delete on clin.substance_intake
+	for each row execute procedure clin.trf_delete_intake_document_deleted();
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-substance_intake-dynamic.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_edc_journal.sql b/server/sql/v20-v21/dynamic/v21-clin-v_edc_journal.sql
new file mode 100644
index 0000000..c973016
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_edc_journal.sql
@@ -0,0 +1,90 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_edc_journal cascade;
+
+
+create view clin.v_edc_journal as
+select
+	c_p.fk_identity
+		as pk_patient,
+	c_p.modified_when
+		as modified_when,
+	c_p.modified_when
+		as clin_when,
+	coalesce (
+		(select short_alias from dem.staff where db_user = c_p.modified_by),
+		'<' || c_p.modified_by || '>'
+	)
+		as modified_by,
+	's'::text
+		as soap_cat,
+	_('EDC') || to_char(c_p.edc, ': YYYY Mon DD')
+		as narrative,
+	(
+		select c_e.pk
+		from clin.encounter c_e
+		where c_e.fk_patient = c_p.fk_identity
+		order by started desc
+		limit 1
+	)
+		as pk_encounter,
+	null::integer
+		as pk_episode,
+	null::integer
+		as pk_health_issue,
+	c_p.pk
+		as src_pk,
+	'clin.patient'::text
+		as src_table,
+	c_p.row_version
+		as row_version,
+
+	-- issue
+	null::text
+		as health_issue,
+	null::text
+		as issue_laterality,
+	null::boolean
+		as issue_active,
+	null::boolean
+		as issue_clinically_relevant,
+	null::boolean
+		as issue_confidential,
+
+	-- episode
+	null::text
+		as episode,
+	null::boolean
+		as episode_open,
+
+	-- encounter
+	null::timestamp with time zone
+		as encounter_started,
+	null::timestamp with time zone
+		as encounter_last_affirmed,
+	null::text
+		as encounter_type,
+	null::text
+		as encounter_l10n_type
+from
+	clin.patient c_p
+where
+	c_p.edc is not NULL
+;
+
+grant select on clin.v_edc_journal to group "gm-doctors";
+
+-- --------------------------------------------------------------
+select i18n.upd_tx('de', 'EDC', 'Geburtstermin');
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_edc_journal.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_emr_journal.sql b/server/sql/v20-v21/dynamic/v21-clin-v_emr_journal.sql
new file mode 100644
index 0000000..927ba6d
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_emr_journal.sql
@@ -0,0 +1,94 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten.Hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_emr_journal cascade;
+
+
+create view clin.v_emr_journal as
+
+	select * from clin.v_pat_narrative_journal
+
+union all
+
+	select * from clin.v_health_issues_journal
+
+union all
+
+	select * from clin.v_pat_encounters_journal
+
+union all
+
+	select * from clin.v_pat_episodes_journal
+
+union all
+
+	select * from clin.v_family_history_journal
+
+union all
+
+	select * from clin.v_pat_allergies_journal
+
+union all
+
+	select * from clin.v_pat_allergy_state_journal
+
+union all
+
+	select * from clin.v_test_results_journal
+
+union all
+
+	select * from clin.v_hospital_stays_journal
+
+union all
+
+	select * from blobs.v_doc_med_journal
+
+union all
+
+	select * from clin.v_substance_intake_journal
+
+union all
+
+	select * from clin.v_procedures_journal
+
+union all
+
+	select * from clin.v_vaccinations_journal
+
+union all
+
+	select * from clin.v_suppressed_hints_journal
+
+union all
+
+	select * from clin.v_external_care_journal
+
+union all
+
+	select * from clin.v_edc_journal
+
+union all
+
+	select * from clin.v_reminders_journal
+
+;
+
+comment on view clin.v_emr_journal is
+	'Clinical patient data formatted into one string per
+	 clinical entity even if it constains several user-
+	 visible fields. Mainly useful for display as a simple
+	 EMR journal.';
+
+
+grant select on clin.v_emr_journal to group "gm-doctors";
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_emr_journal.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_export_items.sql b/server/sql/v20-v21/dynamic/v21-clin-v_export_items.sql
new file mode 100644
index 0000000..4bf41a5
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_export_items.sql
@@ -0,0 +1,75 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_export_items cascade;
+
+create view clin.v_export_items as
+select
+	inner_export_items.*,
+	d_vp.title,
+	d_vp.firstnames,
+	d_vp.lastnames,
+	d_vp.preferred,
+	d_vp.gender,
+	d_vp.dob
+from (
+	select
+		c_ei.pk
+			as pk_export_item,
+		coalesce (
+			c_ei.fk_identity,
+			(select fk_patient from clin.encounter where
+				pk = (
+					select fk_encounter from blobs.doc_med where pk = (
+						select fk_doc from blobs.doc_obj where pk = c_ei.fk_doc_obj
+					)
+				)
+			)
+		)	as pk_identity,
+		coalesce (
+			(select short_alias from dem.staff where db_user = c_ei.created_by),
+			c_ei.created_by
+		)
+			as created_by,
+		c_ei.created_when
+			as created_when,
+		c_ei.designation
+			as designation,
+		c_ei.description
+			as description,
+		c_ei.fk_doc_obj
+			as pk_doc_obj,
+		md5(coalesce (
+			c_ei.data,
+			coalesce (
+				(select b_do.data from blobs.doc_obj b_do where b_do.pk = c_ei.fk_doc_obj),
+				''
+			)
+		)) as md5_sum,
+		octet_length(coalesce(c_ei.data, ''::bytea)) as size,
+		coalesce (
+			c_ei.filename,
+			(select b_do.filename from blobs.doc_obj b_do where b_do.pk = c_ei.fk_doc_obj)
+		) as filename,
+		c_ei.xmin
+			as xmin_export_item
+	from
+		clin.export_item c_ei
+	) as inner_export_items
+	join dem.v_all_persons d_vp on d_vp.pk_identity = inner_export_items.pk_identity
+;
+
+
+revoke all on clin.v_export_items from public;
+grant select on clin.v_export_items to group "gm-staff";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_export_items.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_external_care_journal.sql b/server/sql/v20-v21/dynamic/v21-clin-v_external_care_journal.sql
new file mode 100644
index 0000000..b40e1e3
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_external_care_journal.sql
@@ -0,0 +1,90 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_external_care_journal cascade;
+
+create view clin.v_external_care_journal as
+select
+	c_enc.fk_patient
+		as pk_patient,
+	c_ec.modified_when
+		as modified_when,
+	c_ec.modified_when
+		as clin_when,
+	coalesce (
+		(select short_alias from dem.staff where db_user = c_ec.modified_by),
+		'<' || c_ec.modified_by || '>'
+	)
+		as modified_by,
+	's'::text
+		as soap_cat,
+	_('External care')
+		|| coalesce(' ' || _('by') || ' ' || c_ec.provider, '')
+		|| ' @ ' || d_ou.description || ' ' || _('of') || ' ' || d_o.description || E'\n'
+		|| _('Issue:') || ' ' || coalesce(c_hi.description, c_ec.issue) || E'\n'
+		|| coalesce(_('Comment:') || ' ' || c_ec.comment, '')
+		as narrative,
+	c_ec.fk_encounter
+		as pk_encounter,
+	NULL::integer
+		as pk_episode,
+	c_ec.fk_health_issue
+		as pk_health_issue,
+	c_ec.pk
+		as src_pk,
+	'clin.external_care'::text
+		as src_table,
+	c_ec.row_version
+		as row_version,
+
+	-- issue
+	c_hi.description
+		as health_issue,
+	c_hi.laterality
+		as issue_laterality,
+	c_hi.is_active
+		as issue_active,
+	c_hi.clinically_relevant
+		as issue_clinically_relevant,
+	c_hi.is_confidential
+		as issue_confidential,
+
+	-- episode
+	null::text
+		as episode,
+	null::boolean
+		as episode_open,
+
+	-- encounter
+	c_enc.started
+		as encounter_started,
+	c_enc.last_affirmed
+		as encounter_last_affirmed,
+	c_ety.description
+		as encounter_type,
+	_(c_ety.description)
+		as encounter_l10n_type
+
+from
+	clin.external_care c_ec
+		inner join clin.encounter c_enc on (c_ec.fk_encounter = c_enc.pk)
+			inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+		left join clin.health_issue c_hi on (c_ec.fk_health_issue = c_hi.pk)
+		left join dem.org_unit d_ou on (c_ec.fk_org_unit = d_ou.pk)
+			left join dem.org d_o on (d_ou.fk_org = d_o.pk)
+;
+
+
+revoke all on clin.v_external_care_journal from public;
+grant select on clin.v_external_care_journal to group "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_external_care_journal.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_family_history_journal.sql b/server/sql/v20-v21/dynamic/v21-clin-v_family_history_journal.sql
new file mode 100644
index 0000000..2306297
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_family_history_journal.sql
@@ -0,0 +1,117 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+-- 
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_family_history_journal cascade;
+
+
+create view clin.v_family_history_journal as
+select
+	c_enc.fk_patient
+		as pk_patient,
+	c_fh.modified_when
+		as modified_when,
+	c_fh.clin_when
+		as clin_when,
+	coalesce (
+		(select short_alias from dem.staff where db_user = c_fh.modified_by),
+		'<' || c_fh.modified_by || '>'
+	)
+		as modified_by,
+	c_fh.soap_cat
+		as soap_cat,
+	_(c_fhrt.description)
+			|| coalesce(' @ ' || c_fh.age_noted, '')
+			|| ': '
+			|| c_fh.narrative
+			|| E'\n'
+			|| ' '
+			|| case
+				when c_fh.contributed_to_death is True
+					then _('contributed to death') || ' '
+				else ''
+			end
+			|| coalesce('@ ' || justify_interval(c_fh.age_of_death)::text, '')
+			|| E'\n'
+			|| coalesce(' ' || c_fh.name_relative || ',', '')
+			|| coalesce(' ' || to_char(c_fh.dob_relative, 'YYYY-MM-DD'), '')
+			|| coalesce(E'\n ' || c_fh.comment, '')
+			|| coalesce ((
+					E';\n' || array_to_string (
+						(select array_agg(r_csr.code || ' (' || r_ds.name_short || ' - ' || r_ds.version || ' - ' || r_ds.lang || '): ' || r_csr.term)
+						 from
+						 	clin.lnk_code2fhx c_lc2fhx
+						 		inner join
+							ref.coding_system_root r_csr on c_lc2fhx.fk_generic_code = r_csr.pk_coding_system
+								inner join
+							ref.data_source r_ds on r_ds.pk = r_csr.fk_data_source
+						where
+							c_lc2fhx.fk_item = c_fh.pk
+						),
+						'; '
+					) || ';'
+				),
+				''
+			)
+		as narrative,
+	c_fh.fk_encounter
+		as pk_encounter,
+	c_fh.fk_episode
+		as pk_episode,
+	c_epi.fk_health_issue
+		as pk_health_issue,
+	c_fh.pk
+		as src_pk,
+	'clin.family_history'::text
+		as src_table,
+	c_fh.row_version,
+
+	-- issue
+	c_hi.description
+		as health_issue,
+	c_hi.laterality
+		as issue_laterality,
+	c_hi.is_active
+		as issue_active,
+	c_hi.clinically_relevant
+		as issue_clinically_relevant,
+	c_hi.is_confidential
+		as issue_confidential,
+
+	-- episode
+	c_epi.description
+		as episode,
+	c_epi.is_open
+		as episode_open,
+
+	-- encounter
+	c_enc.started
+		as encounter_started,
+	c_enc.last_affirmed
+		as encounter_last_affirmed,
+	c_ety.description
+		as encounter_type,
+	_(c_ety.description)
+		as encounter_l10n_type
+
+from
+	clin.family_history c_fh
+		inner join clin.encounter c_enc on (c_fh.fk_encounter = c_enc.pk)
+			inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+				inner join clin.episode c_epi on (c_fh.fk_episode = c_epi.pk)
+					left join clin.fhx_relation_type c_fhrt on c_fh.fk_relation_type = c_fhrt.pk
+						left join clin.health_issue c_hi on (c_epi.fk_health_issue = c_hi.pk)
+;
+
+
+grant select on clin.v_family_history_journal to group "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_family_history_journal.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_health_issues_journal.sql b/server/sql/v20-v21/dynamic/v21-clin-v_health_issues_journal.sql
new file mode 100644
index 0000000..cba1cc0
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_health_issues_journal.sql
@@ -0,0 +1,123 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_health_issues_journal cascade;
+
+
+create view clin.v_health_issues_journal as
+select
+	c_enc.fk_patient
+		as pk_patient,
+	c_hi.modified_when
+		as modified_when,
+	coalesce (
+		(select dem.identity.dob + c_hi.age_noted
+		 from dem.identity
+		 where pk = (select fk_patient from clin.encounter where pk = c_hi.fk_encounter)
+		),
+		c_enc.started
+	)
+		as clin_when,
+	coalesce (
+		(select short_alias from dem.staff where db_user = c_hi.modified_by),
+		'<' || c_hi.modified_by || '>'
+	) 	as modified_by,
+	'a'::text
+		as soap_cat,
+	_('Health Issue') || ' ('
+			|| case when c_hi.is_active
+				then _('active')
+				else _('inactive')
+			   end
+			|| ', '
+			|| case when c_hi.clinically_relevant
+				then _('clinically relevant')
+				else _('clinically not relevant')
+			   end
+			|| coalesce((', ' || c_hi.diagnostic_certainty_classification), '')
+			|| '): '
+			|| c_hi.description
+			|| coalesce((E';\n' || _('noted at age') || ': ' || c_hi.age_noted::text || E';\n'), E';\n')
+			|| coalesce((_('Laterality') || ': ' || c_hi.laterality || ' / '), '')
+			|| case when c_hi.is_confidential
+				then _('confidential') || ' / ' else ''
+			   end
+			|| case when c_hi.is_cause_of_death
+				then _('cause of death') else ''
+			   end
+			|| coalesce((E';\n' || _('Summary') || E':\n' || c_hi.summary), E'')
+			|| coalesce ((
+					E';\n' || array_to_string (
+						(select array_agg(r_csr.code || ' (' || r_ds.name_short || ' - ' || r_ds.version || ' - ' || r_ds.lang || '): ' || r_csr.term)
+						 from
+						 	clin.lnk_code2h_issue c_lc2h
+						 		inner join
+							ref.coding_system_root r_csr on c_lc2h.fk_generic_code = r_csr.pk_coding_system
+								inner join
+							ref.data_source r_ds on r_ds.pk = r_csr.fk_data_source
+						where
+							c_lc2h.fk_item = c_hi.pk
+						),
+						'; '
+					) || ';'
+				),
+				''
+			)
+		as narrative,
+	c_hi.fk_encounter
+		as pk_encounter,
+	NULL::integer
+		as pk_episode,
+	c_hi.pk
+		as pk_health_issue,
+	c_hi.pk
+		as src_pk,
+	'clin.health_issue'::text
+		as src_table,
+	c_hi.row_version,
+
+	-- issue
+	c_hi.description
+		as health_issue,
+	c_hi.laterality
+		as issue_laterality,
+	c_hi.is_active
+		as issue_active,
+	c_hi.clinically_relevant
+		as issue_clinically_relevant,
+	c_hi.is_confidential
+		as issue_confidential,
+
+	-- episode
+	NULL::text
+		as episode,
+	NULL::boolean
+		as episode_open,
+
+	-- encounter
+	c_enc.started
+		as encounter_started,
+	c_enc.last_affirmed
+		as encounter_last_affirmed,
+	c_ety.description
+		as encounter_type,
+	_(c_ety.description)
+		as encounter_l10n_type
+
+from
+	clin.health_issue c_hi
+		inner join clin.encounter c_enc on c_hi.fk_encounter = c_enc.pk
+			inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+;
+
+
+grant select on clin.v_health_issues_journal TO GROUP "gm-doctors";
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_health_issues_journal.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_hospital_stays_journal.sql b/server/sql/v20-v21/dynamic/v21-clin-v_hospital_stays_journal.sql
new file mode 100644
index 0000000..945da01
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_hospital_stays_journal.sql
@@ -0,0 +1,352 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+--set default_transaction_read_only to off;
+\set ON_ERROR_STOP 1
+
+-- --------------------------------------------------------------
+-- stays w/o discharge date
+drop view if exists clin.v_hospital_stays_journal_no_discharge cascade;
+
+create view clin.v_hospital_stays_journal_no_discharge as
+	select
+		c_enc.fk_patient
+			as pk_patient,
+		c_hs.modified_when
+			as modified_when,
+		c_hs.clin_when
+			as clin_when,
+		coalesce (
+			(select short_alias from dem.staff where db_user = c_hs.modified_by),
+			'<' || c_hs.modified_by || '>'
+		)
+			as modified_by,
+		c_hs.soap_cat
+			as soap_cat,
+		_('hospital stay') || E'\n'
+			|| ' ' || _('admitted') || ': ' || to_char(clin_when, 'YYYY-MM-DD') || E'\n'
+			|| ' ' || _('hospital') || ': "' || d_ou.description || ' @ ' || d_o.description || '"'
+			|| coalesce(E'\n ' || c_hs.narrative, '')
+			as narrative,
+		c_hs.fk_encounter
+			as pk_encounter,
+		c_hs.fk_episode
+			as pk_episode,
+		(select fk_health_issue from clin.episode where pk = c_hs.fk_episode)
+			as pk_health_issue,
+		c_hs.pk
+			as src_pk,
+		'clin.hospital_stay'::text
+			as src_table,
+		c_hs.row_version
+			as row_version,
+
+		-- issue
+		c_hi.description
+			as health_issue,
+		c_hi.laterality
+			as issue_laterality,
+		c_hi.is_active
+			as issue_active,
+		c_hi.clinically_relevant
+			as issue_clinically_relevant,
+		c_hi.is_confidential
+			as issue_confidential,
+
+		-- episode
+		c_epi.description
+			as episode,
+		c_epi.is_open
+			as episode_open,
+
+		-- encounter
+		c_enc.started
+			as encounter_started,
+		c_enc.last_affirmed
+			as encounter_last_affirmed,
+		c_ety.description
+			as encounter_type,
+		_(c_ety.description)
+			as encounter_l10n_type
+
+	from
+		clin.hospital_stay c_hs
+			inner join clin.encounter c_enc on (c_hs.fk_encounter = c_enc.pk)
+				inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+					inner join clin.episode c_epi on (c_hs.fk_episode = c_epi.pk)
+						left join clin.health_issue c_hi on (c_epi.fk_health_issue = c_hi.pk)
+							left join dem.org_unit d_ou on (d_ou.pk = c_hs.fk_org_unit)
+								left join dem.org d_o on (d_o.pk = d_ou.fk_org)
+	where
+		c_hs.discharge is NULL
+;
+
+
+grant select on clin.v_hospital_stays_journal_no_discharge to group "gm-doctors";
+
+-- --------------------------------------------------------------
+-- one-day stays
+drop view if exists clin.v_hospital_stays_journal_one_day cascade;
+
+create view clin.v_hospital_stays_journal_one_day as
+	select
+		c_enc.fk_patient
+			as pk_patient,
+		c_hs.modified_when
+			as modified_when,
+		c_hs.clin_when
+			as clin_when,
+		coalesce (
+			(select short_alias from dem.staff where db_user = c_hs.modified_by),
+			'<' || c_hs.modified_by || '>'
+		)
+			as modified_by,
+		c_hs.soap_cat
+			as soap_cat,
+		_('hospital stay') || E'\n'
+			|| ' ' || _('admitted/discharged') || ': ' || to_char(clin_when, 'YYYY-MM-DD') || E'\n'
+			|| ' ' || _('hospital') || ': "' || d_ou.description || ' @ ' || d_o.description || '"' || E'\n'
+			|| coalesce(E'\n ' || c_hs.narrative, '')
+			as narrative,
+		c_hs.fk_encounter
+			as pk_encounter,
+		c_hs.fk_episode
+			as pk_episode,
+		(select fk_health_issue from clin.episode where pk = c_hs.fk_episode)
+			as pk_health_issue,
+		c_hs.pk
+			as src_pk,
+		'clin.hospital_stay'::text
+			as src_table,
+		c_hs.row_version
+			as row_version,
+
+		-- issue
+		c_hi.description
+			as health_issue,
+		c_hi.laterality
+			as issue_laterality,
+		c_hi.is_active
+			as issue_active,
+		c_hi.clinically_relevant
+			as issue_clinically_relevant,
+		c_hi.is_confidential
+			as issue_confidential,
+
+		-- episode
+		c_epi.description
+			as episode,
+		c_epi.is_open
+			as episode_open,
+
+		-- encounter
+		c_enc.started
+			as encounter_started,
+		c_enc.last_affirmed
+			as encounter_last_affirmed,
+		c_ety.description
+			as encounter_type,
+		_(c_ety.description)
+			as encounter_l10n_type
+
+	from
+		clin.hospital_stay c_hs
+			inner join clin.encounter c_enc on (c_hs.fk_encounter = c_enc.pk)
+				inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+					inner join clin.episode c_epi on (c_hs.fk_episode = c_epi.pk)
+						left join clin.health_issue c_hi on (c_epi.fk_health_issue = c_hi.pk)
+							left join dem.org_unit d_ou on (d_ou.pk = c_hs.fk_org_unit)
+								left join dem.org d_o on (d_o.pk = d_ou.fk_org)
+	where
+		(c_hs.discharge is not NULL)
+			and
+		(to_char(c_hs.clin_when, 'YYYYMMDD') = to_char(c_hs.discharge, 'YYYYMMDD'))
+;
+
+
+grant select on clin.v_hospital_stays_journal_one_day to group "gm-doctors";
+
+-- --------------------------------------------------------------
+-- several days stays: admission
+drop view if exists clin.v_hospital_stays_journal_multi_day_adm cascade;
+
+create view clin.v_hospital_stays_journal_multi_day_adm as
+	select
+		c_enc.fk_patient
+			as pk_patient,
+		c_hs.modified_when
+			as modified_when,
+		c_hs.clin_when
+			as clin_when,
+		coalesce (
+			(select short_alias from dem.staff where db_user = c_hs.modified_by),
+			'<' || c_hs.modified_by || '>'
+		)
+			as modified_by,
+		c_hs.soap_cat
+			as soap_cat,
+		_('hospital stay') || E'\n'
+			|| ' ' || _('admitted') || ': ' || to_char(clin_when, 'YYYY-MM-DD') || E'\n'
+			|| ' ' || _('discharged') || ': ' || to_char(discharge, 'YYYY-MM-DD') || E'\n'
+			|| ' ' || _('hospital') || ': "' || d_ou.description || ' @ ' || d_o.description || '"' || E'\n'
+			|| coalesce(E'\n ' || c_hs.narrative, '')
+			as narrative,
+		c_hs.fk_encounter
+			as pk_encounter,
+		c_hs.fk_episode
+			as pk_episode,
+		(select fk_health_issue from clin.episode where pk = c_hs.fk_episode)
+			as pk_health_issue,
+		c_hs.pk
+			as src_pk,
+		'clin.hospital_stay'::text
+			as src_table,
+		c_hs.row_version
+			as row_version,
+
+		-- issue
+		c_hi.description
+			as health_issue,
+		c_hi.laterality
+			as issue_laterality,
+		c_hi.is_active
+			as issue_active,
+		c_hi.clinically_relevant
+			as issue_clinically_relevant,
+		c_hi.is_confidential
+			as issue_confidential,
+
+		-- episode
+		c_epi.description
+			as episode,
+		c_epi.is_open
+			as episode_open,
+
+		-- encounter
+		c_enc.started
+			as encounter_started,
+		c_enc.last_affirmed
+			as encounter_last_affirmed,
+		c_ety.description
+			as encounter_type,
+		_(c_ety.description)
+			as encounter_l10n_type
+
+	from
+		clin.hospital_stay c_hs
+			inner join clin.encounter c_enc on (c_hs.fk_encounter = c_enc.pk)
+				inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+					inner join clin.episode c_epi on (c_hs.fk_episode = c_epi.pk)
+						left join clin.health_issue c_hi on (c_epi.fk_health_issue = c_hi.pk)
+							left join dem.org_unit d_ou on (d_ou.pk = c_hs.fk_org_unit)
+								left join dem.org d_o on (d_o.pk = d_ou.fk_org)
+	where
+		(c_hs.discharge is not NULL)
+			and
+		(to_char(c_hs.clin_when, 'YYYYMMDD') != to_char(c_hs.discharge, 'YYYYMMDD'))
+;
+
+
+grant select on clin.v_hospital_stays_journal_multi_day_adm to group "gm-doctors";
+
+-- --------------------------------------------------------------
+-- several days stays: discharge
+drop view if exists clin.v_hospital_stays_journal_multi_day_dis cascade;
+
+create view clin.v_hospital_stays_journal_multi_day_dis as
+	select
+		c_enc.fk_patient
+			as pk_patient,
+		c_hs.modified_when
+			as modified_when,
+		c_hs.discharge
+			as clin_when,
+		coalesce (
+			(select short_alias from dem.staff where db_user = c_hs.modified_by),
+			'<' || c_hs.modified_by || '>'
+		)
+			as modified_by,
+		c_hs.soap_cat
+			as soap_cat,
+		_('discharged from') || ' "' || d_ou.description || ' @ ' || d_o.description || '"'
+			as narrative,
+		c_hs.fk_encounter
+			as pk_encounter,
+		c_hs.fk_episode
+			as pk_episode,
+		(select fk_health_issue from clin.episode where pk = c_hs.fk_episode)
+			as pk_health_issue,
+		c_hs.pk
+			as src_pk,
+		'clin.hospital_stay'::text
+			as src_table,
+		c_hs.row_version
+			as row_version,
+
+		-- issue
+		c_hi.description
+			as health_issue,
+		c_hi.laterality
+			as issue_laterality,
+		c_hi.is_active
+			as issue_active,
+		c_hi.clinically_relevant
+			as issue_clinically_relevant,
+		c_hi.is_confidential
+			as issue_confidential,
+
+		-- episode
+		c_epi.description
+			as episode,
+		c_epi.is_open
+			as episode_open,
+
+		-- encounter
+		c_enc.started
+			as encounter_started,
+		c_enc.last_affirmed
+			as encounter_last_affirmed,
+		c_ety.description
+			as encounter_type,
+		_(c_ety.description)
+			as encounter_l10n_type
+
+	from
+		clin.hospital_stay c_hs
+			inner join clin.encounter c_enc on (c_hs.fk_encounter = c_enc.pk)
+				inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+					inner join clin.episode c_epi on (c_hs.fk_episode = c_epi.pk)
+						left join clin.health_issue c_hi on (c_epi.fk_health_issue = c_hi.pk)
+							left join dem.org_unit d_ou on (d_ou.pk = c_hs.fk_org_unit)
+								left join dem.org d_o on (d_o.pk = d_ou.fk_org)
+	where
+		(c_hs.discharge is not NULL)
+			and
+		(to_char(c_hs.clin_when, 'YYYYMMDD') != to_char(c_hs.discharge, 'YYYYMMDD'))
+;
+
+
+grant select on clin.v_hospital_stays_journal_multi_day_dis to group "gm-doctors";
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_hospital_stays_journal cascade;
+
+
+create view clin.v_hospital_stays_journal as
+	select * from clin.v_hospital_stays_journal_no_discharge
+union all
+	select * from clin.v_hospital_stays_journal_one_day
+union all
+	select * from clin.v_hospital_stays_journal_multi_day_adm
+union all
+	select * from clin.v_hospital_stays_journal_multi_day_dis
+;
+
+grant select on clin.v_hospital_stays_journal to group "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_hospital_stays_journal.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_narrative4search.sql b/server/sql/v20-v21/dynamic/v21-clin-v_narrative4search.sql
new file mode 100644
index 0000000..3aa411e
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_narrative4search.sql
@@ -0,0 +1,424 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+--
+-- ==============================================================
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_narrative4search cascade;
+
+create view clin.v_narrative4search as
+
+select * from (
+
+	-- clin.clin_root_items
+	select
+		vpi.pk_patient as pk_patient,
+		vpi.soap_cat as soap_cat,
+		vpi.narrative as narrative,
+		vpi.pk_encounter as pk_encounter,
+		vpi.pk_episode as pk_episode,
+		vpi.pk_health_issue as pk_health_issue,
+		vpi.pk_item as src_pk,
+		vpi.src_table as src_table
+	from
+		clin.v_pat_items vpi
+	where
+		src_table not in (
+			'clin.allergy',
+			'clin.test_result',
+			'clin.procedure',
+			'clin.substance_intake',
+			'clin.family_history'
+		)
+
+
+	union all
+
+		select * from clin.v_subst_intake4narr_search
+		where gm.is_null_or_blank_string(narrative) is FALSE
+
+
+	union all
+	select		-- clin.procedure
+		(select fk_patient from clin.encounter where pk = cpr.fk_encounter)
+			as pk_patient,
+		cpr.soap_cat
+			as soap_cat,
+		cpr.narrative
+			as narrative,
+		cpr.fk_encounter
+			as pk_encounter,
+		cpr.fk_episode
+			as pk_episode,
+		(select fk_health_issue from clin.episode where pk = cpr.fk_episode)
+			as pk_health_issue,
+		cpr.pk
+			as src_pk,
+		'clin.procedure'
+			as src_table
+	from
+		clin.procedure cpr
+	where
+		cpr.narrative is not NULL
+
+
+	union all
+	select		-- test results
+		(select fk_patient from clin.encounter where pk = ctr.fk_encounter)
+			as pk_patient,
+		ctr.soap_cat
+			as soap_cat,
+		coalesce(ctr.narrative, '')
+			|| coalesce(' ' || ctr.val_alpha, '')
+			|| coalesce(' ' || ctr.val_unit, '')
+			|| coalesce(' ' || ctr.val_normal_range, '')
+			|| coalesce(' ' || ctr.val_target_range, '')
+			|| coalesce(' ' || ctr.norm_ref_group, '')
+			|| coalesce(' ' || ctr.note_test_org, '')
+			|| coalesce(' ' || ctr.material, '')
+			|| coalesce(' ' || ctr.material_detail, '')
+			as narrative,
+		ctr.fk_encounter
+			as pk_encounter,
+		ctr.fk_episode
+			as pk_episode,
+		(select fk_health_issue from clin.episode where pk = ctr.fk_episode)
+			as pk_health_issue,
+		ctr.pk
+			as src_pk,
+		'clin.test_result'
+			as src_table
+	from
+		clin.test_result ctr
+
+
+	union all	-- test result reviews
+	select
+		(select fk_patient from clin.encounter where pk =
+			(select fk_encounter from clin.test_result where clin.test_result.pk = crtr.fk_reviewed_row)
+		)
+			as pk_patient,
+		'o'::text
+			as soap_cat,
+		crtr.comment
+			as narrative,
+		(select fk_encounter from clin.test_result where clin.test_result.pk = crtr.fk_reviewed_row)
+			as pk_encounter,
+		(select fk_episode from clin.test_result where clin.test_result.pk = crtr.fk_reviewed_row)
+			as pk_episode,
+		(select fk_health_issue from clin.episode where pk =
+			(select fk_episode from clin.test_result where clin.test_result.pk = crtr.fk_reviewed_row)
+		)
+			as pk_health_issue,
+		crtr.pk
+			as src_pk,
+		'clin.reviewed_test_results'
+			as src_table
+	from
+		clin.reviewed_test_results crtr
+
+
+	union all
+	select -- allergy state
+		(select fk_patient from clin.encounter where pk = cas.fk_encounter)
+			as pk_patient,
+		'o'::text
+			as soap_cat,
+		cas.comment
+			as narrative,
+		cas.fk_encounter
+			as pk_encounter,
+		null
+			as pk_episode,
+		null
+			as pk_health_issue,
+		cas.pk
+			as src_pk,
+		'clin.allergy_state'
+			as src_table
+	from
+		clin.allergy_state cas
+	where
+		cas.comment is not NULL
+
+
+	union all
+	select -- allergies
+		(select fk_patient from clin.encounter where pk = ca.fk_encounter)
+			as pk_patient,
+		ca.soap_cat
+			as soap_cat,
+		coalesce(narrative, '')
+			|| coalesce(' ' || substance, '')
+			|| coalesce(' ' || substance_code, '')
+			|| coalesce(' ' || generics, '')
+			|| coalesce(' ' || allergene, '')
+			|| coalesce(' ' || atc_code, '')
+			as narrative,
+		ca.fk_encounter
+			as pk_encounter,
+		ca.fk_episode
+			as pk_episode,
+		(select fk_health_issue from clin.episode where pk = ca.fk_episode)
+			as pk_health_issue,
+		ca.pk
+			as src_pk,
+		'clin.allergy'
+			as src_table
+	from
+		clin.allergy ca
+
+
+	union all	-- health issues
+	select
+		(select fk_patient from clin.encounter where pk = chi.fk_encounter)
+			as pk_patient,
+		'a' as soap_cat,
+		chi.description
+			|| coalesce(' ' || chi.summary, '')
+			as narrative,
+		chi.fk_encounter
+			as pk_encounter,
+		null
+			as pk_episode,
+		chi.pk
+			as pk_health_issue,
+		chi.pk
+			as src_pk,
+		'clin.health_issue'
+			as src_table
+	from
+		clin.health_issue chi
+
+
+	union all	-- encounters
+	select
+		cenc.fk_patient as pk_patient,
+		's' as soap_cat,
+		coalesce(cenc.reason_for_encounter, '')
+			|| coalesce(' ' || cenc.assessment_of_encounter, '')
+			as narrative,
+		cenc.pk as pk_encounter,
+		null as pk_episode,
+		null as pk_health_issue,
+		cenc.pk as src_pk,
+		'clin.encounter' as src_table
+	from
+		clin.encounter cenc
+
+
+	union all	-- episodes
+	select
+		(select fk_patient from clin.encounter where pk = cep.fk_encounter)
+			as pk_patient,
+		's' as soap_cat,
+		cep.description
+			|| coalesce(' ' || cep.summary, '')
+			as narrative,
+		cep.fk_encounter
+			as pk_encounter,
+		cep.pk
+			as pk_episode,
+		cep.fk_health_issue
+			as pk_health_issue,
+		cep.pk
+			as src_pk,
+		'clin.episode'
+			as src_table
+	from
+		clin.episode cep
+
+
+	union all	-- family history
+	select
+		c_vfhx.pk_patient,
+		c_vfhx.soap_cat,
+		(c_vfhx.relation || ' / ' || c_vfhx.l10n_relation || ' '
+		 || c_vfhx.name_relative || ': '
+		 || c_vfhx.condition
+		) as narrative,
+		c_vfhx.pk_encounter,
+		c_vfhx.pk_episode,
+		c_vfhx.pk_health_issue,
+		c_vfhx.pk_family_history as src_pk,
+		'clin.family_history' as src_table
+	from
+		clin.v_family_history c_vfhx
+
+
+	union all	-- documents
+	select
+		vdm.pk_patient as pk_patient,
+		'o' as soap_cat,
+		(vdm.l10n_type || ' ' ||
+		 coalesce(vdm.ext_ref, '') || ' ' ||
+		 coalesce(vdm.comment, '')
+		) as narrative,
+		vdm.pk_encounter as pk_encounter,
+		vdm.pk_episode as pk_episode,
+		vdm.pk_health_issue as pk_health_issue,
+		vdm.pk_doc as src_pk,
+		'blobs.doc_med' as src_table
+	from
+		blobs.v_doc_med vdm
+
+
+	union all	-- document objects
+	select
+		vo4d.pk_patient as pk_patient,
+		'o' as soap_cat,
+		vo4d.obj_comment as narrative,
+		vo4d.pk_encounter as pk_encounter,
+		vo4d.pk_episode as pk_episode,
+		vo4d.pk_health_issue as pk_health_issue,
+		vo4d.pk_obj as src_pk,
+		'blobs.doc_obj' as src_table
+	from
+		blobs.v_obj4doc_no_data vo4d
+
+
+	union all	-- document descriptions
+	select
+		vdd.pk_patient as pk_patient,
+		'o' as soap_cat,
+		vdd.description as narrative,
+		vdd.pk_encounter as pk_encounter,
+		vdd.pk_episode as pk_episode,
+		vdd.pk_health_issue as pk_health_issue,
+		vdd.pk_doc_desc as src_pk,
+		'blobs.doc_desc' as src_table
+	from
+		blobs.v_doc_desc vdd
+
+
+	union all	-- reviewed documents
+	select
+		vrdo.pk_patient as pk_patient,
+		's' as soap_cat,
+		vrdo.comment as narrative,
+		null as pk_encounter,
+		vrdo.pk_episode as pk_episode,
+		vrdo.pk_health_issue as pk_health_issue,
+		vrdo.pk_review_root as src_pk,
+		'blobs.v_reviewed_doc_objects' as src_table
+	from
+		blobs.v_reviewed_doc_objects vrdo
+
+
+	union all	-- patient tags
+	select
+		d_vit.pk_identity
+			as pk_patient,
+		's' as soap_cat,
+		d_vit.l10n_description
+			|| coalesce(' ' || d_vit.comment, '')
+			as narrative,
+		null
+			as pk_encounter,
+		null
+			as pk_episode,
+		null
+			as pk_health_issue,
+		d_vit.pk_identity_tag
+			as src_pk,
+		'dem.v_identity_tags'
+			as src_table
+	from
+		dem.v_identity_tags d_vit
+
+
+	union all	-- external care
+	select
+		c_vec.pk_identity
+			as pk_patient,
+		's' as soap_cat,
+		case
+			when c_vec.pk_health_issue is null then
+				coalesce(c_vec.issue, '')
+				|| coalesce(' / ' || c_vec.provider, '')
+				|| coalesce(' / ' || c_vec.comment, '')
+			else
+				coalesce(c_vec.provider, '')
+				|| coalesce(' / ' || c_vec.comment, '')
+		end as narrative,
+		c_vec.pk_encounter
+			as pk_encounter,
+		null
+			as pk_episode,
+		c_vec.pk_health_issue
+			as pk_health_issue,
+		c_vec.pk_external_care
+			as src_pk,
+		'clin.v_external_care'
+			as src_table
+	from
+		clin.v_external_care c_vec
+
+
+	union all	-- export items
+	select
+		c_vei.pk_identity
+			as pk_patient,
+		's' as soap_cat,
+		case
+			when c_vei.pk_doc_obj is null then
+				coalesce(c_vei.description, '')
+				|| coalesce(' / ' || c_vei.filename, '')
+			else
+				coalesce(c_vei.description, '')
+		end as narrative,
+		null
+			as pk_encounter,
+		null
+			as pk_episode,
+		null
+			as pk_health_issue,
+		c_vei.pk_export_item
+			as src_pk,
+		'clin.v_export_items'
+			as src_table
+	from
+		clin.v_export_items c_vei
+
+
+	union all	-- hint suppression rationale
+	select
+		(select fk_patient from clin.encounter where pk = c_sh.fk_encounter)
+			as pk_patient,
+		'p' as soap_cat,
+		c_sh.rationale
+			as narrative,
+		c_sh.fk_encounter
+			as pk_encounter,
+		null
+			as pk_episode,
+		null
+			as pk_health_issue,
+		c_sh.pk
+			as src_pk,
+		'clin.suppressed_hint'
+			as src_table
+	from
+		clin.suppressed_hint c_sh
+
+) as union_table
+
+where
+	trim(coalesce(union_table.narrative, '')) != ''
+;
+
+
+comment on view clin.v_narrative4search is
+	'unformatted *complete* narrative for patients
+	 including health issue/episode/encounter descriptions,
+	 mainly for searching the narrative in context';
+
+
+grant select on clin.v_narrative4search to group "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_narrative4search.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_pat_allergies_journal.sql b/server/sql/v20-v21/dynamic/v21-clin-v_pat_allergies_journal.sql
new file mode 100644
index 0000000..f989684
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_pat_allergies_journal.sql
@@ -0,0 +1,90 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_pat_allergies_journal cascade;
+
+
+create view clin.v_pat_allergies_journal as
+
+select
+	c_enc.fk_patient
+		as pk_patient,
+	c_all.modified_when
+		as modified_when,
+	c_all.clin_when
+		as clin_when,
+	coalesce (
+		(select short_alias from dem.staff where db_user = c_all.modified_by),
+		'<' || c_all.modified_by || '>'
+	)
+		as modified_by,
+	c_all.soap_cat
+		as soap_cat,
+	_('Allergy') || ' (' || _(c_at.value) || '): ' || coalesce(c_all.narrative, '') || E'\n'
+		|| _('substance') || ': ' || c_all.substance || '; '
+		|| coalesce((_('allergene') || ': ' || c_all.allergene || '; '), '')
+		|| coalesce((_('generic')   || ': ' || c_all.generics || '; '), '')
+		|| coalesce((_('ATC code')  || ': ' || c_all.atc_code || '; '), '')
+		as narrative,
+	c_all.fk_encounter
+		as pk_encounter,
+	c_all.fk_episode
+		as pk_episode,
+	c_epi.fk_health_issue
+		as pk_health_issue,
+	c_all.pk
+		as src_pk,
+	'clin.allergy'::text
+		as src_table,
+	c_all.row_version,
+
+	-- issue
+	c_hi.description
+		as health_issue,
+	c_hi.laterality
+		as issue_laterality,
+	c_hi.is_active
+		as issue_active,
+	c_hi.clinically_relevant
+		as issue_clinically_relevant,
+	c_hi.is_confidential
+		as issue_confidential,
+
+	-- episode
+	c_epi.description
+		as episode,
+	c_epi.is_open
+		as episode_open,
+
+	-- encounter
+	c_enc.started
+		as encounter_started,
+	c_enc.last_affirmed
+		as encounter_last_affirmed,
+	c_ety.description
+		as encounter_type,
+	_(c_ety.description)
+		as encounter_l10n_type
+
+
+from
+	clin.allergy c_all
+		inner join clin._enum_allergy_type c_at on (c_all.fk_type = c_at.pk)
+			inner join clin.encounter c_enc on (c_all.fk_encounter = c_enc.pk)
+				inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+					inner join clin.episode c_epi on (c_all.fk_episode = c_epi.pk)
+						left join clin.health_issue c_hi on (c_epi.fk_health_issue = c_hi.pk)
+;
+
+
+grant select on clin.v_pat_allergies_journal to group "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_pat_allergies_journal.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_pat_allergy_state_journal.sql b/server/sql/v20-v21/dynamic/v21-clin-v_pat_allergy_state_journal.sql
new file mode 100644
index 0000000..880f0b7
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_pat_allergy_state_journal.sql
@@ -0,0 +1,191 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_pat_allergy_state_journal cascade;
+
+
+create view clin.v_pat_allergy_state_journal as
+
+	select
+		c_enc.fk_patient
+			as pk_patient,
+		c_ast.modified_when
+			as modified_when,
+		coalesce(c_ast.last_confirmed, c_ast.modified_when)
+			as clin_when,
+		coalesce (
+			(select short_alias from dem.staff where db_user = c_ast.modified_by),
+			'<' || c_ast.modified_by || '>'
+		)
+			as modified_by,
+		'o'::text
+			as soap_cat,
+		_('Allergy state') || ': '
+			|| case
+				when c_ast.has_allergy is null then _('unknown, unasked')
+				when c_ast.has_allergy = 0 then _('no known allergies')
+				when c_ast.has_allergy = 1 then _('does have allergies')
+			   end
+			|| coalesce (
+				' (' || _('last confirmed') || to_char(c_ast.last_confirmed, ' YYYY-MM-DD HH24:MI') || ')',
+				''
+			) || coalesce (
+				E'\n ' || c_ast.comment,
+				''
+			) as narrative,
+		c_ast.fk_encounter
+			as pk_encounter,
+		null::integer
+			as pk_episode,
+		null::integer
+			as pk_health_issue,
+		c_ast.pk
+			as src_pk,
+		'clin.allergy_state'::text
+			as src_table,
+		c_ast.row_version,
+
+		-- issue
+		NULL::text
+			as health_issue,
+		NULL::text
+			as issue_laterality,
+		NULL::boolean
+			as issue_active,
+		NULL::boolean
+			as issue_clinically_relevant,
+		NULL::boolean
+			as issue_confidential,
+
+		-- episode
+		NULL::text
+			as episode,
+		NULL::boolean
+			as episode_open,
+
+		-- encounter
+		c_enc.started
+			as encounter_started,
+		c_enc.last_affirmed
+			as encounter_last_affirmed,
+		c_ety.description
+			as encounter_type,
+		_(c_ety.description)
+			as encounter_l10n_type
+
+	from
+		clin.allergy_state c_ast
+			inner join clin.encounter c_enc on (c_ast.fk_encounter = c_enc.pk)
+				inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+
+UNION ALL
+
+	-- add a copy with all potential sort dates set to now()
+	-- that way, we can ensure the allergy state bubbles up to the top
+	-- in whatever date sorting scheme is selected thereby improving
+	-- patient safety,
+	-- the "real" times are mentioned in the narrative
+	select
+		c_enc.fk_patient
+			as pk_patient,
+		--c_ast.modified_when
+		now()
+			as modified_when,
+		--coalesce(c_ast.last_confirmed, c_ast.modified_when)
+		now()
+			as clin_when,
+		coalesce (
+			(select short_alias from dem.staff where db_user = c_ast.modified_by),
+			'<' || c_ast.modified_by || '>'
+		)
+			as modified_by,
+		'o'::text
+			as soap_cat,
+		_('Allergy state') || ' (' || _('copy') || '): '
+			|| case
+				when c_ast.has_allergy is null then _('unknown, unasked')
+				when c_ast.has_allergy = 0 then _('no known allergies')
+				when c_ast.has_allergy = 1 then _('does have allergies')
+			   end
+			|| coalesce (
+				E'\n ' || c_ast.comment,
+				''
+			) || coalesce (
+				-- .clin_when
+				E'\n ' || _('last confirmed') || to_char(c_ast.last_confirmed, ' YYYY-MM-DD HH24:MI'),
+				''
+			) || coalesce (
+				-- .modified_when
+				E'\n ' || _('entry last modified') || to_char(c_ast.modified_when, ' YYYY-MM-DD HH24:MI'),
+				''
+			) || coalesce (
+				-- .encounter_started
+				E'\n ' || _('encounter started') || to_char(c_enc.started, ' YYYY-MM-DD HH24:MI'),
+				''
+			) || coalesce (
+				-- .encounter_last_affirmed
+				E'\n ' || _('encounter last affirmed') || to_char(c_enc.last_affirmed, ' YYYY-MM-DD HH24:MI'),
+				''
+			) as narrative,
+		c_ast.fk_encounter
+			as pk_encounter,
+		null::integer
+			as pk_episode,
+		null::integer
+			as pk_health_issue,
+		c_ast.pk
+			as src_pk,
+		'clin.allergy_state'::text
+			as src_table,
+		c_ast.row_version,
+
+		-- issue
+		NULL::text
+			as health_issue,
+		NULL::text
+			as issue_laterality,
+		NULL::boolean
+			as issue_active,
+		NULL::boolean
+			as issue_clinically_relevant,
+		NULL::boolean
+			as issue_confidential,
+
+		-- episode
+		NULL::text
+			as episode,
+		NULL::boolean
+			as episode_open,
+
+		-- encounter
+		--c_enc.started
+		now()
+			as encounter_started,
+		--c_enc.last_affirmed
+		now()
+			as encounter_last_affirmed,
+		c_ety.description
+			as encounter_type,
+		_(c_ety.description)
+			as encounter_l10n_type
+
+	from
+		clin.allergy_state c_ast
+			inner join clin.encounter c_enc on (c_ast.fk_encounter = c_enc.pk)
+				inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+
+;
+
+
+grant select on clin.v_pat_allergy_state_journal to group "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_pat_allergy_state_journal.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_pat_encounters_journal.sql b/server/sql/v20-v21/dynamic/v21-clin-v_pat_encounters_journal.sql
new file mode 100644
index 0000000..2c25eae
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_pat_encounters_journal.sql
@@ -0,0 +1,122 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_pat_encounters_journal cascade;
+
+
+create view clin.v_pat_encounters_journal as
+select
+	c_enc.fk_patient
+		as pk_patient,
+	c_enc.modified_when
+		as modified_when,
+	-- FIXME: or last_affirmed ?
+	c_enc.started
+		as clin_when,
+	coalesce (
+		(select short_alias from dem.staff where db_user = c_enc.modified_by),
+		'<' || c_enc.modified_by || '>'
+	) 	as modified_by,
+	null::text
+		as soap_cat,
+	_('Encounter') || ': '
+			|| (select _(description) from clin.encounter_type where pk = c_enc.fk_type)
+			|| to_char(c_enc.started::timestamp with time zone, ' YYYY-MM-DD HH24:MI')
+			|| to_char(c_enc.last_affirmed::timestamp with time zone, ' - HH24:MI')
+			|| coalesce(E'\n @ ' || _('branch') || ' "' || d_ou.description || '" ' || _('of') || ' "' || d_o.description || '"', '')
+			|| coalesce(E'\n ' || _('RFE') || ': ' || c_enc.reason_for_encounter, '')
+			|| coalesce ((
+					E'\n' || array_to_string (
+						(select array_agg(r_csr.code || ' (' || r_ds.name_short || ' - ' || r_ds.version || ' - ' || r_ds.lang || '): ' || r_csr.term)
+						 from
+							clin.lnk_code2rfe c_lc2r
+								inner join
+							ref.coding_system_root r_csr on c_lc2r.fk_generic_code = r_csr.pk_coding_system
+								inner join
+							ref.data_source r_ds on r_ds.pk = r_csr.fk_data_source
+						where
+							c_lc2r.fk_item = c_enc.pk
+						),
+						'; '
+					) || ';'
+				),
+				''
+			)
+			|| coalesce(E'\n ' || _('AOE') || ': ' || c_enc.assessment_of_encounter, '')
+			|| coalesce ((
+					E'\n' || array_to_string (
+						(select array_agg(r_csr.code || ' (' || r_ds.name_short || ' - ' || r_ds.version || ' - ' || r_ds.lang || '): ' || r_csr.term)
+						 from
+							clin.lnk_code2aoe c_lc2a
+								inner join
+							ref.coding_system_root r_csr on c_lc2a.fk_generic_code = r_csr.pk_coding_system
+								inner join
+							ref.data_source r_ds on r_ds.pk = r_csr.fk_data_source
+						where
+							c_lc2a.fk_item = c_enc.pk
+						),
+						'; '
+					) || ';'
+				),
+				''
+			)
+		as narrative,
+	c_enc.pk
+		as pk_encounter,
+	NULL::integer
+		as pk_episode,
+	NULL::integer
+		as pk_health_issue,
+	c_enc.pk
+		as src_pk,
+	'clin.encounter'::text as src_table,
+	c_enc.row_version,
+
+	-- issue
+	NULL::text
+		as health_issue,
+	NULL::text
+		as issue_laterality,
+	NULL::boolean
+		as issue_active,
+	NULL::boolean
+		as issue_clinically_relevant,
+	NULL::boolean
+		as issue_confidential,
+
+	-- episode
+	NULL::text
+		as episode,
+	NULL::boolean
+		as episode_open,
+
+	-- encounter
+	c_enc.started
+		as encounter_started,
+	c_enc.last_affirmed
+		as encounter_last_affirmed,
+	c_ety.description
+		as encounter_type,
+	_(c_ety.description)
+		as encounter_l10n_type
+
+from
+	clin.encounter c_enc
+		inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+			left join dem.org_unit d_ou on (c_enc.fk_location = d_ou.pk)
+				left join dem.org d_o on (d_ou.fk_org = d_o.pk)
+;
+
+
+grant select on clin.v_pat_encounters_journal TO GROUP "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_pat_encounters_journal.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_pat_episodes_journal.sql b/server/sql/v20-v21/dynamic/v21-clin-v_pat_episodes_journal.sql
new file mode 100644
index 0000000..ed26f43
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_pat_episodes_journal.sql
@@ -0,0 +1,107 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_pat_episodes_journal cascade;
+
+
+create view clin.v_pat_episodes_journal as
+select
+	c_enc.fk_patient
+		as pk_patient,
+	c_epi.modified_when
+		as modified_when,
+	c_enc.started
+		as clin_when,
+	coalesce (
+		(select short_alias from dem.staff where db_user = c_epi.modified_by),
+		'<' || c_epi.modified_by || '>'
+	)
+		as modified_by,
+	'a'::text
+		as soap_cat,
+	_('Episode') || ' ('
+		|| case when c_epi.is_open
+			then _('open')
+			else _('closed')
+			end
+		|| coalesce((', ' || c_epi.diagnostic_certainty_classification), '')
+		|| '): '
+		|| c_epi.description || ';'
+		|| coalesce((E'\n ' || _('Synopsis') || ': ' || c_epi.summary || ';'), '')
+		|| coalesce ((
+				E'\n' || array_to_string (
+					(select array_agg(r_csr.code || ' (' || r_ds.name_short || ' - ' || r_ds.version || ' - ' || r_ds.lang || '): ' || r_csr.term)
+					 from
+					 	clin.lnk_code2episode c_lc2e
+					 		inner join
+						ref.coding_system_root r_csr on c_lc2e.fk_generic_code = r_csr.pk_coding_system
+							inner join
+						ref.data_source r_ds on r_ds.pk = r_csr.fk_data_source
+					where
+						c_lc2e.fk_item = c_epi.pk
+					),
+					'; '
+				) || ';'
+			),
+			''
+		)
+		as narrative,
+	c_epi.fk_encounter
+		as pk_encounter,
+	c_epi.pk
+		as pk_episode,
+	c_epi.fk_health_issue
+		as pk_health_issue,
+	c_epi.pk
+		as src_pk,
+	'clin.episode'::text
+		as src_table,
+	c_epi.row_version,
+
+	-- issue
+	c_hi.description
+		as health_issue,
+	c_hi.laterality
+		as issue_laterality,
+	c_hi.is_active
+		as issue_active,
+	c_hi.clinically_relevant
+		as issue_clinically_relevant,
+	c_hi.is_confidential
+		as issue_confidential,
+
+	-- episode
+	c_epi.description
+		as episode,
+	c_epi.is_open
+		as episode_open,
+
+	-- encounter
+	c_enc.started
+		as encounter_started,
+	c_enc.last_affirmed
+		as encounter_last_affirmed,
+	c_ety.description
+		as encounter_type,
+	_(c_ety.description)
+		as encounter_l10n_type
+
+from
+	clin.episode c_epi
+		inner join clin.encounter c_enc on (c_epi.fk_encounter = c_enc.pk)
+			inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+				left join clin.health_issue c_hi on (c_epi.fk_health_issue = c_hi.pk)
+;
+
+
+grant select on clin.v_pat_episodes_journal TO GROUP "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_pat_episodes_journal.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_pat_narrative_journal.sql b/server/sql/v20-v21/dynamic/v21-clin-v_pat_narrative_journal.sql
new file mode 100644
index 0000000..c9c7cb2
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_pat_narrative_journal.sql
@@ -0,0 +1,87 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_pat_narrative_journal cascade;
+
+
+create view clin.v_pat_narrative_journal as
+select
+	c_enc.fk_patient
+		as pk_patient,
+	c_n.modified_when
+		as modified_when,
+	case
+		-- pre-sort:
+		when c_n.soap_cat in ('s','o','u') then c_enc.started
+		when c_n.soap_cat is NULL then c_enc.last_affirmed
+		when c_n.soap_cat in ('a','p') then c_enc.last_affirmed
+	end
+		as clin_when,
+	coalesce (
+		(select short_alias from dem.staff where db_user = c_n.modified_by),
+		'<' || c_n.modified_by || '>'
+	)
+		as modified_by,
+	c_n.soap_cat
+		as soap_cat,
+	c_n.narrative
+		as narrative,
+	c_n.fk_encounter
+		as pk_encounter,
+	c_n.fk_episode
+		as pk_episode,
+	c_epi.fk_health_issue
+		as pk_health_issue,
+	c_n.pk
+		as src_pk,
+	'clin.clin_narrative'::text
+		as src_table,
+	c_n.row_version,
+
+	-- issue
+	c_hi.description
+		as health_issue,
+	c_hi.laterality
+		as issue_laterality,
+	c_hi.is_active
+		as issue_active,
+	c_hi.clinically_relevant
+		as issue_clinically_relevant,
+	c_hi.is_confidential
+		as issue_confidential,
+
+	-- episode
+	c_epi.description
+		as episode,
+	c_epi.is_open
+		as episode_open,
+
+	-- encounter
+	c_enc.started
+		as encounter_started,
+	c_enc.last_affirmed
+		as encounter_last_affirmed,
+	c_ety.description
+		as encounter_type,
+	_(c_ety.description)
+		as encounter_l10n_type
+
+from
+	clin.clin_narrative c_n
+		inner join clin.encounter c_enc on (c_n.fk_encounter = c_enc.pk)
+			inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+				inner join clin.episode c_epi on (c_n.fk_episode = c_epi.pk)
+					left join clin.health_issue c_hi on (c_epi.fk_health_issue = c_hi.pk)
+;
+
+
+grant select on clin.v_pat_narrative_journal TO GROUP "gm-doctors";
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_pat_narrative_journal.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_procedures_journal.sql b/server/sql/v20-v21/dynamic/v21-clin-v_procedures_journal.sql
new file mode 100644
index 0000000..eb2c1e0
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_procedures_journal.sql
@@ -0,0 +1,232 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_procedures_at_hospital_journal cascade;
+
+create view clin.v_procedures_at_hospital_journal as
+select
+	c_enc.fk_patient
+		as pk_patient,
+	c_pr.modified_when
+		as modified_when,
+	c_pr.clin_when
+		as clin_when,
+	coalesce (
+		(select short_alias from dem.staff where db_user = c_pr.modified_by),
+		'<' || c_pr.modified_by || '>'
+	)
+		as modified_by,
+	c_pr.soap_cat
+		as soap_cat,
+	_('Procedure') || ' "' || c_pr.narrative	|| '"'
+		|| ' ('
+			|| d_ou.description || ' @ ' || d_o.description
+			|| coalesce (
+				(', ' || _('until') || ' ' || to_char(c_pr.clin_end, 'YYYY Mon DD')),
+				case
+					when (c_pr.is_ongoing is True)
+						then ', ' || _('ongoing')
+						else ''
+				end
+			)
+		|| E')'
+		|| coalesce ((
+				E'\n' || array_to_string (
+					(select array_agg(r_csr.code || ' (' || r_ds.name_short || ' - ' || r_ds.version || ' - ' || r_ds.lang || '): ' || r_csr.term)
+					 from
+					 	clin.lnk_code2procedure c_lc2p
+					 		inner join
+						ref.coding_system_root r_csr on c_lc2p.fk_generic_code = r_csr.pk_coding_system
+							inner join
+						ref.data_source r_ds on r_ds.pk = r_csr.fk_data_source
+					where
+						c_lc2p.fk_item = c_pr.pk
+					),
+					'; '
+				) || ';'
+			),
+			''
+		)
+		as narrative,
+	c_pr.fk_encounter
+		as pk_encounter,
+	c_pr.fk_episode
+		as pk_episode,
+	c_epi.fk_health_issue
+		as pk_health_issue,
+	c_pr.pk
+		as src_pk,
+	'clin.procedure'::text
+		as src_table,
+	c_pr.row_version,
+
+	-- issue
+	c_hi.description
+		as health_issue,
+	c_hi.laterality
+		as issue_laterality,
+	c_hi.is_active
+		as issue_active,
+	c_hi.clinically_relevant
+		as issue_clinically_relevant,
+	c_hi.is_confidential
+		as issue_confidential,
+
+	-- episode
+	c_epi.description
+		as episode,
+	c_epi.is_open
+		as episode_open,
+
+	-- encounter
+	c_enc.started
+		as encounter_started,
+	c_enc.last_affirmed
+		as encounter_last_affirmed,
+	c_ety.description
+		as encounter_type,
+	_(c_ety.description)
+		as encounter_l10n_type
+
+from
+	clin.procedure c_pr
+		inner join clin.encounter c_enc on c_pr.fk_encounter = c_enc.pk
+			inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+		inner join clin.episode c_epi on c_pr.fk_episode = c_epi.pk
+			left join clin.health_issue c_hi on (c_epi.fk_health_issue = c_hi.pk)
+		left join clin.hospital_stay c_hs on c_pr.fk_hospital_stay = c_hs.pk
+			left join dem.org_unit d_ou on c_hs.fk_org_unit = d_ou.pk
+				left join dem.org d_o on d_ou.fk_org = d_o.pk
+where
+	c_pr.fk_hospital_stay is not null
+;
+
+
+grant select on clin.v_procedures_at_hospital_journal TO GROUP "gm-doctors";
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_procedures_not_at_hospital_journal cascade;
+
+create view clin.v_procedures_not_at_hospital_journal as
+select
+	c_enc.fk_patient
+		as pk_patient,
+	c_pr.modified_when
+		as modified_when,
+	c_pr.clin_when
+		as clin_when,
+	coalesce (
+		(select short_alias from dem.staff where db_user = c_pr.modified_by),
+		'<' || c_pr.modified_by || '>'
+	)
+		as modified_by,
+	c_pr.soap_cat
+		as soap_cat,
+	_('Procedure') || ' "' || c_pr.narrative	|| '"'
+		|| ' ('
+			|| d_ou.description || ' @ ' || d_o.description
+			|| coalesce (
+				(', ' || _('until') || ' ' || to_char(c_pr.clin_end, 'YYYY Mon DD')),
+				case
+					when (c_pr.is_ongoing is True)
+						then ', ' || _('ongoing')
+						else ''
+				end
+			)
+		|| E')'
+		|| coalesce ((
+				E'\n' || array_to_string (
+					(select array_agg(r_csr.code || ' (' || r_ds.name_short || ' - ' || r_ds.version || ' - ' || r_ds.lang || '): ' || r_csr.term)
+					 from
+					 	clin.lnk_code2procedure c_lc2p
+					 		inner join
+						ref.coding_system_root r_csr on c_lc2p.fk_generic_code = r_csr.pk_coding_system
+							inner join
+						ref.data_source r_ds on r_ds.pk = r_csr.fk_data_source
+					where
+						c_lc2p.fk_item = c_pr.pk
+					),
+					'; '
+				) || ';'
+			),
+			''
+		)
+		as narrative,
+	c_pr.fk_encounter
+		as pk_encounter,
+	c_pr.fk_episode
+		as pk_episode,
+	c_epi.fk_health_issue
+		as pk_health_issue,
+	c_pr.pk
+		as src_pk,
+	'clin.procedure'::text
+		as src_table,
+	c_pr.row_version,
+
+	-- issue
+	c_hi.description
+		as health_issue,
+	c_hi.laterality
+		as issue_laterality,
+	c_hi.is_active
+		as issue_active,
+	c_hi.clinically_relevant
+		as issue_clinically_relevant,
+	c_hi.is_confidential
+		as issue_confidential,
+
+	-- episode
+	c_epi.description
+		as episode,
+	c_epi.is_open
+		as episode_open,
+
+	-- encounter
+	c_enc.started
+		as encounter_started,
+	c_enc.last_affirmed
+		as encounter_last_affirmed,
+	c_ety.description
+		as encounter_type,
+	_(c_ety.description)
+		as encounter_l10n_type
+
+from
+	clin.procedure c_pr
+		inner join clin.encounter c_enc on c_pr.fk_encounter = c_enc.pk
+			inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+		inner join clin.episode c_epi on c_pr.fk_episode = c_epi.pk
+			left join clin.health_issue c_hi on (c_epi.fk_health_issue = c_hi.pk)
+		left join dem.org_unit d_ou on c_pr.fk_org_unit = d_ou.pk
+			left join dem.org d_o on d_ou.fk_org = d_o.pk
+where
+	c_pr.fk_hospital_stay is null
+;
+
+
+grant select on clin.v_procedures_not_at_hospital_journal TO GROUP "gm-doctors";
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_procedures_journal cascade;
+
+create view clin.v_procedures_journal as
+
+	select * from clin.v_procedures_at_hospital_journal
+		union all
+	select * from clin.v_procedures_not_at_hospital_journal
+;
+
+
+grant select on clin.v_procedures_journal TO GROUP "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_procedures_journal.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_reminders_journal.sql b/server/sql/v20-v21/dynamic/v21-clin-v_reminders_journal.sql
new file mode 100644
index 0000000..6bba6bc
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_reminders_journal.sql
@@ -0,0 +1,323 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_reminders_journal cascade;
+
+
+create view clin.v_reminders_journal as
+
+	-- clin_when: due date
+	select
+		d_mi.fk_patient
+			as pk_patient,
+		d_mi.modified_when
+			as modified_when,
+		d_mi.due_date
+			as clin_when,
+		coalesce (
+			(select short_alias from dem.staff where db_user = d_mi.modified_by),
+			'<' || d_mi.modified_by || '>'
+		)
+			as modified_by,
+		NULL::text
+			as soap_cat,
+		_('Due today') || ' (' || d_vit.l10n_category || ' - ' || d_vit.l10n_type || ')' || E'\n'
+			|| coalesce(' ' || d_mi.comment || E'\n', '')
+			|| coalesce(' ' || _('Will expire:') || ' ' || to_char(d_mi.expiry_date, 'YYYY-MM-DD') || E'\n', '')
+			|| ' ' || _('Importance:') || ' ' || d_mi.importance || E'\n'
+			|| coalesce(' ' || _('Context:') || ' ' || array_to_string(d_mi.ufk_context, ',', '?') || E'\n', '')
+			|| coalesce(' ' || _('Data:') || ' ' || d_mi.data || E'\n', '')
+			|| coalesce(' ' || _('Provider:') || ' ' || d_st.short_alias, '')
+		as narrative,
+		(
+			select c_e.pk
+			from clin.encounter c_e
+			where c_e.fk_patient = d_mi.fk_patient
+			order by started desc
+			limit 1
+		)
+			as pk_encounter,
+		null::integer
+			as pk_episode,
+		null::integer
+			as pk_health_issue,
+		d_mi.pk
+			as src_pk,
+		'dem.message_inbox'::text
+			as src_table,
+		d_mi.row_version
+			as row_version,
+
+		-- issue
+		null::text
+			as health_issue,
+		null::text
+			as issue_laterality,
+		null::boolean
+			as issue_active,
+		null::boolean
+			as issue_clinically_relevant,
+		null::boolean
+			as issue_confidential,
+
+		-- episode
+		null::text
+			as episode,
+		null::boolean
+			as episode_open,
+
+		-- encounter
+		(
+			select c_e.started
+			from clin.encounter c_e
+			where c_e.fk_patient = d_mi.fk_patient
+			order by started desc
+			limit 1
+		)
+			as encounter_started,
+		(
+			select c_e.last_affirmed
+			from clin.encounter c_e
+			where c_e.fk_patient = d_mi.fk_patient
+			order by started desc
+			limit 1
+		)
+			as encounter_last_affirmed,
+		null::text
+			as encounter_type,
+		null::text
+			as encounter_l10n_type
+	from
+		dem.message_inbox d_mi
+			inner join dem.v_inbox_item_type d_vit on (d_mi.fk_inbox_item_type = d_vit.pk_type)
+			left join dem.staff d_st on (d_mi.fk_staff = d_st.pk)
+	where
+		d_mi.fk_patient is not null
+			and
+		d_vit.category = 'clinical'
+			and
+		d_mi.due_date is not null
+
+UNION
+
+	-- clin_when: expiry date
+	select
+		d_mi.fk_patient
+			as pk_patient,
+		d_mi.modified_when
+			as modified_when,
+		d_mi.expiry_date
+			as clin_when,
+		coalesce (
+			(select short_alias from dem.staff where db_user = d_mi.modified_by),
+			'<' || d_mi.modified_by || '>'
+		)
+			as modified_by,
+		NULL::text
+			as soap_cat,
+		_('Epires today') || ' (' || d_vit.l10n_category || ' - ' || d_vit.l10n_type || ')' || E'\n'
+			|| coalesce(' ' || d_mi.comment || E'\n', '')
+			|| coalesce(' ' || _('Was due:') || ' ' || to_char(d_mi.due_date, 'YYYY-MM-DD') || E'\n', '')
+			|| ' ' || _('Importance:') || ' ' || d_mi.importance || E'\n'
+			|| coalesce(' ' || _('Context:') || ' ' || array_to_string(d_mi.ufk_context, ',', '?') || E'\n', '')
+			|| coalesce(' ' || _('Data:') || ' ' || d_mi.data || E'\n', '')
+			|| coalesce(' ' || _('Provider:') || ' ' || d_st.short_alias, '')
+		as narrative,
+		(
+			select c_e.pk
+			from clin.encounter c_e
+			where c_e.fk_patient = d_mi.fk_patient
+			order by started desc
+			limit 1
+		)
+			as pk_encounter,
+		null::integer
+			as pk_episode,
+		null::integer
+			as pk_health_issue,
+		d_mi.pk
+			as src_pk,
+		'dem.message_inbox'::text
+			as src_table,
+		d_mi.row_version
+			as row_version,
+
+		-- issue
+		null::text
+			as health_issue,
+		null::text
+			as issue_laterality,
+		null::boolean
+			as issue_active,
+		null::boolean
+			as issue_clinically_relevant,
+		null::boolean
+			as issue_confidential,
+
+		-- episode
+		null::text
+			as episode,
+		null::boolean
+			as episode_open,
+
+		-- encounter
+		(
+			select c_e.started
+			from clin.encounter c_e
+			where c_e.fk_patient = d_mi.fk_patient
+			order by started desc
+			limit 1
+		)
+			as encounter_started,
+		(
+			select c_e.last_affirmed
+			from clin.encounter c_e
+			where c_e.fk_patient = d_mi.fk_patient
+			order by started desc
+			limit 1
+		)
+			as encounter_last_affirmed,
+		null::text
+			as encounter_type,
+		null::text
+			as encounter_l10n_type
+	from
+		dem.message_inbox d_mi
+			inner join dem.v_inbox_item_type d_vit on (d_mi.fk_inbox_item_type = d_vit.pk_type)
+			left join dem.staff d_st on (d_mi.fk_staff = d_st.pk)
+	where
+		d_mi.fk_patient is not null
+			and
+		d_vit.category = 'clinical'
+			and
+		d_mi.expiry_date is not null
+
+UNION
+
+	-- clin_when: modified_when (= message received)
+	select
+		d_mi.fk_patient
+			as pk_patient,
+		d_mi.modified_when
+			as modified_when,
+		d_mi.modified_when
+			as clin_when,
+		coalesce (
+			(select short_alias from dem.staff where db_user = d_mi.modified_by),
+			'<' || d_mi.modified_by || '>'
+		)
+			as modified_by,
+		NULL::text
+			as soap_cat,
+		_('Clinical reminder') || ' (' || d_vit.l10n_category || ' - ' || d_vit.l10n_type || ')' || E'\n'
+			|| coalesce(' ' || d_mi.comment || E'\n', '')
+			|| coalesce(' ' || _('Due:') || ' ' || to_char(d_mi.due_date, 'YYYY-MM-DD') || E'\n', '')
+			|| coalesce(' ' || _('Expires:') || ' ' || to_char(d_mi.expiry_date, 'YYYY-MM-DD') || E'\n', '')
+			|| ' ' || _('Importance:') || ' ' || d_mi.importance || E'\n'
+			|| coalesce(' ' || _('Context:') || ' ' || array_to_string(d_mi.ufk_context, ',', '?') || E'\n', '')
+			|| coalesce(' ' || _('Data:') || ' ' || d_mi.data || E'\n', '')
+			|| coalesce(' ' || _('Provider:') || ' ' || d_st.short_alias, '')
+		as narrative,
+		(
+			select c_e.pk
+			from clin.encounter c_e
+			where c_e.fk_patient = d_mi.fk_patient
+			order by started desc
+			limit 1
+		)
+			as pk_encounter,
+		null::integer
+			as pk_episode,
+		null::integer
+			as pk_health_issue,
+		d_mi.pk
+			as src_pk,
+		'dem.message_inbox'::text
+			as src_table,
+		d_mi.row_version
+			as row_version,
+
+		-- issue
+		null::text
+			as health_issue,
+		null::text
+			as issue_laterality,
+		null::boolean
+			as issue_active,
+		null::boolean
+			as issue_clinically_relevant,
+		null::boolean
+			as issue_confidential,
+
+		-- episode
+		null::text
+			as episode,
+		null::boolean
+			as episode_open,
+
+		-- encounter
+		(
+			select c_e.started
+			from clin.encounter c_e
+			where c_e.fk_patient = d_mi.fk_patient
+			order by started desc
+			limit 1
+		)
+			as encounter_started,
+		(
+			select c_e.last_affirmed
+			from clin.encounter c_e
+			where c_e.fk_patient = d_mi.fk_patient
+			order by started desc
+			limit 1
+		)
+			as encounter_last_affirmed,
+		null::text
+			as encounter_type,
+		null::text
+			as encounter_l10n_type
+	from
+		dem.message_inbox d_mi
+			inner join dem.v_inbox_item_type d_vit on (d_mi.fk_inbox_item_type = d_vit.pk_type)
+			left join dem.staff d_st on (d_mi.fk_staff = d_st.pk)
+	where
+		d_mi.fk_patient is not null
+			and
+		d_vit.category = 'clinical'
+			and
+		(
+			(d_mi.due_date is not null)
+				or
+			(d_mi.expiry_date is not null)
+		)
+;
+
+
+grant select on clin.v_reminders_journal to group "gm-doctors";
+
+-- --------------------------------------------------------------
+select i18n.upd_tx('de', 'Clinical reminder', 'Medizinische Erinnerung');
+
+select i18n.upd_tx('de', 'Due today', 'Heute fällig');
+select i18n.upd_tx('de', 'Due:', 'Fällig:');
+select i18n.upd_tx('de', 'Was due:', 'War fällig:');
+
+select i18n.upd_tx('de', 'Epires today', 'Läuft heute ab');
+select i18n.upd_tx('de', 'Expires:', 'Läuft ab:');
+select i18n.upd_tx('de', 'Will expire:', 'Wird ablaufen:');
+
+select i18n.upd_tx('de', 'Importance:', 'Bedeutsamkeit:');
+select i18n.upd_tx('de', 'Context:', 'Kontext:');
+select i18n.upd_tx('de', 'Data:', 'Daten:');
+select i18n.upd_tx('de', 'Provider:', 'Mitarbeiter:');
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_reminders_journal.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_substance_intake4narrative_search.sql b/server/sql/v20-v21/dynamic/v21-clin-v_substance_intake4narrative_search.sql
new file mode 100644
index 0000000..b9f58b7
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_substance_intake4narrative_search.sql
@@ -0,0 +1,46 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_subst_intake4narr_search cascade;
+
+create view clin.v_subst_intake4narr_search as
+
+select
+	c_enc.fk_patient
+		as pk_patient,
+	c_si.soap_cat
+		as soap_cat,
+	coalesce(c_si.narrative, '')			-- comment/note/advice
+		|| coalesce(' / ' || c_si.comment_on_start, '')
+		|| coalesce(' / ' || c_si.schedule, '')
+		|| coalesce(' / ' || c_si.aim, '')
+		|| coalesce(' / ' || c_si.discontinue_reason, '')
+		as narrative,
+	c_si.fk_encounter
+		as pk_encounter,
+	c_si.fk_episode
+		as pk_episode,
+	c_epi.fk_health_issue
+		as pk_health_issue,
+	c_si.pk
+		as src_pk,
+	'clin.substance_intake'
+		as src_table
+from
+	clin.substance_intake c_si
+		join clin.encounter c_enc on (c_si.fk_encounter = c_enc.pk)
+			join clin.episode c_epi on (c_si.fk_episode = c_epi.pk)
+;
+
+grant select on clin.v_subst_intake4narr_search to group "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_subst_intake4narr_search.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_substance_intake_journal.sql b/server/sql/v20-v21/dynamic/v21-clin-v_substance_intake_journal.sql
new file mode 100644
index 0000000..3b536e0
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_substance_intake_journal.sql
@@ -0,0 +1,258 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_pat_substance_intake_journal cascade;
+drop view if exists clin.v_substance_intake_journal cascade;
+
+
+create view clin.v_substance_intake_journal as
+
+	-- brands
+	select
+		c_enc.fk_patient
+			as pk_patient,
+		c_si.modified_when
+			as modified_when,
+		c_si.clin_when
+			as clin_when,
+		coalesce (
+			(select short_alias from dem.staff where db_user = c_si.modified_by),
+			'<' || c_si.modified_by || '>'
+		)
+			as modified_by,
+		c_si.soap_cat
+			as soap_cat,
+
+		(case
+			when is_long_term is true then _('long-term') || ' '
+			else ''
+		 end
+		)
+			|| _('substance intake') || ' '
+			|| (case
+					when intake_is_approved_of is true then _('(approved of)')
+					when intake_is_approved_of is false then _('(not approved of)')
+					else _('(of unknown approval)')
+				end)
+			|| (case
+					when harmful_use_type IS NULL then ''
+					when harmful_use_type = 0 then _('no harmful use')
+					when harmful_use_type = 1 then _('harmful use')
+					when harmful_use_type = 2 then _('addiction')
+					when harmful_use_type = 3 then _('previous addiction')
+				end)
+			|| E':\n'
+
+			|| ' ' || r_cs.description								-- Metoprolol
+			|| coalesce(' [' || r_cs.atc_code || '] ', ' ')			-- [ATC]
+			|| r_cs.amount::text									-- 100
+			|| r_cs.unit || ' '										-- mg
+			|| r_bd.preparation										-- tab
+			|| coalesce(' ' || c_si.schedule, '')					-- 1-0-0
+			|| ', ' || (case
+					when c_si.comment_on_start = '?' then '?'		-- start = unknown
+					when c_si.comment_on_start is NULL then to_char(c_si.clin_when, 'YYYY-MM-DD')				-- 2009-03-01
+					else '~' || to_char(c_si.clin_when, 'YYYY-MM-DD') || ' (' || c_si.comment_on_start || ')'	-- ~2009-03-01 (comment)
+				end)
+			|| coalesce(' -> ' || c_si.duration, '')				-- -> 6 months
+			|| E'\n'
+
+			|| coalesce (
+				' ' || _('Discontinued') || to_char(c_si.discontinued, ': YYYY-MM-DD')
+					|| coalesce(' (' || c_si.discontinue_reason || ')', '')
+					|| E'\n',
+				''
+			)
+
+			|| coalesce(E'\n ' || _('Aim') || ': ' || c_si.aim, '')				-- lower RR
+			|| coalesce(E'\n ' || _('Notes') || ': ' || c_si.narrative, '')		-- report if unwell
+
+			|| coalesce (' "' || r_bd.description || '"'													-- "MetoPharm"
+				|| coalesce(' [' || r_bd.atc_code || ']', '')												-- [ATC code]
+				|| coalesce(' (' || r_bd.external_code_type || ': ' || r_bd.external_code || ')', ''),		-- (external code)
+				'')
+
+		as narrative,
+
+		c_si.fk_encounter
+			as pk_encounter,
+		c_si.fk_episode
+			as pk_episode,
+		(select fk_health_issue from clin.episode where pk = c_si.fk_episode)
+			as pk_health_issue,
+		c_si.pk
+			as src_pk,
+		'clin.substance_intake'::text
+			as src_table,
+		c_si.row_version
+			as row_version,
+
+		-- issue
+		c_hi.description
+			as health_issue,
+		c_hi.laterality
+			as issue_laterality,
+		c_hi.is_active
+			as issue_active,
+		c_hi.clinically_relevant
+			as issue_clinically_relevant,
+		c_hi.is_confidential
+			as issue_confidential,
+
+		-- episode
+		c_epi.description
+			as episode,
+		c_epi.is_open
+			as episode_open,
+
+		-- encounter
+		c_enc.started
+			as encounter_started,
+		c_enc.last_affirmed
+			as encounter_last_affirmed,
+		c_ety.description
+			as encounter_type,
+		_(c_ety.description)
+			as encounter_l10n_type
+
+	from
+		clin.substance_intake c_si
+			inner join ref.lnk_substance2brand r_ls2b on (c_si.fk_drug_component = r_ls2b.pk)
+				inner join ref.branded_drug r_bd on (r_bd.pk = r_ls2b.fk_brand)
+				inner join ref.consumable_substance r_cs on (r_cs.pk = r_ls2b.fk_substance)
+			inner join clin.encounter c_enc on (c_si.fk_encounter = c_enc.pk)
+				inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+			inner join clin.episode c_epi on (c_si.fk_episode = c_epi.pk)
+				left join clin.health_issue c_hi on (c_epi.fk_health_issue = c_hi.pk)
+	where
+		c_si.fk_drug_component is not null
+
+union all
+
+	-- substances w/o brands
+	select
+		c_enc.fk_patient
+			as pk_patient,
+		c_si.modified_when
+			as modified_when,
+		c_si.clin_when
+			as clin_when,
+		coalesce (
+			(select short_alias from dem.staff where db_user = c_si.modified_by),
+			'<' || c_si.modified_by || '>'
+		)
+			as modified_by,
+		c_si.soap_cat
+			as soap_cat,
+
+		(case
+			when is_long_term is true then _('long-term') || ' '
+			else ''
+		 end
+		)
+			|| (case
+					when harmful_use_type IS NULL then _('Substance intake') || ' '
+					else _('Substance abuse') || ' '
+				end)
+			|| (case
+					when intake_is_approved_of is true then _('(approved of)')
+					when intake_is_approved_of is false then _('(not approved of)')
+					else _('(of unknown approval)')
+				end)
+			|| (case
+					when harmful_use_type IS NULL then ''
+					when harmful_use_type = 0 then ', ' || _('no harmful use') || ' (' || to_char(c_enc.started, 'YYYY-MM-DD') || ')'
+					when harmful_use_type = 1 then ', ' || _('harmful use') || ' (' || to_char(c_enc.started, 'YYYY-MM-DD') || ')'
+					when harmful_use_type = 2 then ', ' || _('addiction') || ' (' || to_char(c_enc.started, 'YYYY-MM-DD') || ')'
+					when harmful_use_type = 3 then ', ' || _('previous addiction') || ' (' || to_char(c_enc.started, 'YYYY-MM-DD') || ')'
+				end)
+			|| E':\n'
+
+			|| ' ' || r_cs.description								-- Metoprolol
+			|| coalesce(' [' || r_cs.atc_code || '] ', ' ')			-- [ATC]
+			|| r_cs.amount || r_cs.unit || ' '						-- 100mg
+			|| c_si.preparation										-- tab
+			|| coalesce(' ' || c_si.schedule, '')					-- 1-0-0
+			|| ', ' || (case
+					when c_si.comment_on_start = '?' then '?'		-- start = unknown
+					when c_si.comment_on_start is NULL then to_char(c_si.clin_when, 'YYYY-MM-DD')				-- 2009-03-01
+					else '~' || to_char(c_si.clin_when, 'YYYY-MM-DD') || ' (' || c_si.comment_on_start || ')'	-- ~2009-03-01 (comment)
+				end)
+			|| coalesce(' -> ' || c_si.duration, '')				-- -> 6 months
+			|| E'\n'
+
+			|| coalesce (
+				' ' || _('Discontinued') || to_char(c_si.discontinued, ': YYYY-MM-DD') || coalesce(' (' || c_si.discontinue_reason || ')', '') || E'\n',
+				''
+			)
+
+			|| coalesce(E'\n ' || _('Aim') || ': ' || c_si.aim, '')				-- lower RR
+			|| coalesce(E'\n ' || _('Notes') || ': ' || c_si.narrative, '')		-- report if unwell
+		as narrative,
+
+		c_si.fk_encounter
+			as pk_encounter,
+		c_si.fk_episode
+			as pk_episode,
+		(select fk_health_issue from clin.episode where pk = c_si.fk_episode)
+			as pk_health_issue,
+		c_si.pk
+			as src_pk,
+		'clin.substance_intake'::text
+			as src_table,
+		c_si.row_version
+			as row_version,
+
+		-- issue
+		c_hi.description
+			as health_issue,
+		c_hi.laterality
+			as issue_laterality,
+		c_hi.is_active
+			as issue_active,
+		c_hi.clinically_relevant
+			as issue_clinically_relevant,
+		c_hi.is_confidential
+			as issue_confidential,
+
+		-- episode
+		c_epi.description
+			as episode,
+		c_epi.is_open
+			as episode_open,
+
+		-- encounter
+		c_enc.started
+			as encounter_started,
+		c_enc.last_affirmed
+			as encounter_last_affirmed,
+		c_ety.description
+			as encounter_type,
+		_(c_ety.description)
+			as encounter_l10n_type
+
+	from
+		clin.substance_intake c_si
+			inner join ref.consumable_substance r_cs on (r_cs.pk = c_si.fk_substance)
+			inner join clin.encounter c_enc on (c_si.fk_encounter = c_enc.pk)
+				inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+			inner join clin.episode c_epi on (c_si.fk_episode = c_epi.pk)
+				left join clin.health_issue c_hi on (c_epi.fk_health_issue = c_hi.pk)
+	where
+		c_si.fk_drug_component is null
+
+;
+
+
+grant select on clin.v_substance_intake_journal to group "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_substance_intake_journal.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_substance_intakes.sql b/server/sql/v20-v21/dynamic/v21-clin-v_substance_intakes.sql
new file mode 100644
index 0000000..6db6e2b
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_substance_intakes.sql
@@ -0,0 +1,419 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_brand_intakes cascade;
+
+create view clin.v_brand_intakes as
+select
+	c_si.pk
+		as pk_substance_intake,
+	(select fk_patient from clin.encounter where pk = c_si.fk_encounter)
+		as pk_patient,
+	c_si.soap_cat,
+	r_bd.description
+		as brand,
+	r_bd.preparation,
+	r_cs.description
+		as substance,
+	r_cs.amount,
+	r_cs.unit
+		as unit,
+
+	r_cs.atc_code
+		as atc_substance,
+	r_bd.atc_code
+		as atc_brand,
+	r_bd.external_code
+		as external_code_brand,
+	r_bd.external_code_type
+		as external_code_type_brand,
+
+	-- uncertainty of start
+	case
+		when c_si.comment_on_start = '?' then null
+		else c_si.clin_when
+	end::timestamp with time zone
+		as started,
+	c_si.comment_on_start,
+	case
+		when c_si.comment_on_start = '?' then true
+		else false
+	end::boolean
+		as start_is_unknown,
+	case
+		when c_si.comment_on_start is null then false
+		else true
+	end::boolean
+		as start_is_approximate,
+	c_si.intake_is_approved_of,
+	c_si.harmful_use_type,
+	NULL::timestamp with time zone
+		as last_checked_when,
+	c_si.schedule,
+	c_si.duration,
+	c_si.discontinued,
+	c_si.discontinue_reason,
+	c_si.is_long_term,
+	c_si.aim,
+	cep.description
+		as episode,
+	c_hi.description
+		as health_issue,
+	c_si.narrative
+		as notes,
+	r_bd.is_fake
+		as fake_brand,
+	-- currently active ?
+	case
+		-- no discontinue date documented so assumed active
+		when c_si.discontinued is null then true
+		-- else not active (constraints guarantee that .discontinued > clin_when and < current_timestamp)
+		else false
+	end::boolean
+		as is_currently_active,
+	-- seems inactive ?
+	case
+		when c_si.discontinued is not null then true
+		-- from here on discontinued is NULL
+		when c_si.clin_when is null then
+			case
+				when c_si.is_long_term is true then false
+				else null
+			end
+		-- from here clin_when is NOT null
+		when (c_si.clin_when > current_timestamp) is true then true
+		when ((c_si.clin_when + c_si.duration) < current_timestamp) is true then true
+		when ((c_si.clin_when + c_si.duration) > current_timestamp) is true then false
+		else null
+	end::boolean
+		as seems_inactive,
+	r_ls2b.fk_brand
+		as pk_brand,
+	r_bd.fk_data_source
+		as pk_data_source,
+	r_ls2b.fk_substance
+		as pk_substance,
+	r_ls2b.pk
+		as pk_drug_component,
+	c_si.fk_encounter
+		as pk_encounter,
+	c_si.fk_episode
+		as pk_episode,
+	cep.fk_health_issue
+		as pk_health_issue,
+	c_si.modified_when,
+	c_si.modified_by,
+	c_si.row_version
+		as row_version,
+	c_si.xmin
+		as xmin_substance_intake
+from
+	clin.substance_intake c_si
+		inner join ref.lnk_substance2brand r_ls2b on (c_si.fk_drug_component = r_ls2b.pk)
+			inner join ref.branded_drug r_bd on (r_ls2b.fk_brand = r_bd.pk)
+			inner join ref.consumable_substance r_cs on (r_ls2b.fk_substance = r_cs.pk)
+				left join clin.episode cep on (c_si.fk_episode = cep.pk)
+					left join clin.health_issue c_hi on (c_hi.pk = cep.fk_health_issue)
+where
+	c_si.fk_drug_component IS NOT NULL
+
+;
+
+grant select on clin.v_brand_intakes to group "gm-doctors";
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_nonbrand_intakes cascade;
+
+create view clin.v_nonbrand_intakes as
+select
+	c_si.pk
+		as pk_substance_intake,
+	(select fk_patient from clin.encounter where pk = c_si.fk_encounter)
+		as pk_patient,
+	c_si.soap_cat,
+	null
+		as brand,
+	c_si.preparation,
+	r_cs.description
+		as substance,
+	r_cs.amount,
+	r_cs.unit
+		as unit,
+	r_cs.atc_code
+		as atc_substance,
+	null
+		as atc_brand,
+	null
+		as external_code_brand,
+	null
+		as external_code_type_brand,
+
+	-- uncertainty of start
+	case
+		when c_si.comment_on_start = '?' then null
+		else c_si.clin_when
+	end::timestamp with time zone
+		as started,
+	c_si.comment_on_start,
+	case
+		when c_si.comment_on_start = '?' then true
+		else false
+	end::boolean
+		as start_is_unknown,
+	case
+		when c_si.comment_on_start is null then false
+		else true
+	end::boolean
+		as start_is_approximate,
+	c_si.intake_is_approved_of,
+	c_si.harmful_use_type,
+	CASE
+		WHEN c_si.harmful_use_type IS NULL THEN NULL::timestamp with time zone
+		ELSE c_enc.started
+	END
+		AS last_checked_when,
+	c_si.schedule,
+	c_si.duration,
+	c_si.discontinued,
+	c_si.discontinue_reason,
+	c_si.is_long_term,
+	c_si.aim,
+	cep.description
+		as episode,
+	c_hi.description
+		as health_issue,
+	c_si.narrative
+		as notes,
+	null
+		as fake_brand,
+	-- currently active ?
+	case
+		-- no discontinue date documented so assumed active
+		when c_si.discontinued is null then true
+		-- else not active (constraints guarantee that .discontinued > clin_when and < current_timestamp)
+		else false
+	end::boolean
+		as is_currently_active,
+	-- seems inactive ?
+	case
+		when c_si.discontinued is not null then true
+		-- from here on discontinued is NULL
+		when c_si.clin_when is null then
+			case
+				when c_si.is_long_term is true then false
+				else null
+			end
+		-- from here clin_when is NOT null
+		when (c_si.clin_when > current_timestamp) is true then true
+		when ((c_si.clin_when + c_si.duration) < current_timestamp) is true then true
+		when ((c_si.clin_when + c_si.duration) > current_timestamp) is true then false
+		else null
+	end::boolean
+		as seems_inactive,
+	null
+		as pk_brand,
+	null
+		as pk_data_source,
+	r_cs.pk
+		as pk_substance,
+	null
+		as pk_drug_component,
+	c_si.fk_encounter
+		as pk_encounter,
+	c_si.fk_episode
+		as pk_episode,
+	cep.fk_health_issue
+		as pk_health_issue,
+	c_si.modified_when,
+	c_si.modified_by,
+	c_si.row_version
+		as row_version,
+	c_si.xmin
+		as xmin_substance_intake
+from
+	clin.substance_intake c_si
+		inner join ref.consumable_substance r_cs on (c_si.fk_substance = r_cs.pk)
+			left join clin.episode cep on (c_si.fk_episode = cep.pk)
+				left join clin.health_issue c_hi on (c_hi.pk = cep.fk_health_issue)
+					left join clin.encounter c_enc on (c_si.fk_encounter = c_enc.pk)
+where
+	c_si.fk_drug_component IS NULL
+;
+
+grant select on clin.v_nonbrand_intakes to group "gm-doctors";
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_substance_intakes cascade;
+
+create view clin.v_substance_intakes as
+select * from clin.v_brand_intakes
+	union all
+select * from clin.v_nonbrand_intakes
+;
+
+grant select on clin.v_substance_intakes to group "gm-doctors";
+
+-- --------------------------------------------------------------
+-- --------------------------------------------------------------
+INSERT INTO ref.consumable_substance (
+	description,
+	atc_code,
+	amount,
+	unit
+)	SELECT
+		'nicotine',
+		'N07BA01',
+		'1',
+		'piece'
+	WHERE
+		NOT EXISTS (SELECT 1 FROM ref.consumable_substance WHERE atc_code = 'N07BA01' and description = 'nicotine')
+;
+
+INSERT INTO clin.episode
+	(description, is_open, fk_encounter, summary)
+SELECT
+	'substance use',
+	false,
+	-- most recent encounter
+	(select pk from clin.encounter where fk_patient = (
+		select id_identity from dem.names where firstnames = 'James Tiberius' and lastnames = 'Kirk'
+	 )
+	 order by last_affirmed desc limit 1
+	),
+	'[substance use] (auto-added by v21.0 @ ' || clock_timestamp()::text || ')'
+WHERE NOT EXISTS (
+	SELECT 1 FROM clin.v_pat_episodes
+	WHERE
+		summary ILIKE '%[substance use]%'
+			AND
+		pk_patient = (
+			select id_identity from dem.names where firstnames = 'James Tiberius' and lastnames = 'Kirk'
+		)
+);
+
+INSERT INTO clin.substance_intake (
+	clin_when,
+	comment_on_start,
+	fk_encounter,
+	fk_episode,
+	fk_substance,
+	preparation,
+	narrative,
+	intake_is_approved_of,
+	harmful_use_type
+)	SELECT
+		'20051111'::timestamp,
+		'?',
+		(select pk from clin.encounter where fk_patient = (
+			select id_identity from dem.names where firstnames = 'James Tiberius' and lastnames = 'Kirk'
+		) order by last_affirmed desc limit 1),
+		(SELECT 1 FROM clin.v_pat_episodes WHERE
+			summary ILIKE '%[substance use]%'
+				AND
+			pk_patient = (
+				select id_identity from dem.names where firstnames = 'James Tiberius' and lastnames = 'Kirk'
+			)
+		),
+		(select pk from ref.consumable_substance where atc_code = 'N07BA01' limit 1),
+		'tobacco',
+		'enjoys an occasional pipe of Old Toby',
+		FALSE,
+		0
+;
+
+INSERT INTO ref.consumable_substance (
+	description,
+	atc_code,
+	amount,
+	unit
+)	SELECT
+		'ethanol',
+		'V03AB16',
+		'1',
+		'l'
+	WHERE
+		NOT EXISTS (SELECT 1 FROM ref.consumable_substance WHERE atc_code = 'V03AB16' and description = 'ethanol')
+;
+
+INSERT INTO clin.substance_intake (
+	clin_when,
+	comment_on_start,
+	fk_encounter,
+	fk_episode,
+	fk_substance,
+	preparation,
+	narrative,
+	intake_is_approved_of,
+	harmful_use_type
+)	SELECT
+		'20051111'::timestamp,
+		'?',
+		(select pk from clin.encounter where fk_patient = (
+			select id_identity from dem.names where firstnames = 'James Tiberius' and lastnames = 'Kirk'
+		) order by last_affirmed desc limit 1),
+		(SELECT 1 FROM clin.v_pat_episodes WHERE
+			summary ILIKE '%[substance use]%'
+				AND
+			pk_patient = (
+				select id_identity from dem.names where firstnames = 'James Tiberius' and lastnames = 'Kirk'
+			)
+		),
+		(select pk from ref.consumable_substance where atc_code = 'V03AB16' limit 1),
+		'liquid',
+		'occasionally relishes a fine glass of Saurian Brandy and will not forego a pint of Romulan Ale',
+		FALSE,
+		3
+;
+
+INSERT INTO ref.consumable_substance (
+	description,
+	amount,
+	unit
+)	SELECT
+		'other drugs',
+		'1',
+		'/1'
+	WHERE
+		NOT EXISTS (SELECT 1 FROM ref.consumable_substance WHERE description = 'other drugs')
+;
+
+INSERT INTO clin.substance_intake (
+	clin_when,
+	comment_on_start,
+	fk_encounter,
+	fk_episode,
+	fk_substance,
+	preparation,
+	narrative,
+	intake_is_approved_of,
+	harmful_use_type
+)	SELECT
+		'20051111'::timestamp,
+		'?',
+		(select pk from clin.encounter where fk_patient = (
+			select id_identity from dem.names where firstnames = 'James Tiberius' and lastnames = 'Kirk'
+		) order by last_affirmed desc limit 1),
+		(SELECT 1 FROM clin.v_pat_episodes WHERE
+			summary ILIKE '%[substance use]%'
+				AND
+			pk_patient = (
+				select id_identity from dem.names where firstnames = 'James Tiberius' and lastnames = 'Kirk'
+			)
+		),
+		(select pk from ref.consumable_substance where description = 'other drugs' limit 1),
+		'piece',
+		'possibly experimented with cordrazine at one point',
+		FALSE,
+		0
+;
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_substance_intakes.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_suppressed_hints.sql b/server/sql/v20-v21/dynamic/v21-clin-v_suppressed_hints.sql
new file mode 100644
index 0000000..b9d4bcd
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_suppressed_hints.sql
@@ -0,0 +1,50 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_suppressed_hints cascade;
+
+
+create view clin.v_suppressed_hints as
+select
+	(select fk_patient from clin.encounter where pk = c_sh.fk_encounter)
+		as pk_identity,
+	c_sh.pk
+		as pk_suppressed_hint,
+	c_sh.fk_hint
+		as pk_hint,
+	r_vah.title,
+	r_vah.hint,
+	r_vah.recommendation,
+	r_vah.url,
+	r_vah.is_active,
+	r_vah.source,
+	r_vah.query,
+	r_vah.lang,
+	c_sh.rationale,
+	c_sh.md5_sum
+		as md5_suppressed,
+	r_vah.md5_sum
+		as md5_hint,
+	c_sh.suppressed_by,
+	c_sh.suppressed_when,
+	c_sh.fk_encounter
+		as pk_encounter
+from
+	clin.suppressed_hint c_sh
+		join ref.v_auto_hints r_vah on c_sh.fk_hint = r_vah.pk_auto_hint
+;
+
+
+revoke all on clin.v_suppressed_hints from public;
+grant select on clin.v_suppressed_hints to group "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_suppressed_hints.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_suppressed_hints_journal.sql b/server/sql/v20-v21/dynamic/v21-clin-v_suppressed_hints_journal.sql
new file mode 100644
index 0000000..c879784
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_suppressed_hints_journal.sql
@@ -0,0 +1,98 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_suppressed_hints_journal cascade;
+
+
+create view clin.v_suppressed_hints_journal as
+select
+	c_enc.fk_patient
+		as pk_patient,
+	c_sh.modified_when
+		as modified_when,
+	c_sh.suppressed_when
+		as clin_when,
+	c_sh.modified_by
+		as modified_by,
+	'p'::text
+		as soap_cat,
+	case
+		when r_vah.is_active is TRUE then
+			_('Active hint')
+		else
+			_('Inactive hint')
+	end
+		|| ' #' || c_sh.fk_hint || ' ' || _('suppressed by') || ' ' || c_sh.suppressed_by || E'\n'
+		|| coalesce(_('Title: ') || r_vah.title || E'\n', '')
+		|| coalesce(_('URL: ') || r_vah.url || E'\n', '')
+		|| coalesce(_('Source: ') || r_vah.source || E'\n', '')
+		|| coalesce(_('Rationale: ') || c_sh.rationale || E'\n', '')
+		|| case when c_sh.md5_sum <> r_vah.md5_sum
+			then _('Hint definition has been modified since suppression. Rationale for suppression may no longer apply.') || E'\n'
+			else ''
+		end
+		|| coalesce(_('Hint: ') || r_vah.hint || E'\n', '')
+		|| coalesce(_('Recommendation: ') || r_vah.recommendation, '')
+		as narrative,
+	c_sh.fk_encounter
+		as fk_encounter,
+	NULL::integer
+		as pk_episode,
+	NULL::integer
+		as pk_health_issue,
+	c_sh.pk
+		as src_pk,
+	'clin.suppressed_hint'::text
+		as src_table,
+	c_sh.row_version
+		as row_version,
+
+	-- issue
+	null::text
+		as health_issue,
+	null::text
+		as issue_laterality,
+	null::boolean
+		as issue_active,
+	null::boolean
+		as issue_clinically_relevant,
+	null::boolean
+		as issue_confidential,
+
+	-- episode
+	null::text
+		as episode,
+	null::boolean
+		as episode_open,
+
+	-- encounter
+	c_enc.started
+		as encounter_started,
+	c_enc.last_affirmed
+		as encounter_last_affirmed,
+	c_ety.description
+		as encounter_type,
+	_(c_ety.description)
+		as encounter_l10n_type
+
+from
+	clin.suppressed_hint c_sh
+		inner join clin.encounter c_enc on (c_sh.fk_encounter = c_enc.pk)
+			inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+		inner join ref.v_auto_hints r_vah on (c_sh.fk_hint = r_vah.pk_auto_hint)
+;
+
+
+revoke all on clin.v_suppressed_hints from public;
+grant select on clin.v_suppressed_hints to group "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_suppressed_hints_journal.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_test_results_journal.sql b/server/sql/v20-v21/dynamic/v21-clin-v_test_results_journal.sql
new file mode 100644
index 0000000..cf663f4
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_test_results_journal.sql
@@ -0,0 +1,112 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_test_results_journal cascade;
+
+
+create view clin.v_test_results_journal as
+select
+	c_vtr.pk_patient
+		as pk_patient,
+	c_vtr.modified_when
+		as modified_when,
+	c_vtr.clin_when
+		as clin_when,
+	c_vtr.modified_by
+		as modified_by,
+	c_vtr.soap_cat
+		as soap_cat,
+	coalesce ((
+		c_vtr.unified_name || ' ('
+		|| c_vtr.unified_abbrev
+		|| coalesce(' [#' || c_vtr.unified_loinc || ']', '') || '): '
+		|| c_vtr.unified_val::text || ' '
+		|| coalesce(c_vtr.val_unit, '') || ' '
+		|| coalesce('(' || c_vtr.abnormality_indicator || ')', '') || E'\n'
+		|| _('Range: ')
+			|| coalesce(c_vtr.unified_target_min::text, '') || ' - '
+			|| coalesce(c_vtr.unified_target_max::text, '') || ' / '
+			|| coalesce(c_vtr.unified_target_range, '')
+			|| coalesce(' (' || c_vtr.norm_ref_group || ')', '') || E'\n'
+		|| coalesce(_('Assessment: ') || c_vtr.comment || E'\n', '')
+		|| coalesce(_('Context: ') || c_vtr.note_test_org || E'\n', '')
+		|| coalesce(_('Status: ') || c_vtr.status || E'\n', '')
+		|| coalesce(_('Grouping: ') || c_vtr.val_grouping || E'\n', '')
+		|| coalesce (
+			_('Review by ')
+				|| c_vtr.last_reviewer || ' @ '
+				|| to_char(c_vtr.last_reviewed, 'YYYY-MM-DD HH24:MI') || ': '
+				|| case when c_vtr.is_technically_abnormal then _('abnormal') || ', ' else '' end
+				|| case when c_vtr.is_clinically_relevant then _('relevant') || ' ' else '' end
+				|| coalesce('(' || c_vtr.review_comment || E')\n', E'\n')
+			, ''
+		)
+		|| _('Responsible clinician: ')
+			|| c_vtr.responsible_reviewer
+		|| coalesce(_('Source data:') || E'\n' || c_vtr.source_data || E'\n', '')
+		), 'faulty clin.v_test_results_journal definition'
+	)	as narrative,
+	c_vtr.pk_encounter
+		as pk_encounter,
+	c_vtr.pk_episode
+		as pk_episode,
+	c_vtr.pk_health_issue
+		as pk_health_issue,
+	c_vtr.pk_test_result
+		as src_pk,
+	'clin.test_result'::text
+		as src_table,
+	c_vtr.row_version
+		as row_version,
+
+	-- issue
+	c_vtr.health_issue
+		as health_issue,
+	c_hi.laterality
+		as issue_laterality,
+	c_hi.is_active
+		as issue_active,
+	c_hi.clinically_relevant
+		as issue_clinically_relevant,
+	c_hi.is_confidential
+		as issue_confidential,
+
+	-- episode
+	c_vtr.episode
+		as episode,
+	c_epi.is_open
+		as episode_open,
+
+	-- encounter
+	c_enc.started
+		as encounter_started,
+	c_enc.last_affirmed
+		as encounter_last_affirmed,
+	c_ety.description
+		as encounter_type,
+	_(c_ety.description)
+		as encounter_l10n_type
+
+from
+	clin.v_test_results c_vtr
+		inner join clin.encounter c_enc on (c_vtr.pk_encounter = c_enc.pk)
+			inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+				inner join clin.episode c_epi on (c_vtr.pk_episode = c_epi.pk)
+					left join clin.health_issue c_hi on (c_epi.fk_health_issue = c_hi.pk)
+;
+
+
+comment on view clin.v_test_results_journal is
+	'formatting of v_test_results for inclusion in v_emr_journal';
+
+
+grant select on clin.v_test_results_journal to group "gm-doctors";
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_test_results_journal.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_vaccinations_journal.sql b/server/sql/v20-v21/dynamic/v21-clin-v_vaccinations_journal.sql
new file mode 100644
index 0000000..3da1736
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_vaccinations_journal.sql
@@ -0,0 +1,116 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_pat_vaccinations_journal cascade;
+drop view if exists clin.v_vaccinations_journal cascade;
+
+
+create view clin.v_vaccinations_journal as
+select
+	c_enc.fk_patient
+		as pk_patient,
+	c_vacc.modified_when
+		as modified_when,
+	c_vacc.clin_when
+		as clin_when,
+	coalesce (
+		(select short_alias from dem.staff where db_user = c_vacc.modified_by),
+		'<' || c_vacc.modified_by || '>'
+	)
+		as modified_by,
+	c_vacc.soap_cat
+		as soap_cat,
+
+	(_('Vaccination') || ': '
+		|| r_bd.description || ' '
+		|| '[' || c_vacc.batch_no || ']'
+		|| coalesce(' (' || c_vacc.site || ')', '')
+		|| coalesce(E'\n' || _('Reaction') || ': ' || c_vacc.reaction, '')
+		|| coalesce(E'\n' || _('Comment') || ': ' || c_vacc.narrative, '')
+		|| coalesce (
+			(
+				E'\n' || _('Indications') || ': '
+				|| array_to_string ((
+					select
+						array_agg(_(description))
+		 			from
+						clin.lnk_vaccine2inds c_lv2i
+							join clin.vacc_indication cvi on (c_lv2i.fk_indication = cvi.id)
+					where
+						c_lv2i.fk_vaccine = c_vacc.fk_vaccine
+					),
+					' / '
+				)
+			),
+			''
+		)
+	)
+		as narrative,
+
+	c_vacc.fk_encounter
+		as pk_encounter,
+	c_vacc.fk_episode
+		as pk_episode,
+	(select fk_health_issue from clin.episode where pk = c_vacc.fk_episode)
+		as pk_health_issue,
+	c_vacc.pk
+		as src_pk,
+	'clin.vaccination'::text
+		as src_table,
+	c_vacc.row_version
+		as row_version,
+
+	-- issue
+	c_hi.description
+		as health_issue,
+	c_hi.laterality
+		as issue_laterality,
+	c_hi.is_active
+		as issue_active,
+	c_hi.clinically_relevant
+		as issue_clinically_relevant,
+	c_hi.is_confidential
+		as issue_confidential,
+
+	-- episode
+	c_epi.description
+		as episode,
+	c_epi.is_open
+		as episode_open,
+
+	-- encounter
+	c_enc.started
+		as encounter_started,
+	c_enc.last_affirmed
+		as encounter_last_affirmed,
+	c_ety.description
+		as encounter_type,
+	_(c_ety.description)
+		as encounter_l10n_type
+
+from
+	clin.vaccination c_vacc
+		join clin.encounter c_enc on (c_enc.pk = c_vacc.fk_encounter)
+			inner join clin.encounter_type c_ety on (c_enc.fk_type = c_ety.pk)
+		inner join clin.episode c_epi on (c_vacc.fk_episode = c_epi.pk)
+			left join clin.health_issue c_hi on (c_epi.fk_health_issue = c_hi.pk)
+		inner join clin.vaccine on (clin.vaccine.pk = c_vacc.fk_vaccine)
+			inner join ref.branded_drug r_bd on (clin.vaccine.fk_brand = r_bd.pk)
+;
+
+
+comment on view clin.v_vaccinations_journal is
+	'Vaccination data denormalized for the EMR journal.';
+
+
+grant select on clin.v_vaccinations_journal to group "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_vaccinations_journal.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-v_waiting_list.sql b/server/sql/v20-v21/dynamic/v21-clin-v_waiting_list.sql
new file mode 100644
index 0000000..6576667
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-v_waiting_list.sql
@@ -0,0 +1,72 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_waiting_list cascade;
+
+create view clin.v_waiting_list as
+select
+	c_wl.list_position
+		as list_position,
+	c_wl.area
+		as waiting_zone,
+	c_wl.urgency
+		as urgency,
+	d_i.title
+		as title,
+	d_n.firstnames
+		as firstnames,
+	d_n.lastnames
+		as lastnames,
+	d_n.preferred
+		as preferred_name,
+	d_i.dob
+		as dob,
+	d_i.gender
+		as gender,
+	_(d_i.gender)
+		as l10n_gender,
+	d_i.comment
+		as comment_identity,
+	c_wl.registered
+		as registered,
+	(select now() - c_wl.registered)
+		as waiting_time,
+	(select to_char(age(now(), c_wl.registered), 'DDD HH24:MI'))
+		as waiting_time_formatted,
+	c_wl.comment
+		as comment,
+	d_i.pk
+		as pk_identity,
+	d_n.id
+		as pk_name,
+	c_wl.pk
+		as pk_waiting_list
+from
+	clin.waiting_list c_wl,
+	dem.identity d_i,
+	dem.names d_n
+where
+	c_wl.fk_patient = d_i.pk
+		and
+	c_wl.fk_patient = d_n.id_identity
+		and
+	d_i.deceased is NULL
+		and
+	d_n.active is TRUE
+;
+
+
+revoke all on clin.v_waiting_list from public;
+grant select on clin.v_waiting_list to group "gm-public";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-v_waiting_list.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-clin-vaccination-dynamic.sql b/server/sql/v20-v21/dynamic/v21-clin-vaccination-dynamic.sql
new file mode 100644
index 0000000..9a03ec4
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-clin-vaccination-dynamic.sql
@@ -0,0 +1,196 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_lnk_vaccine2inds cascade;
+
+create view clin.v_lnk_vaccine2inds as
+	select
+		cv.pk
+			as pk_vaccine,
+
+		rbd.description
+			as vaccine,
+		rbd.preparation
+			as preparation,
+		rbd.atc_code
+			as atc_code,
+		rbd.is_fake
+			as is_fake_vaccine,
+
+		cvr.abbreviation
+			as route_abbreviation,
+		cvr.description
+			as route_description,
+
+		cv.is_live,
+		cv.min_age,
+		cv.max_age,
+		cv.comment,
+
+		cvi.description
+			as indication,
+		_(cvi.description)
+			as l10n_indication,
+		cvi.atcs_single_indication
+			as atcs_single_indication,
+		cvi.atcs_combi_indication
+			as atcs_combi_indication,
+
+		rbd.external_code,
+		rbd.external_code_type,
+
+		cv.id_route
+			as pk_route,
+		cv.fk_brand
+			as pk_brand,
+		rbd.fk_data_source
+			as pk_data_source,
+		cvi.id
+			as pk_indication,
+		cv.xmin
+			as xmin_vaccine
+	from
+		clin.vaccine cv
+			left outer join clin.vacc_route cvr on (cvr.id = cv.id_route)
+				join ref.branded_drug rbd on (rbd.pk = cv.fk_brand)
+					join clin.lnk_vaccine2inds clv2i on (clv2i.fk_vaccine = cv.pk)
+						join clin.vacc_indication cvi on (cvi.id = clv2i.fk_indication)
+
+;
+
+comment on view clin.v_lnk_vaccine2inds is
+	'Denormalizes indications per vaccine.';
+
+grant select on clin.v_lnk_vaccine2inds to group "gm-public";
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_pat_vaccs4indication cascade;
+
+create view clin.v_pat_vaccs4indication as
+select
+	c_enc.fk_patient
+		as pk_patient,
+	c_shot.pk
+		as pk_vaccination,
+	c_shot.clin_when
+		as date_given,
+	--c_vinds4vcine.vaccine
+	c_vlv2i.vaccine
+		as vaccine,
+	--c_vinds4vcine.indication
+	c_vlv2i.indication
+		as indication,
+	--c_vinds4vcine.l10n_indication
+	c_vlv2i.l10n_indication
+		as l10n_indication,
+	c_shot.site
+		as site,
+	c_shot.batch_no
+		as batch_no,
+	c_shot.reaction
+		as reaction,
+	c_shot.narrative
+		as comment,
+	c_shot.soap_cat
+		as soap_cat,
+
+	c_shot.modified_when
+		as modified_when,
+	c_shot.modified_by
+		as modified_by,
+	c_shot.row_version
+		as row_version,
+
+	c_shot.fk_vaccine
+		as pk_vaccine,
+	--c_vinds4vcine.pk_indication
+	c_vlv2i.pk_indication
+		as pk_indication,
+	c_shot.fk_provider
+		as pk_provider,
+	c_shot.fk_encounter
+		as pk_encounter,
+	c_shot.fk_episode
+		as pk_episode,
+
+	c_shot.xmin
+		as xmin_vaccination
+from
+	clin.vaccination c_shot
+		join clin.encounter c_enc on (c_enc.pk = c_shot.fk_encounter)
+			join clin.v_lnk_vaccine2inds c_vlv2i on (c_vlv2i.pk_vaccine = c_shot.fk_vaccine)
+--			join clin.v_indications4vaccine c_vinds4vcine on (c_vinds4vcine.pk_vaccine = c_shot.fk_vaccine)
+
+;
+
+comment on view clin.v_pat_vaccs4indication is
+	'Lists vaccinations per indication for patients';
+
+grant select on clin.v_pat_vaccs4indication to group "gm-doctors";
+
+-- --------------------------------------------------------------
+drop view if exists clin.v_pat_last_vacc4indication cascade;
+
+create view clin.v_pat_last_vacc4indication as
+	SELECT
+		c_vpv4i.*,
+		shots_per_ind.no_of_shots
+	FROM
+		clin.v_pat_vaccs4indication c_vpv4i
+			join (
+				SELECT
+					COUNT(1) AS no_of_shots
+					,pk_patient,
+					pk_indication
+				FROM clin.v_pat_vaccs4indication
+				GROUP BY
+					pk_patient,
+					pk_indication
+				) AS shots_per_ind
+			ON (c_vpv4i.pk_patient = shots_per_ind.pk_patient AND c_vpv4i.pk_indication = shots_per_ind.pk_indication)
+
+	where
+		c_vpv4i.date_given = (
+			select
+				max(c_vpv4i_2.date_given)
+			from
+				clin.v_pat_vaccs4indication c_vpv4i_2
+			where
+				c_vpv4i.pk_patient = c_vpv4i_2.pk_patient
+					and
+				c_vpv4i.pk_indication = c_vpv4i_2.pk_indication
+		)
+
+;
+
+comment on view clin.v_pat_last_vacc4indication is
+	'Lists *latest* vaccinations with total count per indication.';
+
+grant select on clin.v_pat_last_vacc4indication to group "gm-doctors";
+
+-- --------------------------------------------------------------
+drop index if exists clin.idx_clin_lnk_vaccine2inds_fk_vacc cascade;
+create index idx_clin_lnk_vaccine2inds_fk_vacc on clin.lnk_vaccine2inds(fk_vaccine);
+
+drop index if exists clin.idx_clin_lnk_vaccine2inds_fk_ind cascade;
+create index idx_clin_lnk_vaccine2inds_fk_ind on clin.lnk_vaccine2inds(fk_indication);
+
+
+drop index if exists clin.idx_clin_vaccination_fk_vaccine cascade;
+create index idx_clin_vaccination_fk_vaccine on clin.vaccination(fk_vaccine);
+
+drop index if exists clin.idx_clin_vaccination_fk_provider cascade;
+create index idx_clin_vaccination_fk_provider on clin.vaccination(fk_provider);
+
+drop index if exists clin.idx_clin_vaccination_clin_when cascade;
+create index idx_clin_vaccination_clin_when on clin.vaccination(clin_when);
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-vaccination-dynamic.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-dem-external_id-dynamic.sql b/server/sql/v20-v21/dynamic/v21-dem-external_id-dynamic.sql
new file mode 100644
index 0000000..a506273
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-dem-external_id-dynamic.sql
@@ -0,0 +1,15 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+select gm.register_notifying_table('dem', 'lnk_identity2ext_id');
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-dem-external_id-dynamic.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-dem-identity-dynamic.sql b/server/sql/v20-v21/dynamic/v21-dem-identity-dynamic.sql
new file mode 100644
index 0000000..6bf9069
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-dem-identity-dynamic.sql
@@ -0,0 +1,146 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+set check_function_bodies to on;
+
+-- --------------------------------------------------------------
+comment on column dem.identity.comment is
+	'A free-text comment on this identity.\n
+\n
+Can be used to to discriminate patients which are otherwise\n
+identical regarding name and date of birth.\n
+Should be something non-ephemereal and unique to the person\n
+itself across time, place and database instance.\n
+Good: place of birth\n
+Good: maiden name of mother\n
+Good: mother of <name>\n
+Good: hash of DNA\n
+Good (?): hair color of first pet\n
+Bad: current address (will change)\n
+Bad: primary provider in this praxis (can change, invalid in another GNUmed instance)\n
+Bad: nickname (will change, can dupe as well)\n
+Bad: favourite food\n
+not-quite-so-bad: occupation';
+
+-- --------------------------------------------------------------
+drop function if exists dem.new_pupic() cascade;
+
+-- --------------------------------------------------------------
+drop function if exists dem.trf_sane_identity_comment() cascade;
+
+-- disable audit trigger for update (because table layout has changed)
+alter table dem.identity
+	disable trigger zt_upd_identity;
+
+-- de-duplicate
+update dem.identity set
+	comment = coalesce(comment, '') || '[auto-set by <v21-dem-identity-dynamic.sql>: ' || clock_timestamp() || ']'
+where
+	pk in (
+		select pk_identity
+		from dem.v_persons d_vp1
+		where exists (
+			select 1 from dem.v_persons d_vp2
+			where
+				d_vp2.firstnames = d_vp1.firstnames
+					and
+				d_vp2.lastnames = d_vp1.lastnames
+					and
+				d_vp2.gender = d_vp1.gender
+					and
+				date_trunc('day', d_vp2.dob) = date_trunc('day', d_vp1.dob)
+					and
+				d_vp2.pk_identity != d_vp1.pk_identity
+		)
+	)
+;
+
+
+-- create function and trigger
+create function clin.trf_sane_identity_comment()
+	returns trigger
+	language 'plpgsql'
+	as '
+DECLARE
+	_identity_row record;
+	_names_row record;
+BEGIN
+	if TG_TABLE_NAME = ''identity'' then
+		if TG_OP = ''UPDATE'' then
+			if NEW.comment IS NOT DISTINCT FROM OLD.comment then
+				return NEW;
+			end if;
+		end if;
+		_identity_row := NEW;
+		select * into _names_row from dem.names where id_identity = NEW.pk;
+	else
+		select * into _identity_row from dem.identity where pk = NEW.id_identity;
+		_names_row := NEW;
+	end if;
+
+	-- any row with
+	PERFORM 1 FROM
+		dem.v_all_persons
+	WHERE
+		-- same firstname
+		firstnames = _names_row.firstnames
+			and
+		-- same lastname
+		lastnames = _names_row.lastnames
+			and
+		-- same gender
+		gender is not distinct from _identity_row.gender
+			and
+		-- same dob (day)
+		dob_only is not distinct from _identity_row.dob
+			and
+		-- same discriminator
+		comment is not distinct from _identity_row.comment
+			and
+		-- but not the currently updated or inserted row
+		pk_identity != _identity_row.pk
+	;
+	if FOUND then
+		RAISE EXCEPTION
+			''% on %.%: More than one person with (firstnames=%), (lastnames=%), (dob=%), (comment=%)'',
+				TG_OP,
+				TG_TABLE_SCHEMA,
+				TG_TABLE_NAME,
+				_names_row.firstnames,
+				_names_row.lastnames,
+				_identity_row.dob,
+				_identity_row.comment
+			USING ERRCODE = ''unique_violation''
+		;
+		RETURN NULL;
+	end if;
+
+	return NEW;
+END;';
+
+comment on function clin.trf_sane_identity_comment() is
+	'Ensures unique(identity.dob, names.firstnames, names.lastnames, identity.comment)';
+
+
+create trigger tr_sane_identity_comment
+	after insert or update on dem.identity
+	for each row execute procedure clin.trf_sane_identity_comment();
+
+
+create trigger tr_sane_identity_comment
+	after insert or update on dem.names
+	for each row execute procedure clin.trf_sane_identity_comment();
+
+
+-- tob nullable
+-- dob = (dyob + coalesce(tob, 11:11:11.111)) at client_timezone
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-dem-identity-dynamic.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-dem-org-trgm_idx.sql b/server/sql/v20-v21/dynamic/v21-dem-org-trgm_idx.sql
new file mode 100644
index 0000000..396adfe
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-dem-org-trgm_idx.sql
@@ -0,0 +1,20 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop index if exists dem.idx_trgm_dem_org_desc cascade;
+create index idx_trgm_dem_org_desc on dem.org using gin (description pgtrgm.gin_trgm_ops);
+
+-- --------------------------------------------------------------
+drop index if exists dem.idx_trgm_dem_org_unit_desc cascade;
+create index idx_trgm_dem_org_unit_desc on dem.org_unit using gin (description pgtrgm.gin_trgm_ops);
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-dem-org-trgm_idx.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-dem-person_views.sql b/server/sql/v20-v21/dynamic/v21-dem-person_views.sql
new file mode 100644
index 0000000..6c49b78
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-dem-person_views.sql
@@ -0,0 +1,135 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop view if exists dem.v_all_persons cascade;
+
+create view dem.v_all_persons as
+select
+	d_i.pk
+		as pk_identity,
+	d_i.title
+		as title,
+	d_n.firstnames
+		as firstnames,
+	d_n.preferred
+		as preferred,
+	d_n.lastnames
+		as lastnames,
+	d_i.gender
+		as gender,
+	_(d_i.gender)
+		as l10n_gender,
+	d_i.dob
+		as dob_only,
+	(date_trunc('day', d_i.dob) + coalesce(d_i.tob, dob::time))
+		as dob,
+	d_i.tob
+		as tob,
+	d_i.deceased
+		as deceased,
+	coalesce(d_ms.name, 'unknown')
+		as marital_status,
+	_(coalesce(d_ms.name, 'unknown'))
+		as l10n_marital_status,
+	d_i.emergency_contact
+		as emergency_contact,
+	d_i.comment
+		as comment,
+	d_i.deleted
+		as is_deleted,
+	d_i.fk_marital_status
+		as pk_marital_status,
+	d_n.id
+		as pk_active_name,
+	d_i.fk_emergency_contact
+		as pk_emergency_contact,
+	d_i.fk_primary_provider
+		as pk_primary_provider,
+	d_i.xmin
+		as xmin_identity,
+	d_i.dob_is_estimated
+		as dob_is_estimated
+from
+	dem.identity d_i
+		inner join dem.names d_n on ((d_n.id_identity = d_i.pk) and (d_n.active is true))
+			left outer join dem.marital_status d_ms on (d_i.fk_marital_status = d_ms.pk)
+;
+
+comment on view dem.v_all_persons is
+	'This view denormalizes persons with their active name.';
+
+revoke all on dem.v_all_persons from public;
+grant select on dem.v_all_persons to group "gm-public";
+
+-- --------------------------------------------------------------
+drop view if exists dem.v_deleted_persons cascade;
+
+create or replace view dem.v_deleted_persons as
+select d_vp.*
+from dem.v_all_persons d_vp
+where
+	d_vp.is_deleted is true
+;
+
+comment on view dem.v_deleted_persons is
+	'This view denormalizes "deleted" persons with their active name.';
+
+revoke all on dem.v_deleted_persons from public;
+grant select on dem.v_deleted_persons to group "gm-doctors";
+
+-- --------------------------------------------------------------
+drop view if exists dem.v_active_persons cascade;
+
+create or replace view dem.v_active_persons as
+select d_vp.*
+from dem.v_all_persons d_vp
+where
+	d_vp.is_deleted is false
+;
+
+comment on view dem.v_active_persons is
+	'This view denormalizes non-deleted persons with their active name.';
+
+revoke all on dem.v_active_persons from public;
+grant select on dem.v_active_persons to group "gm-public";
+
+-- --------------------------------------------------------------
+drop view if exists dem.v_basic_person cascade;
+
+-- --------------------------------------------------------------
+update cfg.report_query c_rq set
+	cmd = replace(cmd, 'v_basic_person', 'v_active_persons')
+where
+	c_rq.cmd is not null
+		and
+	position('v_basic_person' in c_rq.cmd) > 0
+;
+
+-- --------------------------------------------------------------
+update ref.auto_hint r_ah set
+	query = replace(query, 'v_basic_person', 'v_active_persons')
+where
+	r_ah.query is not null
+		and
+	position('v_basic_person' in r_ah.query) > 0
+;
+
+-- --------------------------------------------------------------
+update ref.auto_hint r_ah set
+	recommendation_query = replace(recommendation_query, 'v_basic_person', 'v_active_persons')
+where
+	r_ah.recommendation_query is not null
+		and
+	position('v_basic_person' in r_ah.recommendation_query) > 0
+;
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-dem-person_views.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-dem-region-dynamic.sql b/server/sql/v20-v21/dynamic/v21-dem-region-dynamic.sql
new file mode 100644
index 0000000..2ba244d
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-dem-region-dynamic.sql
@@ -0,0 +1,634 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+set check_function_bodies to on;
+
+-- --------------------------------------------------------------
+delete from audit.audited_tables where schema = 'dem' and table_name = 'state';
+
+select audit.add_table_for_audit('dem', 'region');
+
+drop function if exists audit.ft_ins_state() cascade;
+drop function if exists audit.ft_upd_state() cascade;
+drop function if exists audit.ft_del_state() cascade;
+
+COMMENT on table dem.region is
+	'region codes (country specific);
+	 Richard agreed we should require pre-existence,
+	 allow user to mail details for adding a state to developers';
+COMMENT on column dem.region.code is
+	'region code';
+
+-- --------------------------------------------------------------
+alter table dem.urb drop constraint if exists fk_dem_urb_dem_region_pk cascade;
+-- remnants of old
+alter table dem.urb drop constraint if exists "$1" cascade ;
+
+
+alter table dem.urb
+	add constraint fk_dem_urb_dem_region_pk
+		foreign key (fk_region)
+		references dem.region(pk)
+		on update cascade
+		on delete restrict
+;
+
+alter table dem.urb
+	drop constraint if exists urb_id_state_fkey cascade
+;
+
+COMMENT on column dem.urb.fk_region IS
+	'reference to information about country and region';
+
+-- --------------------------------------------------------------
+COMMENT on column dem.street.id_urb IS
+	'reference to information postcode, city, country and region';
+
+-- --------------------------------------------------------------
+drop function if exists dem.gm_upd_default_states() cascade;
+
+create or replace function dem.gm_upd_default_regions()
+	returns boolean
+	language 'plpgsql'
+	as '
+declare
+	_region_code text;
+	_region_name text;
+	_country_row record;
+begin
+	_region_code := ''??'';
+	_region_name := ''state/territory/province/region not available'';
+
+	-- add default region to countries needing one
+	for _country_row in
+		select distinct code from dem.country
+		where code not in (
+			select country from dem.region where code = _region_code
+		)
+	loop
+		raise notice ''adding default region for [%]'', _country_row.code;
+		execute ''insert into dem.region (code, country, name) values (''
+				|| quote_literal(_region_code) || '', ''
+				|| quote_literal(_country_row.code) || '', ''
+				|| quote_literal(_region_name) || '');'';
+	end loop;
+	return true;
+end;
+';
+
+select dem.gm_upd_default_regions();
+
+-- --------------------------------------------------------------
+DROP function if exists dem.create_urb(text, text, text, text);
+
+
+CREATE function dem.create_urb(text, text, text, text)
+	RETURNS integer
+	AS '
+DECLARE
+	_urb ALIAS FOR $1;
+	_urb_postcode ALIAS FOR $2;	
+	_region_code ALIAS FOR $3;
+	_country_code ALIAS FOR $4;
+
+ 	_region_pk integer;
+	_urb_id integer;
+
+	msg text;
+BEGIN
+ 	-- get region
+ 	SELECT INTO _region_pk d_r.pk from dem.region d_r WHERE d_r.code = _region_code and d_r.country = _country_code;
+ 	IF NOT FOUND THEN
+		msg := ''combination of region + country not registered [''
+			||   ''country:'' || coalesce(_country_code, ''NULL'')
+			||  '', region:'' || coalesce(_region_code, ''NULL'')
+			||     '', urb:'' || coalesce(_urb, ''NULL'')
+			|| '', urb_zip:'' || coalesce(_urb_postcode, ''NULL'')
+			|| '']'';
+		RAISE EXCEPTION ''=> %'', msg;
+ 	END IF;
+	-- get/create and return urb
+	SELECT INTO _urb_id u.id from dem.urb u WHERE u.name ILIKE _urb AND u.fk_region = _region_pk;
+	IF FOUND THEN
+		RETURN _urb_id;
+	END IF;
+	INSERT INTO dem.urb (name, postcode, fk_region) VALUES (_urb, _urb_postcode, _region_pk);
+	RETURN currval(''dem.urb_id_seq'');
+END;' LANGUAGE 'plpgsql';
+
+
+COMMENT ON function dem.create_urb(text, text, text, text) IS
+	'This function takes a parameters the name of the urb,\n
+	the postcode of the urb, the name of the region and the\n
+	name of the country.\n
+	If the country or the region does not exists in the tables,\n
+	the function fails.\n
+	At first, the urb is tried to be retrieved according to the\n
+	supplied information. If the fields do not match exactly an\n
+	existing row, a new urb is created and returned.';
+
+-- --------------------------------------------------------------
+drop function if exists dem.address_exists(text, text, text, text, text, text, text) cascade;
+
+
+create or replace function dem.address_exists(text, text, text, text, text, text, text)
+	returns integer
+	language 'plpgsql'
+	as '
+DECLARE
+	_code_country alias for $1;
+	_code_region alias for $2;
+	_urb alias for $3;
+	_postcode alias for $4;
+	_street alias for $5;
+	_number alias for $6;
+	_subunit alias for $7;
+
+	__subunit text;
+	_pk_address integer;
+	msg text;
+BEGIN
+
+	if (_code_country || _code_region || _urb || _postcode || _street || _number) is NULL then
+		msg := ''[dem.address_exists]: insufficient or invalid address definition: ''
+			|| ''country code <'' || coalesce(_code_country, ''NULL'') || ''>, ''
+			|| ''region code <'' || coalesce(_code_region, ''NULL'') || ''>, ''
+			|| ''urb <'' || coalesce(_urb, ''NULL'') || ''>, ''
+			|| ''zip <'' || coalesce(_postcode, ''NULL'') || ''>, ''
+			|| ''street <'' || coalesce(_street, ''NULL'') || ''>, ''
+			|| ''number <'' || coalesce(_number, ''NULL'') || ''>''
+		;
+		raise exception ''%'', msg;
+	end if;
+
+	__subunit := nullif(trim(_subunit), '''');
+
+	if __subunit is null then
+		select
+			pk_address into _pk_address
+		from
+			dem.v_address
+		where
+			code_country = trim(_code_country)
+				and
+			code_region = trim(_code_region)
+				and
+			urb = trim(_urb)
+				and
+			postcode = trim(_postcode)
+				and
+			street = trim(_street)
+				and
+			number = trim(_number)
+				and
+			subunit is null;
+	else
+		select
+			pk_address into _pk_address
+		from
+			dem.v_address
+		where
+			code_country = trim(_code_country)
+				and
+			code_region = trim(_code_region)
+				and
+			urb = trim(_urb)
+				and
+			postcode = trim(_postcode)
+				and
+			street = trim(_street)
+				and
+			number = trim(_number)
+				and
+			subunit = __subunit;
+	end if;
+
+	return _pk_address;
+END;';
+
+
+comment on function dem.address_exists(text, text, text, text, text, text, text) is
+E'This function checks whether a given address exists in
+the database and returns the primary key if found.
+
+It takes the following parameters:
+
+	country code,
+	region code,
+	urb (location),
+	postcode,
+	street,
+	number,
+	subunit (can be NULL)
+';
+
+--------------------------------------------------------------
+drop function if exists dem.create_address(text, text, text, text, text, text, text);
+
+
+create or replace function dem.create_address(text, text, text, text, text, text, text)
+	returns integer
+	LANGUAGE 'plpgsql'
+	AS '
+DECLARE
+	_number ALIAS FOR $1;
+	_street ALIAS FOR $2;
+	_postcode ALIAS FOR $3;
+	_urb ALIAS FOR $4;
+	_region_code ALIAS FOR $5;
+	_country_code ALIAS FOR $6;
+	_subunit alias for $7;
+
+	_street_id integer;
+	_pk_address integer;
+
+	__subunit text;
+	msg text;
+BEGIN
+	select into _pk_address dem.address_exists (
+		_country_code,
+		_region_code,
+		_urb,
+		_postcode,
+		_street,
+		_number,
+		_subunit
+	);
+
+	if _pk_address is not null then
+		return _pk_address;
+	end if;
+
+	-- this either creates dem.street and possible dem.urb rows or
+	-- or else it fails (because region and/or country do not exist)
+	select into _street_id dem.create_street(_street, _postcode, _urb, _region_code, _country_code);
+
+	-- create address
+	__subunit := nullif(trim(_subunit), '''');
+	insert into dem.address (
+		number,
+		id_street,
+		subunit
+	) values (
+		_number,
+		_street_id,
+		__subunit
+	)
+	returning id
+	into _pk_address;
+
+	return _pk_address;
+END;';
+
+
+comment on function dem.create_address(text, text, text, text, text, text, text) is
+E'This function creates an address. It first
+checks whether the address already exists.
+
+It takes the following parameters:
+
+	number,
+	street,
+	postcode,
+	urb (location),
+	region code,
+	country code,
+	subunit (can be NULL)
+
+If the country or the region do not exist
+in the database, the function fails.
+';
+
+-- --------------------------------------------------------------
+drop view if exists dem.v_state cascade;
+drop view if exists dem.v_region cascade;
+
+
+create view dem.v_region as
+select
+	d_r.pk as pk_region,
+	d_r.code as code_region,
+	d_r.name as region,
+	_(d_r.name) as l10n_region,
+	d_r.country as code_country,
+	c.name as country,
+	_(c.name) as l10n_country,
+	c.deprecated as country_deprecated,
+	d_r.xmin as xmin_region
+from
+	dem.region as d_r
+		left join dem.country c on (d_r.country = c.code)
+;
+
+
+comment on view dem.v_region is 'denormalizes region information';
+
+
+grant select on dem.v_region to group "gm-doctors";
+
+-- --------------------------------------------------------------
+drop view if exists dem.v_urb cascade;
+
+
+create view dem.v_urb as
+select
+	d_u.id as pk_urb,
+	d_u.name as urb,
+	d_u.postcode as postcode_urb,
+	d_u.lat_lon as lat_lon_urb,
+	d_vr.code_region,
+	d_vr.region,
+	d_vr.l10n_region,
+	d_vr.code_country,
+	d_vr.country,
+	d_vr.l10n_country,
+	d_vr.country_deprecated,
+	d_u.fk_region as pk_region,
+	d_u.xmin as xmin_urb
+from
+	dem.urb d_u
+		left join dem.v_region as d_vr on (d_vr.pk_region = d_u.fk_region)
+;
+
+
+comment on view dem.v_urb is 'denormalizes urb data';
+
+
+grant select on dem.v_urb to group "gm-doctors";
+
+-- --------------------------------------------------------------
+drop view if exists dem.v_street cascade;
+
+
+create view dem.v_street as
+select
+	d_st.id as pk_street,
+	d_st.name as street,
+	coalesce(d_st.postcode, d_vu.postcode_urb) as postcode,
+	d_st.postcode as postcode_street,
+	d_st.lat_lon as lat_lon_street,
+	d_st.suburb as suburb,
+	d_vu.urb,
+	d_vu.postcode_urb,
+	d_vu.lat_lon_urb,
+	d_vu.code_region,
+	d_vu.region,
+	d_vu.l10n_region,
+	d_vu.code_country,
+	d_vu.country,
+	d_vu.l10n_country,
+	d_vu.country_deprecated,
+	d_st.id_urb as pk_urb,
+	d_vu.pk_region,
+	d_st.xmin as xmin_street
+from
+	dem.street d_st
+		left join dem.v_urb d_vu on (d_st.id_urb = d_vu.pk_urb)
+;
+
+
+comment on view dem.v_street is 'denormalizes street data';
+
+
+grant select on dem.v_street to group "gm-doctors";
+
+-- ------------------------------------------------------------
+drop view if exists dem.v_address cascade;
+
+
+create view dem.v_address as
+select
+	d_adr.id
+		as pk_address,
+	d_str.name
+		as street,
+	coalesce(d_str.postcode, d_u.postcode)
+		as postcode,
+	d_adr.aux_street
+		as notes_street,
+	d_adr.number,
+	d_adr.subunit,
+	d_adr.addendum
+		as notes_subunit,
+	d_adr.lat_lon
+		as lat_lon_address,
+	d_str.postcode
+		as postcode_street,
+	d_str.lat_lon
+		as lat_lon_street,
+	d_str.suburb,
+	d_u.name
+		as urb,
+	d_u.postcode
+		as postcode_urb,
+	d_u.lat_lon
+		as lat_lon_urb,
+	d_r.code
+		as code_region,
+	d_r.name
+		as region,
+	_(d_r.name)
+		as l10n_region,
+	d_r.country
+		as code_country,
+	d_c.name
+		as country,
+	_(d_c.name)
+		as l10n_country,
+	d_c.deprecated
+		as country_deprecated,
+	d_adr.id_street
+		as pk_street,
+	d_u.id
+		as pk_urb,
+	d_r.pk
+		as pk_region,
+	d_adr.xmin
+		as xmin_address
+from
+	dem.address d_adr
+		left join dem.street d_str on (d_adr.id_street = d_str.id)
+			left join dem.urb d_u on (d_str.id_urb = d_u.id)
+				left join dem.region d_r on (d_u.fk_region = d_r.pk)
+					left join dem.country d_c on (d_c.code = d_r.country)
+;
+
+
+comment on view dem.v_address is 'fully denormalizes data about addresses as entities in themselves';
+
+
+grant select on dem.v_address to group "gm-doctors";
+
+-- --------------------------------------------------------------
+drop view if exists dem.v_zip2street cascade;
+
+create view dem.v_zip2street as
+	select
+		coalesce (d_str.postcode, d_u.postcode) as postcode,
+		d_str.name as street,
+		d_str.suburb as suburb,
+		d_r.name as region,
+		d_r.code as code_region,
+		d_u.name as urb,
+		d_c.name as country,
+		_(d_c.name) as l10n_country,
+		d_r.country as code_country
+	from
+		dem.street d_str,
+		dem.urb d_u,
+		dem.region d_r,
+		dem.country d_c
+	where
+		d_str.postcode is not null
+			and
+		d_str.id_urb = d_u.id
+			and
+		d_u.fk_region = d_r.pk
+			and
+		d_r.country = d_c.code
+;
+
+comment on view dem.v_zip2street is
+	'list known data for streets that have a zip code';
+
+-- --------------------------------------------------------------
+drop view if exists dem.v_uniq_zipped_urbs cascade;
+
+create view dem.v_uniq_zipped_urbs as
+	-- all the cities that
+	select
+		d_u.postcode as postcode,
+		d_u.name as name,
+		d_r.name as region,
+		d_r.code as code_region,
+		d_c.name as country,
+		_(d_c.name) as l10n_country,
+		d_r.country as code_country
+	from
+		dem.urb d_u,
+		dem.region d_r,
+		dem.country d_c
+	where
+		-- have a zip code
+		d_u.postcode is not null
+			and
+		-- are not found in "street" with this zip code
+		not exists (
+			select 1 from
+				dem.v_zip2street d_vz2str
+			where
+				d_vz2str.postcode = d_u.postcode
+					and
+				d_vz2str.urb = d_u.name
+			) and
+		d_u.fk_region = d_r.pk
+			and
+		d_r.country = d_c.code
+;
+
+comment on view dem.v_uniq_zipped_urbs is
+	'convenience view that selects urbs which:
+	 - have a zip code
+	 - are not referenced in table "street" with that zip code';
+
+grant select on dem.v_uniq_zipped_urbs to group "gm-doctors";
+
+-- --------------------------------------------------------------
+drop view if exists dem.v_zip2data;
+
+create view dem.v_zip2data as
+	select
+		d_vz2s.postcode as zip,
+		d_vz2s.street,
+		d_vz2s.suburb,
+		d_vz2s.urb,
+		d_vz2s.region,
+		d_vz2s.code_region,
+		d_vz2s.country,
+		d_vz2s.l10n_country,
+		d_vz2s.code_country
+	from dem.v_zip2street d_vz2s
+		union
+	select
+		d_vuzu.postcode as zip,
+		null as street,
+		null as suburb,
+		d_vuzu.name as urb,
+		d_vuzu.region,
+		d_vuzu.code_region,
+		d_vuzu.country,
+		d_vuzu.l10n_country,
+		d_vuzu.code_country
+	from
+		dem.v_uniq_zipped_urbs d_vuzu
+;
+
+comment on view dem.v_zip2data is
+	'aggregates nearly all known data per zip code';
+
+-- --------------------------------------------------------------
+drop view if exists dem.v_zip2urb cascade;
+
+create view dem.v_zip2urb as
+	select
+		d_u.postcode as postcode,
+		d_u.name as urb,
+		d_r.name as region,
+		d_r.code as code_region,
+		_(d_c.name) as country,
+		d_r.country as code_country
+	from
+		dem.urb d_u,
+		dem.region d_r,
+		dem.country d_c
+	where
+		d_u.postcode is not null
+			and
+		d_u.fk_region = d_r.pk
+			and
+		d_r.country = d_c.code
+;
+
+comment on view dem.v_zip2urb is
+	'list known data for urbs that have a zip code';
+
+-- --------------------------------------------------------------
+drop view if exists dem.v_basic_address cascade;
+
+create view dem.v_basic_address as
+select
+	d_adr.id as id,
+	d_r.country as country_code,
+	d_r.code as region_code,
+	d_r.name as region,
+	d_c.name as country,
+	coalesce (d_str.postcode, d_u.postcode) as postcode,
+	d_u.name as urb,
+	d_adr.number as number,
+	d_str.name as street,
+	d_adr.addendum as addendum,
+	coalesce (d_adr.lat_lon, d_str.lat_lon, d_u.lat_lon) as lat_lon
+from
+	dem.address d_adr,
+	dem.region d_r,
+	dem.country d_c,
+	dem.urb d_u,
+	dem.street d_str
+where
+	d_r.country = d_c.code
+		and
+	d_adr.id_street = d_str.id
+		and
+	d_str.id_urb = d_u.id
+		and
+	d_u.fk_region = d_r.pk;
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-dem-region-dynamic.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-dem-staff-dynamic.sql b/server/sql/v20-v21/dynamic/v21-dem-staff-dynamic.sql
new file mode 100644
index 0000000..6bf1e7d
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-dem-staff-dynamic.sql
@@ -0,0 +1,141 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten.Hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+set check_function_bodies to on;
+
+-- --------------------------------------------------------------
+drop function if exists dem.trf_prevent_deletion_of_in_use_staff() cascade;
+
+create or replace function dem.trf_prevent_deletion_of_in_use_staff()
+	returns trigger
+	 language 'plpgsql'
+	as '
+BEGIN
+	-- does any audited table contain the dem.staff.db_user we are about to delete ?
+	PERFORM 1 FROM audit.audit_fields WHERE modified_by = OLD.db_user LIMIT 1;
+	IF FOUND THEN
+		RAISE EXCEPTION
+			''DELETE from dem.staff: Sanity check failed. User <%> is referenced from <.modified_by> of at least one audited table.'', OLD.db_user
+			USING ERRCODE = ''foreign_key_violation''
+		;
+		RETURN NULL;
+	END IF;
+
+	-- does any audit table contain the dem.staff.db_user we are about to delete ?
+	PERFORM 1 FROM audit.audit_trail WHERE orig_by = OLD.db_user OR audit_by = OLD.db_user LIMIT 1;
+	IF FOUND THEN
+		RAISE EXCEPTION
+			''DELETE from dem.staff: Sanity check failed. User <%> is referenced from <.orig_by> or <.audit_by> of at least one audit table.'', OLD.db_user
+			USING ERRCODE = ''foreign_key_violation''
+		;
+		RETURN NULL;
+	END IF;
+
+	RETURN OLD;
+END;
+';
+
+comment on function dem.trf_prevent_deletion_of_in_use_staff() is
+	'this function is used to prevent DELETEs of staff members which had been used to store data';
+
+
+drop trigger if exists tr_prevent_deletion_of_in_use_staff on dem.staff cascade;
+
+create trigger tr_prevent_deletion_of_in_use_staff
+	before delete on dem.staff
+	for each row execute procedure dem.trf_prevent_deletion_of_in_use_staff();
+
+-- --------------------------------------------------------------
+drop view if exists dem.v_staff cascade;
+
+
+create view dem.v_staff as
+select
+	d_vp.pk_identity
+		as pk_identity,
+	d_s.pk
+		as pk_staff,
+	d_vp.title
+		as title,
+	d_vp.firstnames
+		as firstnames,
+	d_vp.lastnames
+		as lastnames,
+	d_s.short_alias
+		as short_alias,
+	case
+		when (select exists(select 1 from pg_group where
+			groname = 'gm-doctors'
+				and
+			(select usesysid from pg_user where usename = d_s.db_user) = any(grolist)
+		)) then 'full clinical access'
+		when (select exists(select 1 from pg_group where
+			groname = 'gm-nurses'
+				and
+			(select usesysid from pg_user where usename = d_s.db_user) = any(grolist)
+		)) then 'limited clinical access'
+		when (select exists(select 1 from pg_group where
+			groname = 'gm-staff'
+				and
+			(select usesysid from pg_user where usename = d_s.db_user) = any(grolist)
+		)) then 'non-clinical access'
+		when (select exists(select 1 from pg_group where
+			groname = 'gm-public'
+				and
+			(select usesysid from pg_user where usename = d_s.db_user) = any(grolist)
+		)) then 'public access'
+	end as role,
+	d_vp.dob
+		as dob,
+	d_vp.gender
+		as gender,
+	d_s.db_user
+		as db_user,
+	d_s.comment
+		as comment,
+	d_s.is_active
+		as is_active,
+	d_vp.is_deleted
+		as person_is_deleted,
+	(select (
+		select exists (
+			SELECT 1
+			from pg_group
+			where
+				(SELECT usesysid from pg_user where usename = d_s.db_user) = any(grolist)
+					and
+				groname = current_database()
+		)
+	) AND (
+		select exists (
+			SELECT 1
+			from pg_group
+			where
+				(SELECT usesysid from pg_user where usename = d_s.db_user) = any(grolist)
+					and
+				groname = 'gm-logins'
+		)
+	)) as can_login,
+	d_s.xmin
+		as xmin_staff
+from
+	dem.staff d_s
+		join dem.v_all_persons d_vp on d_s.fk_identity = d_vp.pk_identity
+;
+
+
+comment on view dem.v_staff is 'Denormalized staff data.';
+
+
+revoke all on dem.v_staff from public;
+grant select on dem.v_staff to group "gm-public";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-dem-staff-dynamic.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-dem-v_basic_person.sql b/server/sql/v20-v21/dynamic/v21-dem-v_basic_person.sql
new file mode 100644
index 0000000..94e5310
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-dem-v_basic_person.sql
@@ -0,0 +1,27 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop view if exists dem.v_basic_person cascade;
+
+create or replace view dem.v_basic_person as
+select d_vap.*
+from dem.v_active_persons d_vap;
+
+
+comment on view dem.v_basic_person is
+	'DEPRECATED (use dem.v_active_persons): This view denormalizes non-deleted persons with their active name.';
+
+
+revoke all on dem.v_basic_person from public;
+grant select on dem.v_basic_person to group "gm-public";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-dem-v_basic_person.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-dem-v_pat_addresses.sql b/server/sql/v20-v21/dynamic/v21-dem-v_pat_addresses.sql
new file mode 100644
index 0000000..b84d6b6
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-dem-v_pat_addresses.sql
@@ -0,0 +1,76 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: Karsten Hilbert
+-- 
+-- ==============================================================
+\set ON_ERROR_STOP 1
+
+-- --------------------------------------------------------------
+drop view if exists dem.v_pat_adresses cascade;
+
+
+create or replace view dem.v_pat_addresses as
+select
+	d_vp.pk_identity,
+	d_va.pk_address,
+	d_at.name as address_type,
+	_(d_at.name) as l10n_address_type,
+
+	d_vp.title,
+	d_vp.firstnames,
+	d_vp.lastnames,
+	d_vp.dob,
+	d_vp.gender,
+	d_vp.l10n_gender,
+	d_vp.preferred,
+
+	d_va.street,
+	d_va.postcode,
+	d_va.notes_street,
+	d_va.number,
+	d_va.subunit,
+	d_va.notes_subunit,
+	d_va.lat_lon_address,
+	d_va.postcode_street,
+	d_va.lat_lon_street,
+	d_va.suburb,
+	d_va.urb,
+	d_va.postcode_urb,
+	d_va.lat_lon_urb,
+	d_va.code_region,
+	d_va.region,
+	d_va.l10n_region,
+	d_va.code_country,
+	d_va.country,
+	d_va.l10n_country,
+	d_va.country_deprecated,
+	d_va.pk_street,
+	d_va.pk_urb,
+	d_va.pk_region,
+
+	d_lpoa.id as pk_lnk_person_org_address,
+	d_lpoa.id_type as pk_address_type,
+
+	d_lpoa.xmin as xmin_lnk_person_org_address
+from
+	dem.v_address d_va,
+	dem.lnk_person_org_address d_lpoa,
+	dem.v_all_persons d_vp,
+	dem.address_type d_at
+where
+	d_lpoa.id_identity = d_vp.pk_identity and
+	d_lpoa.id_address = d_va.pk_address and
+	d_lpoa.id_type = d_at.id
+;
+
+
+comment on view dem.v_pat_addresses is 'denormalized addresses per person';
+
+
+revoke all on dem.v_pat_addresses from public;
+grant select on dem.v_pat_addresses to group "gm-doctors";
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-dem-v_pat_addresses.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-gm-db-translations-de_DE.sql b/server/sql/v20-v21/dynamic/v21-gm-db-translations-de_DE.sql
new file mode 100644
index 0000000..02343d2
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-gm-db-translations-de_DE.sql
@@ -0,0 +1,434 @@
+-- GNUmed database string translations exported 2015-10-25 17:23
+-- - contains translations for each of [nl_NL, de, ru, ru_RU, es_ES, fr_CA, fr, pap_AN, fr_FR, de_DE]
+-- - user database language is set to [de_DE]
+
+-- Please email this file to <gnumed-devel at gnu.org>.
+-- ----------------------------------------------------------------------------------------------
+\set ON_ERROR_STOP
+
+--set default_transaction_read_only to off;
+--set client_encoding to 'utf-8';
+
+-- ----------------------------------------------------------------------------------------------
+select i18n.upd_tx(E'de', E'active', E'aktiv');
+select i18n.upd_tx(E'de', E'Administrative', E'Administrativ');
+select i18n.upd_tx(E'de', E'adopted daughter', E'Adoptivtochter');
+select i18n.upd_tx(E'de', E'adopted son', E'Adoptivsohn');
+select i18n.upd_tx(E'de', E'adoptive father', E'Adoptivvater');
+select i18n.upd_tx(E'de', E'adoptive mother', E'Adoptivmutter');
+select i18n.upd_tx(E'de', E'AOE', E'BE');
+select i18n.upd_tx(E'de', E'aunt', E'Tante');
+select i18n.upd_tx(E'de', E'aunt (maternal)', E'Tante (mütterlicherseits)');
+select i18n.upd_tx(E'de', E'aunt (paternal)', E'Tante (väterlicherseits)');
+select i18n.upd_tx(E'de', E'bill receiver', E'Rechnungsempfänger');
+select i18n.upd_tx(E'de', E'billing', E'Rechnungsanschrift');
+select i18n.upd_tx(E'de', E'Blood, Blood forming organs, Immune mechanism', E'Blut, blutbildende Organe, Immunsystem');
+select i18n.upd_tx(E'de', E'branch', E'Zweigstelle');
+select i18n.upd_tx(E'de', E'brother', E'Bruder');
+select i18n.upd_tx(E'de', E'Cardivascular', E'Kreislauf');
+select i18n.upd_tx(E'de', E'cause of death', E'Todesursache');
+select i18n.upd_tx(E'de', E'choleric', E'cholerisch');
+select i18n.upd_tx(E'de', E'clinically not relevant', E'medizinisch nicht relevant');
+select i18n.upd_tx(E'de', E'clinically relevant', E'medizinisch relevant');
+select i18n.upd_tx(E'de', E'closed', E'abgeschlossen');
+select i18n.upd_tx(E'de', E'confidential', E'vertraulich');
+select i18n.upd_tx(E'de', E'cousin', E'Cousin(e)');
+select i18n.upd_tx(E'de', E'cousin (maternal)', E'Cousin(e) (mütterlicherseits)');
+select i18n.upd_tx(E'de', E'cousin (paternal)', E'Cousin(e) (väterlicherseits)');
+select i18n.upd_tx(E'de', E'daughter', E'Tochter');
+select i18n.upd_tx(E'de', E'defacto husband', E'de facto Ehemann');
+select i18n.upd_tx(E'de', E'defacto wife', E'de facto Ehefrau');
+select i18n.upd_tx(E'de', E'Deletion of', E'Löschung:');
+select i18n.upd_tx(E'de', E'Diagnosis, disease', E'Diagnosen, Krankheiten');
+select i18n.upd_tx(E'de', E'Diagnostic screening, prevention', E'Diagnostik, Screening, Prävention');
+select i18n.upd_tx(E'de', E'Digestive', E'Darm: Verdauungssystem');
+select i18n.upd_tx(E'de', E'Ear ("Hearing")', E'Hören: Ohr');
+select i18n.upd_tx(E'de', E'Encounter', E'Kontakt');
+select i18n.upd_tx(E'de', E'Endocrine/Metabolic and Nutritional ("Thyroid")', E'Thyroidea: Endokrin, metabolisch, Ernährung');
+select i18n.upd_tx(E'de', E'Extra care !', E'Vorsicht');
+select i18n.upd_tx(E'de', E'Eye ("Focal")', E'Fokus: Auge');
+select i18n.upd_tx(E'de', E'father', E'Vater');
+select i18n.upd_tx(E'de', E'Female genital ("X-chromosome")', E'X-Chromosom: Weibliches Genitale, Brust');
+select i18n.upd_tx(E'de', E'form header', E'Formularkopf');
+select i18n.upd_tx(E'de', E'General and Unspecified', E'Allgmein und unspezifisch');
+select i18n.upd_tx(E'de', E'General Family History', E'Familienanamnese');
+select i18n.upd_tx(E'de', E'General History (maternal)', E'Familienananmese (mütterlicherseits)');
+select i18n.upd_tx(E'de', E'General History (paternal)', E'Familienananmese (väterlicherseits)');
+select i18n.upd_tx(E'de', E'generic praxis', E'generische Praxis');
+select i18n.upd_tx(E'de', E'generic praxis branch', E'generische Zweigstelle');
+select i18n.upd_tx(E'de', E'Government Agency', E'Regierungsabteilung');
+select i18n.upd_tx(E'de', E'granddaughter', E'Enkelin');
+select i18n.upd_tx(E'de', E'grandfather', E'Großvater');
+select i18n.upd_tx(E'de', E'grandfather (maternal)', E'Großvater (mütterlicherseits)');
+select i18n.upd_tx(E'de', E'grandfather (paternal)', E'Großvater (väterlicherseits)');
+select i18n.upd_tx(E'de', E'grandmother', E'Großmutter');
+select i18n.upd_tx(E'de', E'grandmother (maternal)', E'Großmutter (mütterlicherseits)');
+select i18n.upd_tx(E'de', E'grandmother (paternal)', E'Großmutter (väterlicherseits)');
+select i18n.upd_tx(E'de', E'grandson', E'Enkel');
+select i18n.upd_tx(E'de', E'great grandfather (maternal)', E'Urgroßvater (mütterlicherseits)');
+select i18n.upd_tx(E'de', E'great grandfather (paternal)', E'Urgroßvater (väterlicherseits)');
+select i18n.upd_tx(E'de', E'great grandmother (maternal)', E'Urgroßmutter (mütterlicherseits)');
+select i18n.upd_tx(E'de', E'great grandmother (paternal)', E'Urgroßmutter (väterlicherseits)');
+select i18n.upd_tx(E'de', E'Health Issue', E'Grunderkrankung');
+select i18n.upd_tx(E'de', E'Hospital', E'Krankenhaus');
+select i18n.upd_tx(E'de', E'husband', E'Ehemann');
+select i18n.upd_tx(E'de', E'inactive', E'inaktiv');
+select i18n.upd_tx(E'de', E'influenza (H3N2)', E'Influenza (H3N2)');
+select i18n.upd_tx(E'de', E'influenza (seasonal)', E'Influenza (sais.)');
+select i18n.upd_tx(E'de', E'invoice', E'Rechnungsbeleg');
+select i18n.upd_tx(E'de', E'Laboratory', E'Labor');
+select i18n.upd_tx(E'de', E'Laterality', E'Seite');
+select i18n.upd_tx(E'de', E'major depression', E'Depression');
+select i18n.upd_tx(E'de', E'Male genital ("Y-chromosome")', E'Y-Chromosom: Männliches Genitale, Brust');
+select i18n.upd_tx(E'de', E'Medical Practice', E'Praxis');
+select i18n.upd_tx(E'de', E'Medication history', E'Medikamentenanamnese');
+select i18n.upd_tx(E'de', E'meningococcus A', E'Meningokokken Typ A');
+select i18n.upd_tx(E'de', E'meningococcus W', E'Meningokokken Typ W');
+select i18n.upd_tx(E'de', E'meningococcus Y', E'Meningokokken Typ Y');
+select i18n.upd_tx(E'de', E'Ministry of Public Health', E'Gesundheitsministerium');
+select i18n.upd_tx(E'de', E'minor depression', E'depressoid');
+select i18n.upd_tx(E'de', E'mobility impairment', E'Gehbehinderung');
+select i18n.upd_tx(E'de', E'mother', E'Mutter');
+select i18n.upd_tx(E'de', E'Musculoskeletal ("Locomotion")', E'Laufen: Bewegungsapparat');
+select i18n.upd_tx(E'de', E'nephew', E'Neffe');
+select i18n.upd_tx(E'de', E'Neurological', E'Neurologisch');
+select i18n.upd_tx(E'de', E'niece', E'Nichte');
+select i18n.upd_tx(E'de', E'noted at age', E'aufgefallen im Alter von');
+select i18n.upd_tx(E'de', E'Occupational Therapy Practice', E'Ergotherapiepraxis');
+select i18n.upd_tx(E'de', E'of', E'von');
+select i18n.upd_tx(E'de', E'often late', E'oft zu spät');
+select i18n.upd_tx(E'de', E'ongoing', E'andauernd');
+select i18n.upd_tx(E'de', E'open', E'andauernd');
+select i18n.upd_tx(E'de', E'Other (referral etc)', E'Anderes');
+select i18n.upd_tx(E'de', E'other form', E'sonstiges Formular');
+select i18n.upd_tx(E'de', E'phone w/ caregiver', E'Telefonat mit Pflegeperson');
+select i18n.upd_tx(E'de', E'phone w/ patient', E'Telefonat mit Patient');
+select i18n.upd_tx(E'de', E'phone w/ provider', E'Telefonat mit Arzt/Behandler');
+select i18n.upd_tx(E'de', E'Physical Therapy Practice', E'Physiotherapiepraxis');
+select i18n.upd_tx(E'de', E'Practice', E'Praxis');
+select i18n.upd_tx(E'de', E'Pregnancy, Childbearing, Family planning ("Women")', E'Weiblich: Schwangerschaft, Geburt, Familienplanung');
+select i18n.upd_tx(E'de', E'prescription', E'Rezept');
+select i18n.upd_tx(E'de', E'Privacy notice', E'Datenschutzhinweis');
+select i18n.upd_tx(E'de', E'Procedure', E'Maßnahme');
+select i18n.upd_tx(E'de', E'Psychological', E'Psychologisch');
+select i18n.upd_tx(E'de', E'Respiratory', E'Respiratorisch: Atmungsorgane');
+select i18n.upd_tx(E'de', E'RFE', E'BU');
+select i18n.upd_tx(E'de', E'salmonella typhi (typhoid)', E'Salmonella typhi (Typhus)');
+select i18n.upd_tx(E'de', E'Serbia', E'Serbien');
+select i18n.upd_tx(E'de', E'sister', E'Schwester');
+select i18n.upd_tx(E'de', E'Skin', E'Skin: Haut');
+select i18n.upd_tx(E'de', E'smokes', E'raucht');
+select i18n.upd_tx(E'de', E'Social problems', E'SoZiale Probleme');
+select i18n.upd_tx(E'de', E'son', E'Sohn');
+select i18n.upd_tx(E'de', E'step daughter', E'Stieftochter');
+select i18n.upd_tx(E'de', E'step father', E'Stiefvater');
+select i18n.upd_tx(E'de', E'step mother', E'Stiefmutter');
+select i18n.upd_tx(E'de', E'step son', E'Stiefsohn');
+select i18n.upd_tx(E'de', E'stepbrother', E'Stiefbruder');
+select i18n.upd_tx(E'de', E'stepnephew', E'Stiefneffe');
+select i18n.upd_tx(E'de', E'stepniece', E'Stiefnichte');
+select i18n.upd_tx(E'de', E'stepsister', E'Stiefschwester');
+select i18n.upd_tx(E'de', E'Summary', E'Zusammenfassung');
+select i18n.upd_tx(E'de', E'Surgery', E'Praxis');
+select i18n.upd_tx(E'de', E'Symptoms, complaints', E'Symptome, Beschwerden');
+select i18n.upd_tx(E'de', E'Synopsis', E'Synopse');
+select i18n.upd_tx(E'de', E'Test results', E'Testresultate');
+select i18n.upd_tx(E'de', E'Treatment, procedures, medication', E'Behandlung, Prozeduren, Medikation');
+select i18n.upd_tx(E'de', E'tuberculosis', E'Tuberkulose');
+select i18n.upd_tx(E'de', E'uncle', E'Onkel');
+select i18n.upd_tx(E'de', E'uncle (maternal)', E'Onkel (mütterlicherseits)');
+select i18n.upd_tx(E'de', E'uncle (paternal)', E'Onkel (väterlicherseits)');
+select i18n.upd_tx(E'de', E'until', E'bis');
+select i18n.upd_tx(E'de', E'Urological', E'Urologisch');
+select i18n.upd_tx(E'de', E'Ward', E'Station');
+select i18n.upd_tx(E'de', E'wife', E'Ehefrau');
+select i18n.upd_tx(E'de_DE', E'\'closed\'', E'\'geschlossen\'');
+select i18n.upd_tx(E'de_DE', E' (closed)', E' (beendet)');
+select i18n.upd_tx(E'de_DE', E'administrative', E'Verwaltung');
+select i18n.upd_tx(E'de_DE', E'administrative encounter', E'Verwaltungsakt');
+select i18n.upd_tx(E'de_DE', E'Albania', E'Albanien');
+select i18n.upd_tx(E'de_DE', E'Algeria', E'Algerien');
+select i18n.upd_tx(E'de_DE', E'allergene', E'Allergen');
+select i18n.upd_tx(E'de_DE', E'allergy', E'Allergie');
+select i18n.upd_tx(E'de_DE', E'Allergy state', E'Allergiestatus');
+select i18n.upd_tx(E'de_DE', E'American Samoa', E'Amerikanisch-Samoa');
+select i18n.upd_tx(E'de_DE', E'Antarctica', E'Antarktis');
+select i18n.upd_tx(E'de_DE', E'Antigua and Barbuda', E'Antigua und Barbados');
+select i18n.upd_tx(E'de_DE', E'Argentina', E'Argentinien');
+select i18n.upd_tx(E'de_DE', E'Armenia', E'Armenien');
+select i18n.upd_tx(E'de_DE', E'ATC code', E'ATC-Code');
+select i18n.upd_tx(E'de_DE', E'Australia', E'Australien');
+select i18n.upd_tx(E'de_DE', E'Austria', E'Österreich');
+select i18n.upd_tx(E'de_DE', E'batch no', E'Charge');
+select i18n.upd_tx(E'de_DE', E'Belgium', E'Belgien');
+select i18n.upd_tx(E'de_DE', E'blood oxygen saturation', E'Sauerstoffsättigung (Blut)');
+select i18n.upd_tx(E'de_DE', E'blood pressure', E'Blutdruck');
+select i18n.upd_tx(E'de_DE', E'Bolivia', E'Bolivien');
+select i18n.upd_tx(E'de_DE', E'Bosnia and Herzegovina', E'Bosnien und Herzegovina');
+select i18n.upd_tx(E'de_DE', E'Brazil', E'Brasilien');
+select i18n.upd_tx(E'de_DE', E'Bulgaria', E'Bulgarien');
+select i18n.upd_tx(E'de_DE', E'Cambodia', E'Kambodscha');
+select i18n.upd_tx(E'de_DE', E'Cameroon', E'Kamerun');
+select i18n.upd_tx(E'de_DE', E'Canada', E'Kanada');
+select i18n.upd_tx(E'de_DE', E'Central African Republic', E'Zentralafrikanische Republik');
+select i18n.upd_tx(E'de_DE', E'Chad', E'Tschad');
+select i18n.upd_tx(E'de_DE', E'chart review', E'Akteneinsicht');
+select i18n.upd_tx(E'de_DE', E'child', E'Kind');
+select i18n.upd_tx(E'de_DE', E'cholera', E'Cholera');
+select i18n.upd_tx(E'de_DE', E'Christmas Island', E'Weihnachtsinseln');
+select i18n.upd_tx(E'de_DE', E'clinical', E'medizinisch');
+select i18n.upd_tx(E'de_DE', E'code', E'Code');
+select i18n.upd_tx(E'de_DE', E'Colombia', E'Kolumbien');
+select i18n.upd_tx(E'de_DE', E'Comment', E'Kommentar');
+select i18n.upd_tx(E'de_DE', E'Comoros', E'Komoren');
+select i18n.upd_tx(E'de_DE', E'Congo', E'Kongo');
+select i18n.upd_tx(E'de_DE', E'Congo, The Democratic Republic', E'Demokratische Republik Kongo');
+select i18n.upd_tx(E'de_DE', E'Cote D\'Ivoire', E'Elfenbeinküste');
+select i18n.upd_tx(E'de_DE', E'Croatia', E'Kroatien');
+select i18n.upd_tx(E'de_DE', E'Cuba', E'Kuba');
+select i18n.upd_tx(E'de_DE', E'current medication list', E'Medikamentenliste');
+select i18n.upd_tx(E'de_DE', E'Cyprus', E'Zypern');
+select i18n.upd_tx(E'de_DE', E'Czech Republic', E'Tschechien');
+select i18n.upd_tx(E'de_DE', E'Deletion of document', E'Dokument gelöscht');
+select i18n.upd_tx(E'de_DE', E'Denmark', E'Dänemark');
+select i18n.upd_tx(E'de_DE', E'diet', E'Ernährung');
+select i18n.upd_tx(E'de_DE', E'diphtheria', E'Diphtherie');
+select i18n.upd_tx(E'de_DE', E'discharge summary ENT', E'Entlassung HNO');
+select i18n.upd_tx(E'de_DE', E'discharge summary internal', E'Entlassung Interne');
+select i18n.upd_tx(E'de_DE', E'discharge summary neurological', E'Entlassung Neuro');
+select i18n.upd_tx(E'de_DE', E'discharge summary neurosurgery', E'Entlassung Neurochirurgie');
+select i18n.upd_tx(E'de_DE', E'discharge summary ophthalmology', E'Entlassung Augen');
+select i18n.upd_tx(E'de_DE', E'discharge summary orthopaedic', E'Entlassung Ortho');
+select i18n.upd_tx(E'de_DE', E'discharge summary other', E'Entlassung sonstige');
+select i18n.upd_tx(E'de_DE', E'discharge summary psychiatric', E'Entlassung Psychiatrie');
+select i18n.upd_tx(E'de_DE', E'discharge summary rehabilitation', E'Entlassung Reha');
+select i18n.upd_tx(E'de_DE', E'discharge summary surgical', E'Entlassung Chirurgie');
+select i18n.upd_tx(E'de_DE', E'discharge summary urology', E'Entlassung Uro');
+select i18n.upd_tx(E'de_DE', E'divorced', E'geschieden');
+select i18n.upd_tx(E'de_DE', E'doctor', E'Arzt');
+select i18n.upd_tx(E'de_DE', E'document entry', E'Dokumenteneingang');
+select i18n.upd_tx(E'de_DE', E'does have allergies', E'Allergien vorhanden');
+select i18n.upd_tx(E'de_DE', E'Dominican Republic', E'Dominikanische Republik');
+select i18n.upd_tx(E'de_DE', E'East Timor', E'Osttimor');
+select i18n.upd_tx(E'de_DE', E'Ecuador', E'Ekuador');
+select i18n.upd_tx(E'de_DE', E'Egypt', E'Ägypten');
+select i18n.upd_tx(E'de_DE', E'email', E'e-mail');
+select i18n.upd_tx(E'de_DE', E'emergency encounter', E'Notfall');
+select i18n.upd_tx(E'de_DE', E'EMR printout', E'Karteiausdruck');
+select i18n.upd_tx(E'de_DE', E'encounter', E'APK');
+select i18n.upd_tx(E'de_DE', E'episode', E'Episode');
+select i18n.upd_tx(E'de_DE', E'Ethiopia', E'Äthiopien');
+select i18n.upd_tx(E'de_DE', E'external org', E'externe Organisation');
+select i18n.upd_tx(E'de_DE', E'f', E'w');
+select i18n.upd_tx(E'de_DE', E'family history', E'Familienanamnese');
+select i18n.upd_tx(E'de_DE', E'Family Hx', E'Familienanamnese');
+select i18n.upd_tx(E'de_DE', E'fax', E'Fax');
+select i18n.upd_tx(E'de_DE', E'fax consultation', E'per Fax');
+select i18n.upd_tx(E'de_DE', E'female', E'weiblich');
+select i18n.upd_tx(E'de_DE', E'female only', E'nur Frauen');
+select i18n.upd_tx(E'de_DE', E'final', E'endgültig');
+select i18n.upd_tx(E'de_DE', E'Finland', E'Finnland');
+select i18n.upd_tx(E'de_DE', E'France', E'Frankreich');
+select i18n.upd_tx(E'de_DE', E'FYI', E'zur Kenntnisnahme');
+select i18n.upd_tx(E'de_DE', E'generic', E'Generikum');
+select i18n.upd_tx(E'de_DE', E'Georgia', E'Georgien');
+select i18n.upd_tx(E'de_DE', E'Germany', E'Deutschland');
+select i18n.upd_tx(E'de_DE', E'gnuplot script', E'Gnuplot-Script');
+select i18n.upd_tx(E'de_DE', E'Greece', E'Griechenland');
+select i18n.upd_tx(E'de_DE', E'Greenland', E'Grönland');
+select i18n.upd_tx(E'de_DE', E'haemophilus influenzae b', E'Haemophilus Influenzae B');
+select i18n.upd_tx(E'de_DE', E'halfsibling', E'Stiefgeschwister');
+select i18n.upd_tx(E'de_DE', E'health issue', E'Grunderkrankung');
+select i18n.upd_tx(E'de_DE', E'height', E'Größe');
+select i18n.upd_tx(E'de_DE', E'hepatitis A', E'Hepatitis A');
+select i18n.upd_tx(E'de_DE', E'hepatitis B', E'Hepatitis B');
+select i18n.upd_tx(E'de_DE', E'hermaphrodite', E'Hermaphrodit');
+select i18n.upd_tx(E'de_DE', E'hght', E'Gr.');
+select i18n.upd_tx(E'de_DE', E'history of presenting complaint', E'Jetztanamnese');
+select i18n.upd_tx(E'de_DE', E'holidays', E'Urlaub');
+select i18n.upd_tx(E'de_DE', E'Holy See (Vatican City State)', E'Vatikanstadt');
+select i18n.upd_tx(E'de_DE', E'home', E'daheim');
+select i18n.upd_tx(E'de_DE', E'home visit', E'Hausbesuch');
+select i18n.upd_tx(E'de_DE', E'homephone', E'Telefon zu Hause');
+select i18n.upd_tx(E'de_DE', E'hospital stay', E'Krankenhausaufenthalt');
+select i18n.upd_tx(E'de_DE', E'hospital visit', E'Krankenhausbesuch');
+select i18n.upd_tx(E'de_DE', E'housing', E'Unterkunft');
+select i18n.upd_tx(E'de_DE', E'Hungary', E'Ungarn');
+select i18n.upd_tx(E'de_DE', E'Iceland', E'Island');
+select i18n.upd_tx(E'de_DE', E'in surgery', E'in Praxis');
+select i18n.upd_tx(E'de_DE', E'India', E'Indien');
+select i18n.upd_tx(E'de_DE', E'indication', E'Indikation');
+select i18n.upd_tx(E'de_DE', E'Indications', E'Indikationen');
+select i18n.upd_tx(E'de_DE', E'Indonesia', E'Indonesion');
+select i18n.upd_tx(E'de_DE', E'influenza', E'Influenza');
+select i18n.upd_tx(E'de_DE', E'intramuscular', E'intramuskulär');
+select i18n.upd_tx(E'de_DE', E'Iran, Islamic Republic Of', E'Islamische Republik Iran');
+select i18n.upd_tx(E'de_DE', E'Iraq', E'Irak');
+select i18n.upd_tx(E'de_DE', E'Ireland', E'Irland');
+select i18n.upd_tx(E'de_DE', E'Italy', E'Italien');
+select i18n.upd_tx(E'de_DE', E'jabber', E'Jabber');
+select i18n.upd_tx(E'de_DE', E'Jamaica', E'Jamaika');
+select i18n.upd_tx(E'de_DE', E'japanese B encephalitis', E'Japanische Enzephalitis B');
+select i18n.upd_tx(E'de_DE', E'Jordan', E'Jordanien');
+select i18n.upd_tx(E'de_DE', E'Kazakstan', E'Kasachstan');
+select i18n.upd_tx(E'de_DE', E'Kenya', E'Kenia');
+select i18n.upd_tx(E'de_DE', E'Korea, Democratic People\'s Republic', E'Nordkorea');
+select i18n.upd_tx(E'de_DE', E'Korea, Republic Of', E'Südkorea');
+select i18n.upd_tx(E'de_DE', E'Kyrgyzstan', E'Kirgisien');
+select i18n.upd_tx(E'de_DE', E'lab', E'Labor');
+select i18n.upd_tx(E'de_DE', E'lab technician', E'MTLA');
+select i18n.upd_tx(E'de_DE', E'Lao People\'s Democratic Republic', E'Laos');
+select i18n.upd_tx(E'de_DE', E'last confirmed', E'zuletzt überprüft');
+select i18n.upd_tx(E'de_DE', E'Lebanon', E'Libanon');
+select i18n.upd_tx(E'de_DE', E'legal guardian', E'Vormund');
+select i18n.upd_tx(E'de_DE', E'Lithuania', E'Litauen');
+select i18n.upd_tx(E'de_DE', E'lying in infants, else standing, see result notes', E'Säuglinge liegend, sonst stehend, siehe Kommentar');
+select i18n.upd_tx(E'de_DE', E'male', E'männlich');
+select i18n.upd_tx(E'de_DE', E'manager', E'Manager');
+select i18n.upd_tx(E'de_DE', E'married', E'verheiratet');
+select i18n.upd_tx(E'de_DE', E'Mauritania', E'Mauretanien');
+select i18n.upd_tx(E'de_DE', E'measles', E'Masern');
+select i18n.upd_tx(E'de_DE', E'Medical statement', E'Bescheinigung');
+select i18n.upd_tx(E'de_DE', E'medical student', E'Medizinstudent');
+select i18n.upd_tx(E'de_DE', E'memo', E'Memo');
+select i18n.upd_tx(E'de_DE', E'meningococcus C', E'Meningokokken Typ C');
+select i18n.upd_tx(E'de_DE', E'Mexico', E'Mexiko');
+select i18n.upd_tx(E'de_DE', E'mobile', E'Funktelefon');
+select i18n.upd_tx(E'de_DE', E'Mongolia', E'Mongolei');
+select i18n.upd_tx(E'de_DE', E'Morocco', E'Marokko');
+select i18n.upd_tx(E'de_DE', E'mumps', E'Mumps');
+select i18n.upd_tx(E'de_DE', E'name', E'Name');
+select i18n.upd_tx(E'de_DE', E'Netherlands', E'Niederlanden');
+select i18n.upd_tx(E'de_DE', E'Netherlands Antilles', E'Niederländische Antillen');
+select i18n.upd_tx(E'de_DE', E'New Zealand', E'Neuseeland');
+select i18n.upd_tx(E'de_DE', E'no known allergies', E'keine bekannten Allergie');
+select i18n.upd_tx(E'de_DE', E'Norway', E'Norwegen');
+select i18n.upd_tx(E'de_DE', E'noted at age', E'aufgefallen im Alter von');
+select i18n.upd_tx(E'de_DE', E'notes', E'Bemerkung');
+select i18n.upd_tx(E'de_DE', E'nurse', E'Arzthelferin');
+select i18n.upd_tx(E'de_DE', E'nursing home visit', E'Heimbesuch');
+select i18n.upd_tx(E'de_DE', E'orally', E'oral');
+select i18n.upd_tx(E'de_DE', E'other encounter', E'anderer Kontakt');
+select i18n.upd_tx(E'de_DE', E'other letter', E'sonstiger Brief');
+select i18n.upd_tx(E'de_DE', E'parent', E'Elternteil');
+select i18n.upd_tx(E'de_DE', E'parents', E'Eltern');
+select i18n.upd_tx(E'de_DE', E'partial', E'unvollständig');
+select i18n.upd_tx(E'de_DE', E'patient', E'Patient');
+select i18n.upd_tx(E'de_DE', E'patient photograph', E'Patientenphoto');
+select i18n.upd_tx(E'de_DE', E'pdf form', E'PDF-Formular');
+select i18n.upd_tx(E'de_DE', E'pending', E'ausstehend');
+select i18n.upd_tx(E'de_DE', E'peripheral arterial blood oxygenization level, transduced', E'peripher-arterielle Blutsauerstoffsättigung, transduziert');
+select i18n.upd_tx(E'de_DE', E'peripheral arterial pulse', E'peripher-arterieller Puls');
+select i18n.upd_tx(E'de_DE', E'personal', E'persönlich');
+select i18n.upd_tx(E'de_DE', E'pertussis', E'Pertussis');
+select i18n.upd_tx(E'de_DE', E'Philippines', E'Philippinen');
+select i18n.upd_tx(E'de_DE', E'phone consultation', E'Anruf');
+select i18n.upd_tx(E'de_DE', E'physical therapy report', E'Therapiebericht (PT)');
+select i18n.upd_tx(E'de_DE', E'pneumococcus', E'Pneumokokken');
+select i18n.upd_tx(E'de_DE', E'Poland', E'Polen');
+select i18n.upd_tx(E'de_DE', E'poliomyelitis', E'Poliomyelitis');
+select i18n.upd_tx(E'de_DE', E'preliminary', E'vorläufig');
+select i18n.upd_tx(E'de_DE', E'proxy encounter', E'indirekt');
+select i18n.upd_tx(E'de_DE', E'psycho-social history', E'Sozialanamnese');
+select i18n.upd_tx(E'de_DE', E'pulse', E'Puls');
+select i18n.upd_tx(E'de_DE', E'pulse, periph.art.', E'Puls, periph.art.');
+select i18n.upd_tx(E'de_DE', E'rabies', E'Tollwut');
+select i18n.upd_tx(E'de_DE', E'reaction', E'Reaktion');
+select i18n.upd_tx(E'de_DE', E'Reaction', E'Reaktion');
+select i18n.upd_tx(E'de_DE', E'referral letter', E'Überweisungsbrief');
+select i18n.upd_tx(E'de_DE', E'referral report cardiology', E'Arztbrief Kardio');
+select i18n.upd_tx(E'de_DE', E'referral report ENT', E'Arztbrief HNO');
+select i18n.upd_tx(E'de_DE', E'referral report eye', E'Arztbrief Augen');
+select i18n.upd_tx(E'de_DE', E'referral report internal', E'Arztbrief Innere');
+select i18n.upd_tx(E'de_DE', E'referral report neuro', E'Arztbrief Neuro');
+select i18n.upd_tx(E'de_DE', E'referral report neurosurgery', E'Arztbrief Neurochirurgie');
+select i18n.upd_tx(E'de_DE', E'referral report oncology', E'Arztbrief Onkologie');
+select i18n.upd_tx(E'de_DE', E'referral report orthopaedic', E'Arztbrief Ortho');
+select i18n.upd_tx(E'de_DE', E'referral report other', E'sonstiger Arztbrief');
+select i18n.upd_tx(E'de_DE', E'referral report pathology', E'Arztbrief Patho');
+select i18n.upd_tx(E'de_DE', E'referral report psychotherapy', E'Arztbrief Psychotherapie');
+select i18n.upd_tx(E'de_DE', E'referral report radiology', E'Arztbrief Röntgen');
+select i18n.upd_tx(E'de_DE', E'referral report surgical', E'Arztbrief Chirurgie');
+select i18n.upd_tx(E'de_DE', E'referral report urology', E'Arztbrief Uro');
+select i18n.upd_tx(E'de_DE', E'repeat script', E'Wiederholungsrezept');
+select i18n.upd_tx(E'de_DE', E'results review change', E'Ergebnisbewertung geändert');
+select i18n.upd_tx(E'de_DE', E'results review changed for patient', E'Bewertung von Testergebnissen änderte sich beim Patienten');
+select i18n.upd_tx(E'de_DE', E'review docs', E'Dokumente durchsehen');
+select i18n.upd_tx(E'de_DE', E'review lab', E'Labor durchsehen');
+select i18n.upd_tx(E'de_DE', E'review results', E'Tests durchsehen');
+select i18n.upd_tx(E'de_DE', E'review vaccs', E'Impfungen überprüfen');
+select i18n.upd_tx(E'de_DE', E'RFE', E'BA');
+select i18n.upd_tx(E'de_DE', E'Romania', E'Rumänien');
+select i18n.upd_tx(E'de_DE', E'rubella', E'Röteln');
+select i18n.upd_tx(E'de_DE', E'Russian Federation', E'Russische Föderation');
+select i18n.upd_tx(E'de_DE', E'sample ID', E'Probennummer');
+select i18n.upd_tx(E'de_DE', E'sample taken', E'Probe genommen');
+select i18n.upd_tx(E'de_DE', E'Saudi Arabia', E'Saudi Arabien');
+select i18n.upd_tx(E'de_DE', E'seasonal', E'saisonal');
+select i18n.upd_tx(E'de_DE', E'secretary', E'Sekretärin');
+select i18n.upd_tx(E'de_DE', E'sensitivity', E'Unverträglichkeit');
+select i18n.upd_tx(E'de_DE', E'separated', E'getrennt');
+select i18n.upd_tx(E'de_DE', E'sexual history', E'Sexualanamnese');
+select i18n.upd_tx(E'de_DE', E'Seychelles', E'Seychellen');
+select i18n.upd_tx(E'de_DE', E'sibling', E'Geschwister');
+select i18n.upd_tx(E'de_DE', E'Singapore', E'Singapur');
+select i18n.upd_tx(E'de_DE', E'site', E'Ort');
+select i18n.upd_tx(E'de_DE', E'Slovakia', E'Slowakei');
+select i18n.upd_tx(E'de_DE', E'Slovenia', E'Slowenien');
+select i18n.upd_tx(E'de_DE', E'South Africa', E'Südafrika');
+select i18n.upd_tx(E'de_DE', E'Spain', E'Spanien');
+select i18n.upd_tx(E'de_DE', E'specifics attached to result record', E'Einzelheiten im Karteieintrag');
+select i18n.upd_tx(E'de_DE', E'state/territory/province/region not available', E'Bundesland/Provinz/Region nicht verfügbar');
+select i18n.upd_tx(E'de_DE', E'status', E'Status');
+select i18n.upd_tx(E'de_DE', E'stepchild', E'Stiefkind');
+select i18n.upd_tx(E'de_DE', E'stepparent', E'Stiefelter');
+select i18n.upd_tx(E'de_DE', E'student nurse', E'Schwesternschüler/-in');
+select i18n.upd_tx(E'de_DE', E'subcutaneous', E'subkutan');
+select i18n.upd_tx(E'de_DE', E'substance', E'Substanz');
+select i18n.upd_tx(E'de_DE', E'Summary', E'Zusammenfassung');
+select i18n.upd_tx(E'de_DE', E'Sweden', E'Schweden');
+select i18n.upd_tx(E'de_DE', E'Switzerland', E'Schweiz');
+select i18n.upd_tx(E'de_DE', E'Syrian Arab Republic', E'Syrien');
+select i18n.upd_tx(E'de_DE', E'Taiwan, Province Of China', E'Taiwan');
+select i18n.upd_tx(E'de_DE', E'temporary', E'zeitweilig');
+select i18n.upd_tx(E'de_DE', E'tetanus', E'Tetanus');
+select i18n.upd_tx(E'de_DE', E'the patient\'s weight (body mass to be accurate)', E'Patientengewicht (Körpermasse, genaugenommen)');
+select i18n.upd_tx(E'de_DE', E'tick-borne meningoencephalitis', E'FSME');
+select i18n.upd_tx(E'de_DE', E'trainee - lab', E'MTLA (Azubi)');
+select i18n.upd_tx(E'de_DE', E'trainee - X-ray', E'MTRA (Azubi)');
+select i18n.upd_tx(E'de_DE', E'transsexual phenotype female', E'transsexuell, weiblicher Phänotyp');
+select i18n.upd_tx(E'de_DE', E'transsexual phenotype male', E'transsexuell, männlicher Phänotyp');
+select i18n.upd_tx(E'de_DE', E'Tunisia', E'Tunesien');
+select i18n.upd_tx(E'de_DE', E'Turkey', E'Türkei');
+select i18n.upd_tx(E'de_DE', E'Two vaccinations with overlapping target conditions recorded within one week of each other !', E'Zwei Impfungen innerhalb einer Woche haben überlappende Indikationen !');
+select i18n.upd_tx(E'de_DE', E'type', E'Typ');
+select i18n.upd_tx(E'de_DE', E'United Arab Emirates', E'Vereinigte Arabische Emirate');
+select i18n.upd_tx(E'de_DE', E'United Kingdom', E'Großbritannien');
+select i18n.upd_tx(E'de_DE', E'United States', E'Vereinigte Staaten von Amerika');
+select i18n.upd_tx(E'de_DE', E'unknown', E'unbekannt');
+select i18n.upd_tx(E'de_DE', E'unknown, unasked', E'unbekannt, nicht erfragt');
+select i18n.upd_tx(E'de_DE', E'unreviewed (abnormal) results for patient', E'neue (pathologische) Testergebnisse beim Patienten');
+select i18n.upd_tx(E'de_DE', E'unreviewed (normal) results for patient', E'neue (normale) Testergebnisse beim Patienten');
+select i18n.upd_tx(E'de_DE', E'unreviewed documents for patient', E'neue Dokumente für Patient');
+select i18n.upd_tx(E'de_DE', E'unreviewed results for patient', E'neue Testergebnisse beim Patienten');
+select i18n.upd_tx(E'de_DE', E'Vaccination', E'Impfung');
+select i18n.upd_tx(E'de_DE', E'vaccination record', E'Impfnachweis');
+select i18n.upd_tx(E'de_DE', E'vaccine', E'Impfstoff');
+select i18n.upd_tx(E'de_DE', E'value', E'Wert');
+select i18n.upd_tx(E'de_DE', E'varicella', E'Varizellen');
+select i18n.upd_tx(E'de_DE', E'video conference', E'per Video');
+select i18n.upd_tx(E'de_DE', E'visual progress note', E'Bildnotiz');
+select i18n.upd_tx(E'de_DE', E'ward', E'Betreuer');
+select i18n.upd_tx(E'de_DE', E'web', E'WWW');
+select i18n.upd_tx(E'de_DE', E'weight (body mass)', E'Gewicht (Masse)');
+select i18n.upd_tx(E'de_DE', E'wght', E'KG');
+select i18n.upd_tx(E'de_DE', E'widowed', E'verwitwet');
+select i18n.upd_tx(E'de_DE', E'work', E'Arbeit');
+select i18n.upd_tx(E'de_DE', E'workphone', E'Telefon auf Arbeit');
+select i18n.upd_tx(E'de_DE', E'X-ray assistant', E'MTRA');
+select i18n.upd_tx(E'de_DE', E'yellow fever', E'Gelbfieber');
+select i18n.upd_tx(E'de_DE', E'your own practice', E'eigene Praxis');
+select i18n.upd_tx(E'es_ES', E'Spain', E'España');
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-gm-db-translations-de_DE.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-gm-md5.sql b/server/sql/v20-v21/dynamic/v21-gm-md5.sql
new file mode 100644
index 0000000..ab78a3a
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-gm-md5.sql
@@ -0,0 +1,57 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+create or replace function gm.lo_chunked_md5(oid, int)
+	returns text
+	language 'plpgsql'
+	stable strict
+	as '
+DECLARE
+	lo_id alias for $1;
+	chunk_size alias for $2;
+	_lo_fd integer;
+	_lo_size integer;
+	_chunk_count integer;
+	_remainder integer;
+	_md5_concat text;
+	INV_READ constant integer := x''40000''::integer;
+	SEEK_SET constant integer := 0;
+	SEEK_END constant integer := 2;
+BEGIN
+	-- check for existence of lo_id ?
+
+	_lo_fd := lo_open(lo_id, INV_READ);
+	-- get size
+	_lo_size := lo_lseek(_lo_fd, 0, SEEK_END);
+	PERFORM lo_close(_lo_fd);						-- move further down if loread() proves faster
+
+	-- calculate chunks and remainder
+	_chunk_count := _lo_size / chunk_size;
+	_remainder := _lo_size % chunk_size;
+
+	-- loop over chunks
+	_md5_concat := '''';
+	FOR _chunk_id in 1.._chunk_count LOOP
+		_md5_concat := _md5_concat || md5(lo_get(lo_id, (_chunk_id - 1) * chunk_size, chunk_size));
+		-- using loread() may be faster (as it directly accesses the
+		-- existing lo_fd and thusly does not need to re-open the LO
+		-- each round)
+	END LOOP;
+	-- add remainder
+	_md5_concat := _md5_concat || md5(lo_get(lo_id, _chunk_count * chunk_size, _remainder));
+
+	return md5(_md5_concat);
+END;';
+
+comment on function gm.lo_chunked_md5(oid, int) is 'Function to create a chunked md5 sum on arbitrarily large LARGE OBJECTs.';
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-gm-md5.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-ref-paperwork_templates.sql b/server/sql/v20-v21/dynamic/v21-ref-paperwork_templates.sql
new file mode 100644
index 0000000..641c4df
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-ref-paperwork_templates.sql
@@ -0,0 +1,138 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+-- ref.v_paperwork_templates
+drop view if exists ref.v_paperwork_templates cascade;
+
+
+create view ref.v_paperwork_templates as
+select
+	r_pt.pk
+		as pk_paperwork_template,
+	r_pt.name_short,
+	r_pt.name_long,
+	r_pt.external_version,
+	r_pt.gnumed_revision,
+	(select r_ft.name from ref.form_types r_ft where r_ft.pk = r_pt.fk_template_type)
+		as template_type,
+	(select _(r_ft.name) from ref.form_types r_ft where r_ft.pk = r_pt.fk_template_type)
+		as l10n_template_type,
+	coalesce(r_pt.instance_type, (select r_ft.name from ref.form_types r_ft where r_ft.pk = r_pt.fk_template_type))
+		as instance_type,
+	coalesce(_(r_pt.instance_type), (select _(r_ft.name) from ref.form_types r_ft where r_ft.pk = r_pt.fk_template_type))
+		as l10n_instance_type,
+	r_pt.engine,
+	r_pt.in_use,
+	r_pt.edit_after_substitution,
+	r_pt.filename,
+	case
+		when r_pt.data is not NULL then True
+		else False
+	end
+		as has_template_data,
+--	(select exists(select 1 from public.form_fields where fk_form = r_pt.pk limit 1))
+--		as has_instances,
+	r_pt.modified_when
+		as last_modified,
+	coalesce (
+		(select d_s.short_alias from dem.staff d_s where d_s.db_user = r_pt.modified_by),
+		'<' || r_pt.modified_by || '>'
+	) as modified_by,
+	r_pt.fk_template_type
+		as pk_template_type,
+	r_pt.xmin
+		as xmin_paperwork_template
+from
+	ref.paperwork_templates r_pt
+;
+
+
+grant select on
+	ref.v_paperwork_templates
+to group "gm-doctors";
+
+-- --------------------------------------------------------------
+delete from ref.paperwork_templates where name_long = 'Medikationsplan (Deutschland, AMTS)';
+
+insert into ref.paperwork_templates (
+	fk_template_type,
+	instance_type,
+	name_short,
+	name_long,
+	external_version,
+	engine,
+	filename,
+	edit_after_substitution,
+	data
+) values (
+	(select pk from ref.form_types where name = 'current medication list'),
+	'current medication list',
+	'MedPlan AMTS (D)',
+	'Medikationsplan (Deutschland, AMTS)',
+	'DE-DE-Version 2.0 vom 15.12.2014',
+	'L',
+	'amts-med-plan.tex',
+	false,
+	'real template missing'::bytea
+);
+
+-- --------------------------------------------------------------
+delete from ref.paperwork_templates where name_long = 'Medikationsplan (Deutschland, NICHT konform zu AMTS)';
+
+insert into ref.paperwork_templates (
+	fk_template_type,
+	instance_type,
+	name_short,
+	name_long,
+	external_version,
+	engine,
+	filename,
+	edit_after_substitution,
+	data
+) values (
+	(select pk from ref.form_types where name = 'current medication list'),
+	'current medication list',
+	'MedPlan (D, ähnlich AMTS)',
+	'Medikationsplan (Deutschland, NICHT konform zu AMTS)',
+	'v21.0 (nicht konform zu DE-DE-Version 2.0 vom 15.12.2014)',
+	'L',
+	'not-amts-med-plan.tex',
+	false,
+	'real template missing'::bytea
+);
+
+-- --------------------------------------------------------------
+delete from ref.paperwork_templates where name_long = 'Liste aktueller Medikamente (GNUmed)';
+
+insert into ref.paperwork_templates (
+	fk_template_type,
+	instance_type,
+	name_short,
+	name_long,
+	external_version,
+	engine,
+	filename,
+	edit_after_substitution,
+	data
+) values (
+	(select pk from ref.form_types where name = 'current medication list'),
+	'current medication list',
+	'Med.Liste (GMd)',
+	'Liste aktueller Medikamente (GNUmed)',
+	'21.0',
+	'L',
+	'akt-med-liste.tex',
+	false,
+	'real template missing'::bytea
+);
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-ref-paperwork_templates.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-ref-v_auto_hints.sql b/server/sql/v20-v21/dynamic/v21-ref-v_auto_hints.sql
new file mode 100644
index 0000000..31eaebb
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-ref-v_auto_hints.sql
@@ -0,0 +1,405 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+
+set check_function_bodies to on;
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+alter table ref.auto_hint
+	drop constraint if exists ref_auto_hint_sane_rec_query;
+
+alter table ref.auto_hint
+	add constraint ref_auto_hint_sane_rec_query check (
+		gm.is_null_or_non_empty_string(recommendation_query)
+	);
+
+-- --------------------------------------------------------------
+drop view if exists ref.v_auto_hints cascade;
+
+create view ref.v_auto_hints as
+select
+	pk
+		as pk_auto_hint,
+	query
+		as query,
+	recommendation_query
+		as recommendation_query,
+	title
+		as title,
+	hint
+		as hint,
+	url
+		as url,
+	is_active
+		as is_active,
+	source
+		as source,
+	lang
+		as lang,
+	-- this column is set from clin.get_hints_for_patient(),
+	-- it only exists in this view in order to enable the syntax
+	-- "returns setof ref.v_auto_hints" in that function
+	null::text
+		as rationale4suppression,
+	-- this column is set from clin.get_hints_for_patient(),
+	-- it only exists in this view in order to enable the syntax
+	-- "returns setof ref.v_auto_hints" in that function
+	null::text
+		as recommendation,
+	md5(
+		coalesce(query, '')
+		|| coalesce(recommendation_query, '')
+		|| coalesce(title, '')
+		|| coalesce(hint, '')
+		|| coalesce(url, '')
+	)	as md5_sum,
+	xmin
+		as xmin_auto_hint
+from
+	ref.auto_hint
+;
+
+
+revoke all on ref.v_auto_hints from public;
+grant select on ref.v_auto_hints to group "gm-staff";
+
+
+-- there is no need to update existing suppressions because initially
+-- all ref.auto_hint.recommendation_query's will be NULL and thusly
+-- add an empty string to the md5 summing input which does not change
+-- the md5 sum ...
+
+-- --------------------------------------------------------------
+drop function if exists clin.get_hints_for_patient(integer) cascade;
+
+create function clin.get_hints_for_patient(integer)
+	returns setof ref.v_auto_hints
+	language 'plpgsql'
+	as '
+DECLARE
+	_pk_identity ALIAS FOR $1;
+	_hint ref.v_auto_hints%rowtype;
+	_query text;
+	_md5_suppressed text;
+	_rationale4suppression text;
+	_suppression_exists boolean;		-- does not mean that the suppression applies
+	_hint_currently_applies boolean;	-- regardless of whether suppressed or not
+	_hint_recommendation text;
+--	_exc_state text;
+--	_exc_msg text;
+--	_exc_detail text;
+--	_exc_hint text;
+--	_exc_context text;
+BEGIN
+	-- loop over all defined hints
+	FOR _hint IN SELECT * FROM ref.v_auto_hints WHERE is_active LOOP
+
+		-- is the hint suppressed ?
+		SELECT
+			md5_sum,
+			rationale
+				INTO
+			_md5_suppressed,
+			_rationale4suppression
+		FROM clin.suppressed_hint WHERE
+			fk_hint = _hint.pk_auto_hint
+				AND
+			fk_encounter IN (
+				SELECT pk FROM clin.encounter WHERE fk_patient = _pk_identity
+			);
+		IF FOUND THEN
+			_suppression_exists := TRUE;
+		ELSE
+			_suppression_exists := FALSE;
+		END IF;
+
+		-- does the hint currently apply ?
+		_query := replace(_hint.query, ''ID_ACTIVE_PATIENT'', _pk_identity::text);
+		BEGIN
+			EXECUTE _query INTO STRICT _hint_currently_applies;
+		EXCEPTION
+			--WHEN insufficient_privilege THEN RAISE WARNING ''auto hint query failed: %'', _query;
+			WHEN others THEN
+				RAISE WARNING ''auto hint query failed: %'', _query;
+				-- only available starting with PG 9.2:
+				--GET STACKED DIAGNOSTICS
+				--	_exc_state = RETURNED_SQLSTATE,
+				--	_exc_msg = MESSAGE_TEXT,
+				--	_exc_detail = PG_EXCEPTION_DETAIL,
+				--	_exc_hint = PG_EXCEPTION_HINT,
+				--	_exc_context = PG_EXCEPTION_CONTEXT;
+				--RAISE WARNING ''SQL STATE: %'', _exc_state;
+				--RAISE WARNING ''MESSAGE: %'', _exc_msg;
+				--RAISE WARNING ''DETAIL: %'', _exc_detail;
+				--RAISE WARNING ''HINT: %'', _exc_hint;
+				--RAISE WARNING ''CONTEXT: %'', _exc_context;
+				-- workaround for 9.1:
+				RAISE WARNING ''SQL STATE: %'', SQLSTATE;
+				RAISE WARNING ''MESSAGE: %'', SQLERRM;
+				_hint.title := ''ERROR checking for ['' || _hint.title || ''] !'';
+				_hint.hint := _query;
+				RETURN NEXT _hint;
+				-- process next hint
+				CONTINUE;
+		END;
+
+		IF _suppression_exists THEN
+			-- is the hint definition still the same as at the time of suppression ?
+			IF _md5_suppressed = _hint.md5_sum THEN
+				-- yes, but does this hint currently apply ?
+				IF _hint_currently_applies THEN
+					-- suppressed, suppression valid, and hint applies: skip this hint
+					CONTINUE;
+				END IF;
+				-- suppressed, suppression valid, hint does NOT apply:
+				-- skip but invalidate suppression, because:
+				-- * previously the hint applied and the user suppressed it,
+				-- * then the patient changed such that the hint does not
+				--    apply anymore (but the suppression is still valid),
+				-- * when the patient changes again, the hint might apply again
+				-- * HOWEVER - since the suppression would still be valid - the
+				--   hint would magically get suppressed again (which is
+				--   medically unsafe) ...
+				-- after invalidation, the hint will no longer be suppressed,
+				-- however - since it does not currently apply it - it will
+				-- still not be returned until it applies again ...
+				--
+				-- -----------------------------------------------------------------------
+				-- UNFORTUNATELY, the following is currently not _possible_ because
+				-- we are running inside a READONLY transaction (due to inherent
+				-- security risks when running arbitrary user queries [IOW the hint
+				-- SQL] against the database) and we cannot execute a
+				-- sub-transaction as READWRITE :-/
+				--
+				--UPDATE clin.suppressed_hint
+				--SET md5_sum = ''invalidated''::text		-- will not ever match any md5 sum
+				--WHERE
+				--	fk_encounter IN (
+				--		SELECT pk FROM clin.encounter WHERE fk_patient = _pk_identity
+				--	)
+				--		AND
+				--	fk_hint = _hint.pk_auto_hint;
+				-- -----------------------------------------------------------------------
+				--
+				-- hence our our workaround is to, indeed, return the hint but
+				-- tag it with a magic rationale, by means of which the client
+				-- can detect it to be in need of invalidation:
+				_hint.title := ''HINT DOES NOT APPLY BUT NEEDS INVALIDATION OF EXISTING SUPPRESSION ['' || _hint.title || ''].'';
+				_hint.rationale4suppression := ''magic_tag::please_invalidate_suppression'';
+				RETURN NEXT _hint;
+				CONTINUE;
+			END IF;
+			-- suppression exists but hint definition must have changed
+			-- does the new hint apply ?
+			IF _hint_currently_applies THEN
+				-- yes: ignore the suppression but provide previous
+				-- rationale for suppression to the user
+				_hint.rationale4suppression := _rationale4suppression;
+				-- retrieve recommendation
+				SELECT clin._get_recommendation_for_patient_hint(_hint.recommendation_query, _pk_identity) INTO STRICT _hint_recommendation;
+				_hint.recommendation := _hint_recommendation;
+				RETURN NEXT _hint;
+				CONTINUE;
+			END IF;
+			-- no, new hint does not apply, so ask for
+			-- invalidation of suppression (see above)
+			_hint.title := ''HINT DOES NOT APPLY BUT NEEDS INVALIDATION OF EXISTING SUPPRESSION ['' || _hint.title || ''].'';
+			_hint.rationale4suppression := ''please_invalidate_suppression'';
+			RETURN NEXT _hint;
+			CONTINUE;
+		END IF;
+
+		-- hint is not suppressed
+		-- does the hint currently apply ?
+		IF _hint_currently_applies THEN
+			-- yes: retrieve recommendation
+			SELECT clin._get_recommendation_for_patient_hint(_hint.recommendation_query, _pk_identity) INTO STRICT _hint_recommendation;
+			_hint.recommendation := _hint_recommendation;
+			RETURN NEXT _hint;
+		END IF;
+		-- no: ignore it and process next hint in LOOP
+
+	END LOOP;
+	RETURN;
+END;';
+
+-- --------------------------------------------------------------
+drop function if exists clin._get_recommendation_for_patient_hint(text,integer) cascade;
+
+create function clin._get_recommendation_for_patient_hint(text,integer)
+	returns text
+	language 'plpgsql'
+	as '
+DECLARE
+	_raw_query ALIAS FOR $1;
+	_pk_identity ALIAS FOR $2;
+	_query text;
+	_recommendation text;
+BEGIN
+	IF _raw_query IS NULL THEN
+		RETURN NULL::text;
+	END IF;
+	_query := replace(_raw_query, ''ID_ACTIVE_PATIENT'', _pk_identity::text);
+	BEGIN
+		EXECUTE _query INTO STRICT _recommendation;
+	EXCEPTION
+		--WHEN insufficient_privilege THEN RAISE WARNING ''auto hint recommendation query failed: %'', _query;
+		WHEN others THEN
+			RAISE WARNING ''auto hint recommendation query failed: %'', _query;
+			-- only available starting with PG 9.2:
+			--GET STACKED DIAGNOSTICS
+			--	_exc_state = RETURNED_SQLSTATE,
+			--	_exc_msg = MESSAGE_TEXT,
+			--	_exc_detail = PG_EXCEPTION_DETAIL,
+			--	_exc_hint = PG_EXCEPTION_HINT,
+			--	_exc_context = PG_EXCEPTION_CONTEXT;
+			--RAISE WARNING ''SQL STATE: %'', _exc_state;
+			--RAISE WARNING ''MESSAGE: %'', _exc_msg;
+			--RAISE WARNING ''DETAIL: %'', _exc_detail;
+			--RAISE WARNING ''HINT: %'', _exc_hint;
+			--RAISE WARNING ''CONTEXT: %'', _exc_context;
+			-- workaround for 9.1:
+			RAISE WARNING ''SQL STATE: %'', SQLSTATE;
+			RAISE WARNING ''MESSAGE: %'', SQLERRM;
+			_recommendation := ''ERROR running hint recommendation query ['' || _query || '']'';
+	END;
+	RETURN _recommendation;
+END;';
+
+-- --------------------------------------------------------------
+DELETE FROM ref.auto_hint WHERE title = 'Lack of smoking status documentation';
+
+INSERT INTO ref.auto_hint(query, title, hint, source, lang) VALUES (
+	'SELECT NOT EXISTS(SELECT 1 FROM clin.v_nonbrand_intakes WHERE pk_patient = ID_ACTIVE_PATIENT AND atc_substance = ''N07BA01'' AND harmful_use_type IS NOT NULL)',
+	'Lack of smoking status documentation',
+	'There has never been any smoking status recorded for this patient.',
+	'AWMF NVL Schädlicher Tabakgebrauch',
+	'en'
+);
+
+
+DELETE FROM ref.auto_hint WHERE title = 'Outdated smoking status documentation';
+
+INSERT INTO ref.auto_hint(title, hint, source, lang, query, recommendation_query) VALUES (
+	'Outdated smoking status documentation',
+	'Smoking status was last recorded more than one year ago for this smoker.',
+	'AWMF NVL Schädlicher Tabakgebrauch',
+	'en',
+	'SELECT EXISTS (
+		SELECT 1 FROM clin.v_nonbrand_intakes WHERE
+			(pk_patient = ID_ACTIVE_PATIENT)
+				AND
+			(atc_substance = ''N07BA01'')
+				AND
+			(coalesce(harmful_use_type, -1) > 0)
+				AND
+			((discontinued IS NULL) OR (discontinued > now()))
+				AND
+			(last_checked_when < now() - ''1 year''::interval)
+	);',
+	'SELECT
+		_(''Smoking status'') || E''\n''
+		|| '' '' || _(''Last checked:'') || '' '' || to_char(last_checked_when, ''Mon YYYY'')
+		|| (case
+				when harmful_use_type = 1 then E''\n'' || _(''harmful use'')
+				when harmful_use_type = 2 then E''\n'' || _(''addiction'')
+				when harmful_use_type = 3 then E''\n'' || _(''previous addiction'')
+			end)
+		|| coalesce(E''\n '' || _(''Quit date:'') || '' '' || to_char(discontinued, ''YYYY Mon DD''), '''')
+		|| coalesce(E''\n '' || _(''Notes:'') || '' '' || notes, '''')
+	FROM
+		clin.v_nonbrand_intakes
+	WHERE pk_patient = ID_ACTIVE_PATIENT;'
+);
+
+-- --------------------------------------------------------------
+DELETE FROM ref.auto_hint WHERE title = 'Kontraindikation: ACE/Sartan <-> Schwangerschaft';
+DELETE FROM ref.auto_hint WHERE title = 'Contraindication: ACEI/Sartan <-> Pregnancy';
+
+insert into ref.auto_hint(query, title, hint, url, source, lang, recommendation_query) values (
+	'SELECT EXISTS (
+	-- substance check
+	SELECT 1 FROM clin.v_substance_intakes WHERE
+		pk_patient = ID_ACTIVE_PATIENT
+			AND
+		-- on Sartan or ACEI
+		(
+			substance ~* ''.*sartan.*''
+				OR
+			substance ~* ''.*angiotensin.*''
+				OR
+			substance ~ ''.*ACE.*''
+				OR
+			-- might result in false positives (.Prilocarpin)
+			substance ~* ''.+pril.*''
+				OR
+			atc_brand ~* ''^C09.*''
+				OR
+			atc_substance ~* ''^C09.*''
+	)
+) AND EXISTS (
+	-- pregnancy check
+	SELECT 1 FROM clin.patient WHERE
+		fk_identity = ID_ACTIVE_PATIENT
+			AND
+		coalesce(edc BETWEEN now() - ''1 month''::interval AND now() + ''11 months''::interval, FALSE)
+);',
+	'Contraindication: ACEI/Sartan <-> Pregnancy',
+	'ACEI and Sartans can cause severe fetopathies if used during 2nd and 3rd trimenon.',
+	'http://www.akdae.de/Arzneimittelsicherheit/Bekanntgaben/Archiv/2010/201010151.pdf',
+	'GNUmed default (AkdÄ 2012)',
+	'en',
+	'SELECT _(''EDC: '') || to_char(edc, ''YYYY Mon DD'') FROM clin.patient WHERE fk_identity = ID_ACTIVE_PATIENT;'
+);
+
+-- --------------------------------------------------------------
+DELETE FROM ref.auto_hint WHERE title = 'Outdated or questionable EDC';
+
+insert into ref.auto_hint(title, hint, source, lang, query, recommendation_query) values (
+	'Outdated or questionable EDC',
+	'The EDC documented for this patient is outdated or too far in the future.',
+	'GNUmed default',
+	'en',
+	'SELECT EXISTS (
+	SELECT 1 FROM clin.patient WHERE
+		fk_identity = ID_ACTIVE_PATIENT
+			AND
+		coalesce((
+			-- longer than 3 months ago
+			edc < now() - ''3 months''::interval
+				OR
+			-- 2 years in the future
+			edc > now() + ''2 years''::interval
+		), FALSE)
+);',
+	'SELECT _(''EDC: '') || to_char(edc, ''YYYY Mon DD'') FROM clin.patient WHERE fk_identity = ID_ACTIVE_PATIENT;'
+);
+
+-- --------------------------------------------------------------
+DELETE FROM ref.auto_hint WHERE title = 'Questionable EDC';
+
+insert into ref.auto_hint(title, hint, source, lang, query, recommendation_query) values (
+	'Questionable EDC',
+	'There is an EDC documented for this MALE patient.',
+	'GNUmed default',
+	'en',
+	'SELECT (
+	SELECT d_i.gender = ''m'' FROM dem.identity d_i WHERE
+		d_i.pk = ID_ACTIVE_PATIENT
+) AND EXISTS (
+	SELECT 1 FROM clin.patient WHERE
+		fk_identity = ID_ACTIVE_PATIENT
+			AND
+		edc IS NOT NULL
+);',
+	'SELECT _(''EDC: '') || to_char(edc, ''YYYY Mon DD'') FROM clin.patient WHERE fk_identity = ID_ACTIVE_PATIENT;'
+);
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-ref-v_auto_hints.sql', '21.0');
diff --git a/server/sql/v20-v21/dynamic/v21-release_notes-dynamic.sql b/server/sql/v20-v21/dynamic/v21-release_notes-dynamic.sql
new file mode 100644
index 0000000..38940a6
--- /dev/null
+++ b/server/sql/v20-v21/dynamic/v21-release_notes-dynamic.sql
@@ -0,0 +1,114 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+INSERT INTO dem.message_inbox (
+	fk_staff,
+	fk_inbox_item_type,
+	comment,
+	data
+) VALUES (
+	(select pk from dem.staff where db_user = 'any-doc'),
+	(select pk_type from dem.v_inbox_item_type where type = 'memo' and category = 'administrative'),
+	'Release Notes for GNUmed 1.6.0 (database v21.0)',
+	'GNUmed 1.6.0 Release Notes:
+
+	1.6.0
+
+NEW: plugin: list based EMR journal
+NEW: plugin: limited PACS access (Orthanc DICOM server)
+NEW: text editor like SOAP editor (STC based)
+NEW: first cut at German AMTS medication plan
+NEW: always display select measurements in top panel
+NEW: copy-to-clipboard list content via popup menu
+NEW: region support for placeholder output
+NEW: ellipsis support for placeholder output
+NEW: placeholder $range_of$
+NEW: placeholder $ph_cfg$
+NEW: placeholder $current_meds_AMTS$
+NEW: placeholder $praxis_vcf$
+NEW: placeholder <form_version_internal>
+NEW: placeholder <form_last_modified>
+NEW: placeholder $url_escape$
+NEW: add appdata.xml
+NEW: show patient address in openstreetmap
+NEW: support for substance abuse status (nicotine, ethanol, other)
+NEW: print EMR from EMR tree
+NEW: search in EMR journal view
+NEW: copy EMR journal to export area
+NEW: tooltip in procedures list
+NEW: browse tmp dir, ~/gnumed/, ~/.gnumed/ from client
+NEW: dynamic hint on outdated / questionable EDC
+NEW: HIT risk assessment algorithm
+
+IMPROVED: substance intake editing workflow
+IMPROVED: shutdown with dangling top level windows
+IMPROVED: list suppressed dynamic hints in patient overview [thanks Jim]
+IMPROVED: top panel active encounter area layout [thanks Jim]
+IMPROVED: measurements plots layout
+IMPROVED: injectable placeholders: support arbitrary names if desired
+IMPROVED: placeholder nesting regexen
+IMPROVED: enable nested placeholders in text engine, too
+IMPROVED: lab_panel.most_recent_results() can now respect meta types
+IMPROVED: ignore_dupes_on_picking seems a better item picker default
+IMPROVED: overall code towards Python 3 compatibility
+IMPROVED: CODE: cIdentity(Tag) -> cPerson(Tag)
+IMPROVED: security of tmp/sandbox dir setup
+IMPROVED: do not auto-plot results from edit area
+IMPROVED: much faster access to latest vaccinations
+IMPROVED: show all selected parts at once in new-document plugin
+IMPROVED: ask whether to create metadata when saving export area documents
+IMPROVED: EMR journal formatting
+IMPROVED: support deleting more than one list item at a time
+IMPROVED: put file from filename in clipboard into export area
+IMPROVED: startup shell script
+IMPROVED: procedure tooltip in patient overview Hx box
+IMPROVED: external care tooltip in patient overview problems box
+IMPROVED: tooltip in external care management list
+IMPROVED: substance intake timeframe formatting
+IMPROVED: layout of measurements plugin
+IMPROVED: properly show visual progress notes for empty issues in EMR tree
+IMPROVED: support for invoking file manager on a directory
+IMPROVED: show admin SOAP in EMR tree at encounter level
+IMPROVED: ACEI/pregnancy dynamic hint
+IMPROVED: data mining SQL now wants $<ID_ACTIVE_PATIENT>$ rather than $<ID_active_patient>$
+IMPROVED: can now delete EDC
+IMPROVED: support documenting which organization a document originated from
+IMPROVED: workflow for disabling an identity
+IMPROVED: EMR Journal formatting of hospital stays
+IMPROVED: new-document workflow
+IMPROVED: German referral letter
+IMPROVED: include clinical reminders with EMR Journal
+
+	21.0
+
+NEW: require PG 9.2 because of pg_trigger_depth()
+
+NEW: dem.v_basic_person -> dem.v_active_persons
+NEW: prevent deletion of staff records that are in use
+NEW: smoking support in clin.patient
+NEW: constraints on audit trail to be in the past
+NEW: check for track_commit_timestamp on PG > 9.5
+NEW: chunked md5() for large objects
+NEW: backup/restore scripts based on directory format
+
+IMPROVED: database restore default configuration
+IMPROVED: more resilient backups
+IMPROVED: all input files now utf8 (io.open() Py3 preps)
+IMPROVED: dem.state -> dem.region
+IMPROVED: dem.region.id -> dem.region.pk
+IMPROVED: dem.urb.id_state -> dem.urb.fk_region
+
+FIX: pg_trgm placement and use
+FIX: trigger on clin.procedure normalizing .is_ongoing
+');
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-release_notes-dynamic.sql', '21.0');
diff --git a/server/sql/v20-v21/gm_db-gnumed_v21-fingerprint.txt b/server/sql/v20-v21/gm_db-gnumed_v21-fingerprint.txt
new file mode 100644
index 0000000..ebca874
--- /dev/null
+++ b/server/sql/v20-v21/gm_db-gnumed_v21-fingerprint.txt
@@ -0,0 +1,1789 @@
+Fingerprinting GNUmed database ...
+
+           Name (DB): gnumed_v21
+           Size (DB): 64 MB
+         Schema hash: d7b60c6191a71a812904a7523ed8c80c
+        Version (PG): 9.5.1
+       Encoding (PG): UTF8
+     LC_COLLATE (PG): de_DE.UTF-8
+       LC_CTYPE (PG): de_DE.UTF-8
+            Patients: 15
+            Contacts: 9
+            Episodes: 6
+              Issues: 2
+             Results: 5
+        Vaccinations: 1
+           Documents: 3
+             Objects: 4
+       Organizations: 8
+Organizational units: 10
+ Last .modified_when: 2016-02-21 17:43:40.592251+00:00
+    Last .audit_when: 2016-02-21 17:43:40.592251+00:00
+
+TABLE:ref.tag_image
+PK:ref.tag_image.pk::integer
+COL:ref.tag_image.image::bytea
+COL:ref.tag_image.description::text
+COL:ref.tag_image.filename::text
+COL:ref.tag_image.row_version::int4
+COL:ref.tag_image.modified_when::timestamptz
+COL:ref.tag_image.pk::int4
+COL:ref.tag_image.pk_audit::int4
+COL:ref.tag_image.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+TABLE:ref.icd9
+PK:ref.icd9.pk::integer
+COL:ref.icd9.pk_coding_system::int4
+COL:ref.icd9.fk_data_source::int4
+COL:ref.icd9.comment::text
+COL:ref.icd9.term::text
+COL:ref.icd9.code::text
+COL:ref.icd9.pk::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_data_source)_REFERENCES_ref.data_source(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:dem.org_category
+PK:dem.org_category.pk::integer
+COL:dem.org_category.description::text
+COL:dem.org_category.pk::int4
+TABLE:clin.test_type
+PK:clin.test_type.pk::integer
+COL:clin.test_type.name::text
+COL:clin.test_type.comment::text
+COL:clin.test_type.fk_meta_test_type::int4
+COL:clin.test_type.fk_test_org::int4
+COL:clin.test_type.row_version::int4
+COL:clin.test_type.modified_when::timestamptz
+COL:clin.test_type.abbrev::text
+COL:clin.test_type.pk::int4
+COL:clin.test_type.loinc::text
+COL:clin.test_type.pk_audit::int4
+COL:clin.test_type.modified_by::name
+COL:clin.test_type.reference_unit::text
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_test_org)_REFERENCES_clin.test_org(pk)::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_meta_test_type)_REFERENCES_clin.meta_test_type(pk)::active=true
+TABLE:clin.lnk_substance2episode
+PK:clin.lnk_substance2episode.pk::integer
+COL:clin.lnk_substance2episode.fk_substance::int4
+COL:clin.lnk_substance2episode.row_version::int4
+COL:clin.lnk_substance2episode.modified_when::timestamptz
+COL:clin.lnk_substance2episode.fk_episode::int4
+COL:clin.lnk_substance2episode.pk::int4
+COL:clin.lnk_substance2episode.pk_audit::int4
+COL:clin.lnk_substance2episode.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_substance)_REFERENCES_clin.substance_intake(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_episode)_REFERENCES_clin.episode(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:cfg.cfg_data
+PK:cfg.cfg_data.pk::integer
+COL:cfg.cfg_data.fk_item::int4
+COL:cfg.cfg_data.pk::int4
+COL:cfg.cfg_data.value::bytea
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_item)_REFERENCES_cfg.cfg_item(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:cfg.report_query
+PK:cfg.report_query.pk::integer
+COL:cfg.report_query.label::text
+COL:cfg.report_query.cmd::text
+COL:cfg.report_query.row_version::int4
+COL:cfg.report_query.modified_when::timestamptz
+COL:cfg.report_query.pk::int4
+COL:cfg.report_query.pk_audit::int4
+COL:cfg.report_query.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+TABLE:clin.export_item
+PK:clin.export_item.pk::integer
+COL:clin.export_item.description::text
+COL:clin.export_item.filename::text
+COL:clin.export_item.created_by::name
+COL:clin.export_item.designation::text
+COL:clin.export_item.data::bytea
+COL:clin.export_item.fk_identity::int4
+COL:clin.export_item.fk_doc_obj::int4
+COL:clin.export_item.pk::int4
+COL:clin.export_item.created_when::timestamptz
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_identity)_REFERENCES_clin.patient(fk_identity)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_doc_obj)_REFERENCES_blobs.doc_obj(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:i18n.curr_lang
+PK:i18n.curr_lang.pk::integer
+COL:i18n.curr_lang.db_user::name
+COL:i18n.curr_lang.lang::text
+COL:i18n.curr_lang.pk::int4
+TABLE:clin.test_panel
+PK:clin.test_panel.pk::integer
+COL:clin.test_panel.comment::text
+COL:clin.test_panel.description::text
+COL:clin.test_panel.row_version::int4
+COL:clin.test_panel.modified_when::timestamptz
+COL:clin.test_panel.pk::int4
+COL:clin.test_panel.fk_test_types::_int4
+COL:clin.test_panel.pk_audit::int4
+COL:clin.test_panel.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+TABLE:clin.vaccination_schedule
+PK:clin.vaccination_schedule.pk::integer
+COL:clin.vaccination_schedule.name::text
+COL:clin.vaccination_schedule.comment::text
+COL:clin.vaccination_schedule.row_version::int4
+COL:clin.vaccination_schedule.modified_when::timestamptz
+COL:clin.vaccination_schedule.pk::int4
+COL:clin.vaccination_schedule.pk_audit::int4
+COL:clin.vaccination_schedule.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+TABLE:clin.vaccine
+PK:clin.vaccine.pk::integer
+COL:clin.vaccine.id_route::int4
+COL:clin.vaccine.comment::text
+COL:clin.vaccine.fk_brand::int4
+COL:clin.vaccine.is_live::bool
+COL:clin.vaccine.max_age::interval
+COL:clin.vaccine.row_version::int4
+COL:clin.vaccine.modified_when::timestamptz
+COL:clin.vaccine.pk::int4
+COL:clin.vaccine.min_age::interval
+COL:clin.vaccine.pk_audit::int4
+COL:clin.vaccine.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(id_route)_REFERENCES_clin.vacc_route(id)::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_brand)_REFERENCES_ref.branded_drug(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:dem.identity_tag
+PK:dem.identity_tag.pk::integer
+COL:dem.identity_tag.comment::text
+COL:dem.identity_tag.fk_tag::int4
+COL:dem.identity_tag.row_version::int4
+COL:dem.identity_tag.fk_identity::int4
+COL:dem.identity_tag.modified_when::timestamptz
+COL:dem.identity_tag.pk::int4
+COL:dem.identity_tag.pk_audit::int4
+COL:dem.identity_tag.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_identity)_REFERENCES_dem.identity(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_tag)_REFERENCES_ref.tag_image(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:cfg.config
+PK:cfg.config.id::integer
+COL:cfg.config.profile::bpchar
+COL:cfg.config.ddb::int4
+COL:cfg.config.pwd_hash::text
+COL:cfg.config.id::int4
+COL:cfg.config.hash_algo::text
+COL:cfg.config.crypt_algo::text
+COL:cfg.config.db::int4
+COL:cfg.config.username::bpchar
+COL:cfg.config.crypt_pwd::text
+TABLE:clin.encounter_type
+PK:clin.encounter_type.pk::integer
+COL:clin.encounter_type.description::text
+COL:clin.encounter_type.pk::int4
+TABLE:dem.occupation
+PK:dem.occupation.id::integer
+COL:dem.occupation.name::text
+COL:dem.occupation.id::int4
+COL:dem.occupation.row_version::int4
+COL:dem.occupation.modified_when::timestamptz
+COL:dem.occupation.pk_audit::int4
+COL:dem.occupation.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+TABLE:clin.reviewed_test_results
+PK:clin.reviewed_test_results.pk::integer
+COL:clin.reviewed_test_results.comment::text
+COL:clin.reviewed_test_results.clinically_relevant::bool
+COL:clin.reviewed_test_results.fk_reviewed_row::int4
+COL:clin.reviewed_test_results.is_technically_abnormal::bool
+COL:clin.reviewed_test_results.row_version::int4
+COL:clin.reviewed_test_results.modified_when::timestamptz
+COL:clin.reviewed_test_results.pk::int4
+COL:clin.reviewed_test_results.fk_reviewer::int4
+COL:clin.reviewed_test_results.pk_audit::int4
+COL:clin.reviewed_test_results.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_reviewer)_REFERENCES_dem.staff(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_reviewed_row)_REFERENCES_clin.test_result(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:dem.gender_label
+PK:dem.gender_label.pk::integer
+COL:dem.gender_label.label::text
+COL:dem.gender_label.comment::text
+COL:dem.gender_label.tag::text
+COL:dem.gender_label.sort_weight::int4
+COL:dem.gender_label.row_version::int4
+COL:dem.gender_label.modified_when::timestamptz
+COL:dem.gender_label.pk::int4
+COL:dem.gender_label.pk_audit::int4
+COL:dem.gender_label.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+TABLE:clin.lnk_vaccination_course2schedule
+PK:clin.lnk_vaccination_course2schedule.pk::integer
+COL:clin.lnk_vaccination_course2schedule.fk_course::int4
+COL:clin.lnk_vaccination_course2schedule.fk_schedule::int4
+COL:clin.lnk_vaccination_course2schedule.row_version::int4
+COL:clin.lnk_vaccination_course2schedule.modified_when::timestamptz
+COL:clin.lnk_vaccination_course2schedule.pk::int4
+COL:clin.lnk_vaccination_course2schedule.pk_audit::int4
+COL:clin.lnk_vaccination_course2schedule.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_course)_REFERENCES_clin.vaccination_course(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_schedule)_REFERENCES_clin.vaccination_schedule(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:clin.incoming_data_unmatched
+PK:clin.incoming_data_unmatched.pk::integer
+COL:clin.incoming_data_unmatched.lastnames::text
+COL:clin.incoming_data_unmatched.external_data_id::text
+COL:clin.incoming_data_unmatched.fk_provider_disambiguated::int4
+COL:clin.incoming_data_unmatched.comment::text
+COL:clin.incoming_data_unmatched.type::text
+COL:clin.incoming_data_unmatched.requestor::text
+COL:clin.incoming_data_unmatched.gender::text
+COL:clin.incoming_data_unmatched.firstnames::text
+COL:clin.incoming_data_unmatched.data::bytea
+COL:clin.incoming_data_unmatched.row_version::int4
+COL:clin.incoming_data_unmatched.modified_when::timestamptz
+COL:clin.incoming_data_unmatched.other_info::text
+COL:clin.incoming_data_unmatched.pk::int4
+COL:clin.incoming_data_unmatched.pk_audit::int4
+COL:clin.incoming_data_unmatched.fk_patient_candidates::_int4
+COL:clin.incoming_data_unmatched.modified_by::name
+COL:clin.incoming_data_unmatched.request_id::text
+COL:clin.incoming_data_unmatched.postcode::text
+COL:clin.incoming_data_unmatched.dob::date
+COL:clin.incoming_data_unmatched.fk_identity_disambiguated::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_provider_disambiguated)_REFERENCES_dem.staff(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_identity_disambiguated)_REFERENCES_clin.patient(fk_identity)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:blobs.lnk_doc2hospital_stay
+PK:blobs.lnk_doc2hospital_stay.pk::integer
+COL:blobs.lnk_doc2hospital_stay.fk_stay::int4
+COL:blobs.lnk_doc2hospital_stay.fk_document::int4
+COL:blobs.lnk_doc2hospital_stay.row_version::int4
+COL:blobs.lnk_doc2hospital_stay.modified_when::timestamptz
+COL:blobs.lnk_doc2hospital_stay.pk::int4
+COL:blobs.lnk_doc2hospital_stay.pk_audit::int4
+COL:blobs.lnk_doc2hospital_stay.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_stay)_REFERENCES_clin.hospital_stay(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_document)_REFERENCES_blobs.doc_med(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:blobs.reviewed_doc_objs
+PK:blobs.reviewed_doc_objs.pk::integer
+COL:blobs.reviewed_doc_objs.comment::text
+COL:blobs.reviewed_doc_objs.clinically_relevant::bool
+COL:blobs.reviewed_doc_objs.fk_reviewed_row::int4
+COL:blobs.reviewed_doc_objs.is_technically_abnormal::bool
+COL:blobs.reviewed_doc_objs.row_version::int4
+COL:blobs.reviewed_doc_objs.modified_when::timestamptz
+COL:blobs.reviewed_doc_objs.pk::int4
+COL:blobs.reviewed_doc_objs.fk_reviewer::int4
+COL:blobs.reviewed_doc_objs.pk_audit::int4
+COL:blobs.reviewed_doc_objs.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_reviewed_row)_REFERENCES_blobs.doc_obj(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:clin.vaccine_batches
+PK:clin.vaccine_batches.pk::integer
+COL:clin.vaccine_batches.fk_vaccine::int4
+COL:clin.vaccine_batches.batch_no::text
+COL:clin.vaccine_batches.row_version::int4
+COL:clin.vaccine_batches.modified_when::timestamptz
+COL:clin.vaccine_batches.pk::int4
+COL:clin.vaccine_batches.pk_audit::int4
+COL:clin.vaccine_batches.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_vaccine)_REFERENCES_clin.vaccine(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:clin.encounter
+PK:clin.encounter.pk::integer
+COL:clin.encounter.fk_location::int4
+COL:clin.encounter.reason_for_encounter::text
+COL:clin.encounter.source_time_zone::interval
+COL:clin.encounter.fk_patient::int4
+COL:clin.encounter.last_affirmed::timestamptz
+COL:clin.encounter.row_version::int4
+COL:clin.encounter.modified_when::timestamptz
+COL:clin.encounter.pk::int4
+COL:clin.encounter.fk_type::int4
+COL:clin.encounter.pk_audit::int4
+COL:clin.encounter.assessment_of_encounter::text
+COL:clin.encounter.modified_by::name
+COL:clin.encounter.started::timestamptz
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_type)_REFERENCES_clin.encounter_type(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_patient)_REFERENCES_clin.patient(fk_identity)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_location)_REFERENCES_dem.org_unit(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:dem.message_inbox
+PK:dem.message_inbox.pk::integer
+COL:dem.message_inbox.fk_staff::int4
+COL:dem.message_inbox.comment::text
+COL:dem.message_inbox.due_date::date
+COL:dem.message_inbox.importance::int2
+COL:dem.message_inbox.fk_patient::int4
+COL:dem.message_inbox.row_version::int4
+COL:dem.message_inbox.modified_when::timestamptz
+COL:dem.message_inbox.data::text
+COL:dem.message_inbox.expiry_date::date
+COL:dem.message_inbox.pk::int4
+COL:dem.message_inbox.pk_audit::int4
+COL:dem.message_inbox.fk_inbox_item_type::int4
+COL:dem.message_inbox.modified_by::name
+COL:dem.message_inbox.ufk_context::_int4
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_patient)_REFERENCES_dem.identity(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_staff)_REFERENCES_dem.staff(pk)::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_inbox_item_type)_REFERENCES_dem.inbox_item_type(pk)::active=true
+TABLE:dem.enum_comm_types
+PK:dem.enum_comm_types.pk::integer
+COL:dem.enum_comm_types.description::text
+COL:dem.enum_comm_types.pk::int4
+TABLE:clin.vaccination_course
+PK:clin.vaccination_course.pk::integer
+COL:clin.vaccination_course.is_active::bool
+COL:clin.vaccination_course.comment::text
+COL:clin.vaccination_course.fk_indication::int4
+COL:clin.vaccination_course.row_version::int4
+COL:clin.vaccination_course.modified_when::timestamptz
+COL:clin.vaccination_course.pk::int4
+COL:clin.vaccination_course.fk_recommended_by::int4
+COL:clin.vaccination_course.pk_audit::int4
+COL:clin.vaccination_course.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_indication)_REFERENCES_clin.vacc_indication(id)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:cfg.cfg_string
+PK:cfg.cfg_string.pk::integer
+COL:cfg.cfg_string.fk_item::int4
+COL:cfg.cfg_string.value::text
+COL:cfg.cfg_string.pk::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_item)_REFERENCES_cfg.cfg_item(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:clin.allergy
+PK:clin.allergy.pk::integer
+COL:clin.allergy.fk_encounter::int4
+COL:clin.allergy.generics::text
+COL:clin.allergy.substance_code::text
+COL:clin.allergy.definite::bool
+COL:clin.allergy.narrative::text
+COL:clin.allergy.atc_code::text
+COL:clin.allergy.allergene::text
+COL:clin.allergy.row_version::int4
+COL:clin.allergy.clin_when::timestamptz
+COL:clin.allergy.modified_when::timestamptz
+COL:clin.allergy.pk_item::int4
+COL:clin.allergy.soap_cat::text
+COL:clin.allergy.fk_episode::int4
+COL:clin.allergy.generic_specific::bool
+COL:clin.allergy.pk::int4
+COL:clin.allergy.fk_type::int4
+COL:clin.allergy.substance::text
+COL:clin.allergy.pk_audit::int4
+COL:clin.allergy.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter)_REFERENCES_clin.encounter(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_type)_REFERENCES_clin._enum_allergy_type(pk)::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_episode)_REFERENCES_clin.episode(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:dem.identity
+PK:dem.identity.pk::integer
+COL:dem.identity.cob::bpchar
+COL:dem.identity.title::text
+COL:dem.identity.dob_is_estimated::bool
+COL:dem.identity.comment::text
+COL:dem.identity.fk_marital_status::int4
+COL:dem.identity.deceased::timestamptz
+COL:dem.identity.fk_primary_provider::int4
+COL:dem.identity.gender::text
+COL:dem.identity.deleted::bool
+COL:dem.identity.emergency_contact::text
+COL:dem.identity.fk_emergency_contact::int4
+COL:dem.identity.row_version::int4
+COL:dem.identity.modified_when::timestamptz
+COL:dem.identity.tob::time
+COL:dem.identity.pk::int4
+COL:dem.identity.pk_audit::int4
+COL:dem.identity.modified_by::name
+COL:dem.identity.dob::timestamptz
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_emergency_contact)_REFERENCES_dem.identity(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_marital_status)_REFERENCES_dem.marital_status(pk)::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_primary_provider)_REFERENCES_dem.staff(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(gender)_REFERENCES_dem.gender_label(tag)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:clin.vaccination
+PK:clin.vaccination.pk::integer
+COL:clin.vaccination.fk_provider::int4
+COL:clin.vaccination.fk_encounter::int4
+COL:clin.vaccination.reaction::text
+COL:clin.vaccination.fk_vaccine::int4
+COL:clin.vaccination.narrative::text
+COL:clin.vaccination.batch_no::text
+COL:clin.vaccination.row_version::int4
+COL:clin.vaccination.clin_when::timestamptz
+COL:clin.vaccination.modified_when::timestamptz
+COL:clin.vaccination.pk_item::int4
+COL:clin.vaccination.soap_cat::text
+COL:clin.vaccination.fk_episode::int4
+COL:clin.vaccination.site::text
+COL:clin.vaccination.pk::int4
+COL:clin.vaccination.pk_audit::int4
+COL:clin.vaccination.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_vaccine)_REFERENCES_clin.vaccine(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter)_REFERENCES_clin.encounter(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_provider)_REFERENCES_dem.staff(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_episode)_REFERENCES_clin.episode(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:ref.icpc
+PK:ref.icpc.pk::integer
+COL:ref.icpc.exclusions::_text
+COL:ref.icpc.pk_coding_system::int4
+COL:ref.icpc.fk_data_source::int4
+COL:ref.icpc.comment::text
+COL:ref.icpc.code_extension::text
+COL:ref.icpc.term::text
+COL:ref.icpc.inclusions::text
+COL:ref.icpc.code::text
+COL:ref.icpc.criteria::text
+COL:ref.icpc.see_also::_text
+COL:ref.icpc.short_description::text
+COL:ref.icpc.fk_chapter::bpchar
+COL:ref.icpc.pk::int4
+COL:ref.icpc.fk_component::int2
+COL:ref.icpc.icd10::_text
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_component)_REFERENCES_ref.icpc_component(component)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_data_source)_REFERENCES_ref.data_source(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_chapter)_REFERENCES_ref.icpc_chapter(chapter)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:clin.test_org
+PK:clin.test_org.pk::integer
+COL:clin.test_org.contact::text
+COL:clin.test_org.comment::text
+COL:clin.test_org.fk_med_contact::int4
+COL:clin.test_org.row_version::int4
+COL:clin.test_org.modified_when::timestamptz
+COL:clin.test_org.pk::int4
+COL:clin.test_org.pk_audit::int4
+COL:clin.test_org.fk_org_unit::int4
+COL:clin.test_org.modified_by::name
+COL:clin.test_org.fk_adm_contact::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_org_unit)_REFERENCES_dem.org_unit(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_adm_contact)_REFERENCES_dem.identity(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_med_contact)_REFERENCES_dem.identity(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:clin.procedure
+PK:clin.procedure.pk::integer
+COL:clin.procedure.fk_encounter::int4
+COL:clin.procedure.fk_hospital_stay::int4
+COL:clin.procedure.narrative::text
+COL:clin.procedure.row_version::int4
+COL:clin.procedure.clin_when::timestamptz
+COL:clin.procedure.modified_when::timestamptz
+COL:clin.procedure.is_ongoing::bool
+COL:clin.procedure.pk_item::int4
+COL:clin.procedure.clin_end::timestamptz
+COL:clin.procedure.soap_cat::text
+COL:clin.procedure.fk_episode::int4
+COL:clin.procedure.pk::int4
+COL:clin.procedure.pk_audit::int4
+COL:clin.procedure.fk_org_unit::int4
+COL:clin.procedure.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_hospital_stay)_REFERENCES_clin.hospital_stay(pk)::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter)_REFERENCES_clin.encounter(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_org_unit)_REFERENCES_dem.org_unit(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_episode)_REFERENCES_clin.episode(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:dem.lnk_org_unit2ext_id
+PK:dem.lnk_org_unit2ext_id.pk::integer
+COL:dem.lnk_org_unit2ext_id.comment::text
+COL:dem.lnk_org_unit2ext_id.row_version::int4
+COL:dem.lnk_org_unit2ext_id.modified_when::timestamptz
+COL:dem.lnk_org_unit2ext_id.pk::int4
+COL:dem.lnk_org_unit2ext_id.fk_type::int4
+COL:dem.lnk_org_unit2ext_id.pk_audit::int4
+COL:dem.lnk_org_unit2ext_id.fk_org_unit::int4
+COL:dem.lnk_org_unit2ext_id.modified_by::name
+COL:dem.lnk_org_unit2ext_id.external_id::text
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_org_unit)_REFERENCES_dem.org_unit(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_type)_REFERENCES_dem.enum_ext_id_types(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:dem.name_gender_map
+PK:dem.name_gender_map.id::integer
+COL:dem.name_gender_map.name::text
+COL:dem.name_gender_map.id::int4
+COL:dem.name_gender_map.gender::bpchar
+TABLE:ref.branded_drug
+PK:ref.branded_drug.pk::integer
+COL:ref.branded_drug.fk_data_source::int4
+COL:ref.branded_drug.description::text
+COL:ref.branded_drug.is_fake::bool
+COL:ref.branded_drug.preparation::text
+COL:ref.branded_drug.external_code_type::text
+COL:ref.branded_drug.atc_code::text
+COL:ref.branded_drug.row_version::int4
+COL:ref.branded_drug.modified_when::timestamptz
+COL:ref.branded_drug.pk::int4
+COL:ref.branded_drug.pk_audit::int4
+COL:ref.branded_drug.external_code::text
+COL:ref.branded_drug.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_data_source)_REFERENCES_ref.data_source(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:clin.meta_test_type
+PK:clin.meta_test_type.pk::integer
+COL:clin.meta_test_type.name::text
+COL:clin.meta_test_type.comment::text
+COL:clin.meta_test_type.abbrev::text
+COL:clin.meta_test_type.pk::int4
+COL:clin.meta_test_type.loinc::text
+TABLE:clin.external_care
+PK:clin.external_care.pk::integer
+COL:clin.external_care.fk_encounter::int4
+COL:clin.external_care.fk_health_issue::int4
+COL:clin.external_care.provider::text
+COL:clin.external_care.comment::text
+COL:clin.external_care.row_version::int4
+COL:clin.external_care.modified_when::timestamptz
+COL:clin.external_care.issue::text
+COL:clin.external_care.pk::int4
+COL:clin.external_care.pk_audit::int4
+COL:clin.external_care.fk_org_unit::int4
+COL:clin.external_care.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_health_issue)_REFERENCES_clin.health_issue(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_org_unit)_REFERENCES_dem.org_unit(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter)_REFERENCES_clin.encounter(pk)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT::active=true
+TABLE:clin.form_data
+PK:clin.form_data.pk::integer
+COL:clin.form_data.fk_instance::int4
+COL:clin.form_data.fk_form_field::int4
+COL:clin.form_data.value::text
+COL:clin.form_data.row_version::int4
+COL:clin.form_data.modified_when::timestamptz
+COL:clin.form_data.pk::int4
+COL:clin.form_data.pk_audit::int4
+COL:clin.form_data.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_form_field)_REFERENCES_form_fields(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_instance)_REFERENCES_clin.form_instances(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:ref.icpc_component
+PK:ref.icpc_component.pk::integer
+COL:ref.icpc_component.description::text
+COL:ref.icpc_component.component::int2
+COL:ref.icpc_component.typical_soap_cat::_text
+COL:ref.icpc_component.pk::int4
+TABLE:clin.review_root
+PK:clin.review_root.pk::integer
+COL:clin.review_root.comment::text
+COL:clin.review_root.clinically_relevant::bool
+COL:clin.review_root.fk_reviewed_row::int4
+COL:clin.review_root.is_technically_abnormal::bool
+COL:clin.review_root.row_version::int4
+COL:clin.review_root.modified_when::timestamptz
+COL:clin.review_root.pk::int4
+COL:clin.review_root.fk_reviewer::int4
+COL:clin.review_root.pk_audit::int4
+COL:clin.review_root.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_reviewer)_REFERENCES_dem.staff(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:clin.lnk_type2item
+PK:clin.lnk_type2item.pk::integer
+COL:clin.lnk_type2item.fk_item::int4
+COL:clin.lnk_type2item.row_version::int4
+COL:clin.lnk_type2item.modified_when::timestamptz
+COL:clin.lnk_type2item.pk::int4
+COL:clin.lnk_type2item.fk_type::int4
+COL:clin.lnk_type2item.pk_audit::int4
+COL:clin.lnk_type2item.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_type)_REFERENCES_clin.clin_item_type(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:clin.family_history
+PK:clin.family_history.pk::integer
+COL:clin.family_history.fk_encounter::int4
+COL:clin.family_history.age_of_death::interval
+COL:clin.family_history.dob_relative::timestamptz
+COL:clin.family_history.age_noted::text
+COL:clin.family_history.comment::text
+COL:clin.family_history.name_relative::text
+COL:clin.family_history.contributed_to_death::bool
+COL:clin.family_history.narrative::text
+COL:clin.family_history.row_version::int4
+COL:clin.family_history.clin_when::timestamptz
+COL:clin.family_history.modified_when::timestamptz
+COL:clin.family_history.pk_item::int4
+COL:clin.family_history.soap_cat::text
+COL:clin.family_history.fk_episode::int4
+COL:clin.family_history.pk::int4
+COL:clin.family_history.fk_relation_type::int4
+COL:clin.family_history.pk_audit::int4
+COL:clin.family_history.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_relation_type)_REFERENCES_clin.fhx_relation_type(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter)_REFERENCES_clin.encounter(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_episode)_REFERENCES_clin.episode(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:blobs.doc_obj
+PK:blobs.doc_obj.pk::integer
+COL:blobs.doc_obj.comment::text
+COL:blobs.doc_obj.seq_idx::int4
+COL:blobs.doc_obj.filename::text
+COL:blobs.doc_obj.data::bytea
+COL:blobs.doc_obj.pk::int4
+COL:blobs.doc_obj.fk_doc::int4
+COL:blobs.doc_obj.fk_intended_reviewer::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_doc)_REFERENCES_blobs.doc_med(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_intended_reviewer)_REFERENCES_dem.staff(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:ref.icpc_chapter
+PK:ref.icpc_chapter.pk::integer
+COL:ref.icpc_chapter.description::text
+COL:ref.icpc_chapter.pk::int4
+COL:ref.icpc_chapter.chapter::bpchar
+TABLE:dem.staff
+PK:dem.staff.pk::integer
+COL:dem.staff.db_user::name
+COL:dem.staff.is_active::bool
+COL:dem.staff.comment::text
+COL:dem.staff.row_version::int4
+COL:dem.staff.fk_identity::int4
+COL:dem.staff.modified_when::timestamptz
+COL:dem.staff.short_alias::text
+COL:dem.staff.pk::int4
+COL:dem.staff.pk_audit::int4
+COL:dem.staff.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_identity)_REFERENCES_dem.identity(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:dem.lnk_identity2comm
+PK:dem.lnk_identity2comm.pk::integer
+COL:dem.lnk_identity2comm.comment::text
+COL:dem.lnk_identity2comm.url::text
+COL:dem.lnk_identity2comm.fk_identity::int4
+COL:dem.lnk_identity2comm.fk_address::int4
+COL:dem.lnk_identity2comm.pk::int4
+COL:dem.lnk_identity2comm.fk_type::int4
+COL:dem.lnk_identity2comm.is_confidential::bool
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_address)_REFERENCES_dem.address(id)_ON_UPDATE_SET_NULL_ON_DELETE_SET_NULL::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_identity)_REFERENCES_dem.identity(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_type)_REFERENCES_dem.enum_comm_types(pk)::active=true
+TABLE:clin.clin_diag
+PK:clin.clin_diag.pk::integer
+COL:clin.clin_diag.is_active::bool
+COL:clin.clin_diag.laterality::bpchar
+COL:clin.clin_diag.fk_narrative::int4
+COL:clin.clin_diag.clinically_relevant::bool
+COL:clin.clin_diag.is_definite::bool
+COL:clin.clin_diag.row_version::int4
+COL:clin.clin_diag.modified_when::timestamptz
+COL:clin.clin_diag.is_chronic::bool
+COL:clin.clin_diag.pk::int4
+COL:clin.clin_diag.pk_audit::int4
+COL:clin.clin_diag.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_narrative)_REFERENCES_clin.clin_narrative(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+TABLE:dem.address
+PK:dem.address.id::integer
+COL:dem.address.number::text
+COL:dem.address.subunit::text
+COL:dem.address.id::int4
+COL:dem.address.lat_lon::point
+COL:dem.address.aux_street::text
+COL:dem.address.id_street::int4
+COL:dem.address.addendum::text
+COL:dem.address.row_version::int4
+COL:dem.address.modified_when::timestamptz
+COL:dem.address.pk_audit::int4
+COL:dem.address.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(id_street)_REFERENCES_dem.street(id)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:dem.address_type
+PK:dem.address_type.id::integer
+COL:dem.address_type.name::text
+COL:dem.address_type.id::int4
+TABLE:clin.lnk_code2fhx
+PK:clin.lnk_code2fhx.pk::integer
+COL:clin.lnk_code2fhx.fk_generic_code::int4
+COL:clin.lnk_code2fhx.fk_item::int4
+COL:clin.lnk_code2fhx.pk_lnk_code2item::int4
+COL:clin.lnk_code2fhx.code_modifier::text
+COL:clin.lnk_code2fhx.row_version::int4
+COL:clin.lnk_code2fhx.modified_when::timestamptz
+COL:clin.lnk_code2fhx.pk::int4
+COL:clin.lnk_code2fhx.pk_audit::int4
+COL:clin.lnk_code2fhx.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_item)_REFERENCES_clin.family_history(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:i18n.keys
+PK:i18n.keys.pk::integer
+COL:i18n.keys.orig::text
+COL:i18n.keys.pk::int4
+TABLE:clin.soap_cat_ranks
+PK:clin.soap_cat_ranks.pk::integer
+COL:clin.soap_cat_ranks.pk::int4
+COL:clin.soap_cat_ranks.rank::int4
+COL:clin.soap_cat_ranks.soap_cat::bpchar
+TABLE:ref.papersizes
+PK:ref.papersizes.pk::integer
+COL:ref.papersizes.name::text
+COL:ref.papersizes.size::point
+COL:ref.papersizes.pk::int4
+TABLE:blobs.doc_med
+PK:blobs.doc_med.pk::integer
+COL:blobs.doc_med.fk_encounter::int4
+COL:blobs.doc_med.comment::text
+COL:blobs.doc_med.ext_ref::text
+COL:blobs.doc_med.row_version::int4
+COL:blobs.doc_med.clin_when::timestamptz
+COL:blobs.doc_med.modified_when::timestamptz
+COL:blobs.doc_med.fk_episode::int4
+COL:blobs.doc_med.pk::int4
+COL:blobs.doc_med.fk_type::int4
+COL:blobs.doc_med.pk_audit::int4
+COL:blobs.doc_med.fk_org_unit::int4
+COL:blobs.doc_med.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter)_REFERENCES_clin.encounter(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_org_unit)_REFERENCES_dem.org_unit(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_type)_REFERENCES_blobs.doc_type(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_episode)_REFERENCES_clin.episode(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:clin.health_issue
+PK:clin.health_issue.pk::integer
+COL:clin.health_issue.is_cause_of_death::bool
+COL:clin.health_issue.is_active::bool
+COL:clin.health_issue.fk_encounter::int4
+COL:clin.health_issue.age_noted::interval
+COL:clin.health_issue.description::text
+COL:clin.health_issue.laterality::varchar
+COL:clin.health_issue.grouping::text
+COL:clin.health_issue.summary::text
+COL:clin.health_issue.clinically_relevant::bool
+COL:clin.health_issue.row_version::int4
+COL:clin.health_issue.modified_when::timestamptz
+COL:clin.health_issue.pk::int4
+COL:clin.health_issue.diagnostic_certainty_classification::text
+COL:clin.health_issue.pk_audit::int4
+COL:clin.health_issue.is_confidential::bool
+COL:clin.health_issue.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter)_REFERENCES_clin.encounter(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+TABLE:dem.inbox_item_type
+PK:dem.inbox_item_type.pk::integer
+COL:dem.inbox_item_type.description::text
+COL:dem.inbox_item_type.fk_inbox_item_category::int4
+COL:dem.inbox_item_type.row_version::int4
+COL:dem.inbox_item_type.modified_when::timestamptz
+COL:dem.inbox_item_type.pk::int4
+COL:dem.inbox_item_type.is_user::bool
+COL:dem.inbox_item_type.pk_audit::int4
+COL:dem.inbox_item_type.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_inbox_item_category)_REFERENCES_dem.inbox_item_category(pk)::active=true
+TABLE:clin.allergy_state
+PK:clin.allergy_state.pk::integer
+COL:clin.allergy_state.has_allergy::int4
+COL:clin.allergy_state.fk_encounter::int4
+COL:clin.allergy_state.comment::text
+COL:clin.allergy_state.last_confirmed::timestamptz
+COL:clin.allergy_state.row_version::int4
+COL:clin.allergy_state.modified_when::timestamptz
+COL:clin.allergy_state.pk::int4
+COL:clin.allergy_state.pk_audit::int4
+COL:clin.allergy_state.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter)_REFERENCES_clin.encounter(pk)::active=true
+TABLE:ref.consumable_substance
+PK:ref.consumable_substance.pk::integer
+COL:ref.consumable_substance.amount::numeric
+COL:ref.consumable_substance.description::text
+COL:ref.consumable_substance.atc_code::text
+COL:ref.consumable_substance.row_version::int4
+COL:ref.consumable_substance.modified_when::timestamptz
+COL:ref.consumable_substance.pk::int4
+COL:ref.consumable_substance.unit::text
+COL:ref.consumable_substance.pk_audit::int4
+COL:ref.consumable_substance.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+TABLE:clin.incoming_data_unmatchable
+PK:clin.incoming_data_unmatchable.pk::integer
+COL:clin.incoming_data_unmatchable.lastnames::text
+COL:clin.incoming_data_unmatchable.external_data_id::text
+COL:clin.incoming_data_unmatchable.type::text
+COL:clin.incoming_data_unmatchable.requestor::text
+COL:clin.incoming_data_unmatchable.gender::text
+COL:clin.incoming_data_unmatchable.firstnames::text
+COL:clin.incoming_data_unmatchable.data::bytea
+COL:clin.incoming_data_unmatchable.row_version::int4
+COL:clin.incoming_data_unmatchable.modified_when::timestamptz
+COL:clin.incoming_data_unmatchable.other_info::text
+COL:clin.incoming_data_unmatchable.pk::int4
+COL:clin.incoming_data_unmatchable.pk_audit::int4
+COL:clin.incoming_data_unmatchable.fk_patient_candidates::_int4
+COL:clin.incoming_data_unmatchable.modified_by::name
+COL:clin.incoming_data_unmatchable.request_id::text
+COL:clin.incoming_data_unmatchable.postcode::text
+COL:clin.incoming_data_unmatchable.dob::date
+COL:clin.incoming_data_unmatchable.fk_identity_disambiguated::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+TABLE:dem.marital_status
+PK:dem.marital_status.pk::integer
+COL:dem.marital_status.name::text
+COL:dem.marital_status.pk::int4
+TABLE:clin.vaccination_course_constraint
+PK:clin.vaccination_course_constraint.pk::integer
+COL:clin.vaccination_course_constraint.description::text
+COL:clin.vaccination_course_constraint.row_version::int4
+COL:clin.vaccination_course_constraint.modified_when::timestamptz
+COL:clin.vaccination_course_constraint.pk::int4
+COL:clin.vaccination_course_constraint.pk_audit::int4
+COL:clin.vaccination_course_constraint.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+TABLE:clin.lnk_code2h_issue
+PK:clin.lnk_code2h_issue.pk::integer
+COL:clin.lnk_code2h_issue.fk_generic_code::int4
+COL:clin.lnk_code2h_issue.fk_item::int4
+COL:clin.lnk_code2h_issue.pk_lnk_code2item::int4
+COL:clin.lnk_code2h_issue.code_modifier::text
+COL:clin.lnk_code2h_issue.row_version::int4
+COL:clin.lnk_code2h_issue.modified_when::timestamptz
+COL:clin.lnk_code2h_issue.pk::int4
+COL:clin.lnk_code2h_issue.pk_audit::int4
+COL:clin.lnk_code2h_issue.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_item)_REFERENCES_clin.health_issue(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:clin.form_instances
+PK:clin.form_instances.pk::integer
+COL:clin.form_instances.fk_encounter::int4
+COL:clin.form_instances.fk_form_def::int4
+COL:clin.form_instances.narrative::text
+COL:clin.form_instances.form_name::text
+COL:clin.form_instances.row_version::int4
+COL:clin.form_instances.clin_when::timestamptz
+COL:clin.form_instances.modified_when::timestamptz
+COL:clin.form_instances.pk_item::int4
+COL:clin.form_instances.soap_cat::text
+COL:clin.form_instances.fk_episode::int4
+COL:clin.form_instances.pk::int4
+COL:clin.form_instances.pk_audit::int4
+COL:clin.form_instances.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter)_REFERENCES_clin.encounter(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_form_def)_REFERENCES_ref.paperwork_templates(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_episode)_REFERENCES_clin.episode(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:ref.atc_staging
+COL:ref.atc_staging.name::text
+COL:ref.atc_staging.adro::text
+COL:ref.atc_staging.comment::text
+COL:ref.atc_staging.atc::text
+COL:ref.atc_staging.ddd::text
+COL:ref.atc_staging.unit::text
+TABLE:clin.lnk_pat2vaccination_course
+PK:clin.lnk_pat2vaccination_course.pk::integer
+COL:clin.lnk_pat2vaccination_course.fk_course::int4
+COL:clin.lnk_pat2vaccination_course.fk_patient::int4
+COL:clin.lnk_pat2vaccination_course.row_version::int4
+COL:clin.lnk_pat2vaccination_course.modified_when::timestamptz
+COL:clin.lnk_pat2vaccination_course.pk::int4
+COL:clin.lnk_pat2vaccination_course.pk_audit::int4
+COL:clin.lnk_pat2vaccination_course.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_course)_REFERENCES_clin.vaccination_course(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_patient)_REFERENCES_clin.patient(fk_identity)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:ref.keyword_expansion
+PK:ref.keyword_expansion.pk::integer
+COL:ref.keyword_expansion.fk_staff::int4
+COL:ref.keyword_expansion.binary_data::bytea
+COL:ref.keyword_expansion.encrypted::bool
+COL:ref.keyword_expansion.keyword::text
+COL:ref.keyword_expansion.textual_data::text
+COL:ref.keyword_expansion.owner::text
+COL:ref.keyword_expansion.pk::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_staff)_REFERENCES_dem.staff(pk)::active=true
+TABLE:clin.lnk_code2procedure
+PK:clin.lnk_code2procedure.pk::integer
+COL:clin.lnk_code2procedure.fk_generic_code::int4
+COL:clin.lnk_code2procedure.fk_item::int4
+COL:clin.lnk_code2procedure.pk_lnk_code2item::int4
+COL:clin.lnk_code2procedure.code_modifier::text
+COL:clin.lnk_code2procedure.row_version::int4
+COL:clin.lnk_code2procedure.modified_when::timestamptz
+COL:clin.lnk_code2procedure.pk::int4
+COL:clin.lnk_code2procedure.pk_audit::int4
+COL:clin.lnk_code2procedure.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_item)_REFERENCES_clin.procedure(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:clin.lnk_code2tst_pnl
+PK:clin.lnk_code2tst_pnl.pk::integer
+COL:clin.lnk_code2tst_pnl.fk_generic_code::int4
+COL:clin.lnk_code2tst_pnl.fk_item::int4
+COL:clin.lnk_code2tst_pnl.pk_lnk_code2item::int4
+COL:clin.lnk_code2tst_pnl.code_modifier::text
+COL:clin.lnk_code2tst_pnl.row_version::int4
+COL:clin.lnk_code2tst_pnl.modified_when::timestamptz
+COL:clin.lnk_code2tst_pnl.pk::int4
+COL:clin.lnk_code2tst_pnl.pk_audit::int4
+COL:clin.lnk_code2tst_pnl.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_item)_REFERENCES_clin.test_panel(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:dem.street
+PK:dem.street.id::integer
+COL:dem.street.name::text
+COL:dem.street.id::int4
+COL:dem.street.lat_lon::point
+COL:dem.street.suburb::text
+COL:dem.street.id_urb::int4
+COL:dem.street.row_version::int4
+COL:dem.street.modified_when::timestamptz
+COL:dem.street.pk_audit::int4
+COL:dem.street.modified_by::name
+COL:dem.street.postcode::text
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(id_urb)_REFERENCES_dem.urb(id)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:ref.auto_hint
+PK:ref.auto_hint.pk::integer
+COL:ref.auto_hint.hint::text
+COL:ref.auto_hint.title::text
+COL:ref.auto_hint.lang::text
+COL:ref.auto_hint.source::text
+COL:ref.auto_hint.is_active::bool
+COL:ref.auto_hint.query::text
+COL:ref.auto_hint.row_version::int4
+COL:ref.auto_hint.recommendation_query::text
+COL:ref.auto_hint.url::text
+COL:ref.auto_hint.modified_when::timestamptz
+COL:ref.auto_hint.pk::int4
+COL:ref.auto_hint.pk_audit::int4
+COL:ref.auto_hint.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+TABLE:clin.clin_aux_note
+PK:clin.clin_aux_note.pk::integer
+COL:clin.clin_aux_note.fk_encounter::int4
+COL:clin.clin_aux_note.narrative::text
+COL:clin.clin_aux_note.row_version::int4
+COL:clin.clin_aux_note.clin_when::timestamptz
+COL:clin.clin_aux_note.modified_when::timestamptz
+COL:clin.clin_aux_note.pk_item::int4
+COL:clin.clin_aux_note.soap_cat::text
+COL:clin.clin_aux_note.fk_episode::int4
+COL:clin.clin_aux_note.pk::int4
+COL:clin.clin_aux_note.pk_audit::int4
+COL:clin.clin_aux_note.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter)_REFERENCES_clin.encounter(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_episode)_REFERENCES_clin.episode(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:cfg.cfg_str_array
+PK:cfg.cfg_str_array.pk::integer
+COL:cfg.cfg_str_array.fk_item::int4
+COL:cfg.cfg_str_array.pk::int4
+COL:cfg.cfg_str_array.value::_text
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_item)_REFERENCES_cfg.cfg_item(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:ref.code_thesaurus_root
+PK:ref.code_thesaurus_root.pk_thesaurus::integer
+COL:ref.code_thesaurus_root.synonym::text
+COL:ref.code_thesaurus_root.fk_code::int4
+COL:ref.code_thesaurus_root.pk_thesaurus::int4
+TABLE:dem.names
+PK:dem.names.id::integer
+COL:dem.names.lastnames::text
+COL:dem.names.active::bool
+COL:dem.names.comment::text
+COL:dem.names.id::int4
+COL:dem.names.firstnames::text
+COL:dem.names.preferred::text
+COL:dem.names.id_identity::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(id_identity)_REFERENCES_dem.identity(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:dem.org
+PK:dem.org.pk::integer
+COL:dem.org.fk_category::int4
+COL:dem.org.fk_data_source::int4
+COL:dem.org.description::text
+COL:dem.org.row_version::int4
+COL:dem.org.modified_when::timestamptz
+COL:dem.org.pk::int4
+COL:dem.org.pk_audit::int4
+COL:dem.org.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_data_source)_REFERENCES_ref.data_source(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_category)_REFERENCES_dem.org_category(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:dem.lnk_org_unit2comm
+PK:dem.lnk_org_unit2comm.pk::integer
+COL:dem.lnk_org_unit2comm.comment::text
+COL:dem.lnk_org_unit2comm.row_version::int4
+COL:dem.lnk_org_unit2comm.url::text
+COL:dem.lnk_org_unit2comm.modified_when::timestamptz
+COL:dem.lnk_org_unit2comm.pk::int4
+COL:dem.lnk_org_unit2comm.fk_type::int4
+COL:dem.lnk_org_unit2comm.pk_audit::int4
+COL:dem.lnk_org_unit2comm.fk_org_unit::int4
+COL:dem.lnk_org_unit2comm.is_confidential::bool
+COL:dem.lnk_org_unit2comm.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_org_unit)_REFERENCES_dem.org_unit(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_type)_REFERENCES_dem.enum_comm_types(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:bill.bill_item
+PK:bill.bill_item.pk::integer
+COL:bill.bill_item.currency::text
+COL:bill.bill_item.fk_provider::int4
+COL:bill.bill_item.fk_encounter::int4
+COL:bill.bill_item.amount_multiplier::numeric
+COL:bill.bill_item.description::text
+COL:bill.bill_item.net_amount_per_unit::numeric
+COL:bill.bill_item.fk_bill::int4
+COL:bill.bill_item.row_version::int4
+COL:bill.bill_item.fk_billable::int4
+COL:bill.bill_item.modified_when::timestamptz
+COL:bill.bill_item.unit_count::int4
+COL:bill.bill_item.pk::int4
+COL:bill.bill_item.date_to_bill::date
+COL:bill.bill_item.pk_audit::int4
+COL:bill.bill_item.modified_by::name
+COL:bill.bill_item.status::text
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_billable)_REFERENCES_ref.billable(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter)_REFERENCES_clin.encounter(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_bill)_REFERENCES_bill.bill(pk)_ON_UPDATE_CASCADE_ON_DELETE_SET_NULL_DEFERRABLE_INITIALLY_DEFERRED::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_provider)_REFERENCES_dem.staff(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:cfg.cfg_type_enum
+COL:cfg.cfg_type_enum.name::text
+TABLE:dem.lnk_identity2ext_id
+PK:dem.lnk_identity2ext_id.id::integer
+COL:dem.lnk_identity2ext_id.fk_origin::int4
+COL:dem.lnk_identity2ext_id.comment::text
+COL:dem.lnk_identity2ext_id.id::int4
+COL:dem.lnk_identity2ext_id.row_version::int4
+COL:dem.lnk_identity2ext_id.modified_when::timestamptz
+COL:dem.lnk_identity2ext_id.pk_audit::int4
+COL:dem.lnk_identity2ext_id.modified_by::name
+COL:dem.lnk_identity2ext_id.id_identity::int4
+COL:dem.lnk_identity2ext_id.external_id::text
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_origin)_REFERENCES_dem.enum_ext_id_types(pk)::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(id_identity)_REFERENCES_dem.identity(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:clin.lnk_code2item_root
+PK:clin.lnk_code2item_root.pk_lnk_code2item::integer
+COL:clin.lnk_code2item_root.fk_generic_code::int4
+COL:clin.lnk_code2item_root.fk_item::int4
+COL:clin.lnk_code2item_root.pk_lnk_code2item::int4
+COL:clin.lnk_code2item_root.code_modifier::text
+COL:clin.lnk_code2item_root.row_version::int4
+COL:clin.lnk_code2item_root.modified_when::timestamptz
+COL:clin.lnk_code2item_root.pk_audit::int4
+COL:clin.lnk_code2item_root.modified_by::name
+TABLE:clin.waiting_list
+PK:clin.waiting_list.pk::integer
+COL:clin.waiting_list.area::text
+COL:clin.waiting_list.comment::text
+COL:clin.waiting_list.registered::timestamptz
+COL:clin.waiting_list.list_position::int4
+COL:clin.waiting_list.fk_patient::int4
+COL:clin.waiting_list.row_version::int4
+COL:clin.waiting_list.modified_when::timestamptz
+COL:clin.waiting_list.pk::int4
+COL:clin.waiting_list.urgency::int4
+COL:clin.waiting_list.pk_audit::int4
+COL:clin.waiting_list.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_patient)_REFERENCES_dem.identity(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:clin.episode
+PK:clin.episode.pk::integer
+COL:clin.episode.fk_encounter::int4
+COL:clin.episode.fk_health_issue::int4
+COL:clin.episode.description::text
+COL:clin.episode.summary::text
+COL:clin.episode.row_version::int4
+COL:clin.episode.modified_when::timestamptz
+COL:clin.episode.pk::int4
+COL:clin.episode.diagnostic_certainty_classification::text
+COL:clin.episode.pk_audit::int4
+COL:clin.episode.modified_by::name
+COL:clin.episode.is_open::bool
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter)_REFERENCES_clin.encounter(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_health_issue)_REFERENCES_clin.health_issue(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:clin.lab_request
+PK:clin.lab_request.pk::integer
+COL:clin.lab_request.request_status::text
+COL:clin.lab_request.lab_request_id::text
+COL:clin.lab_request.fk_encounter::int4
+COL:clin.lab_request.is_pending::bool
+COL:clin.lab_request.ordered_service::text
+COL:clin.lab_request.narrative::text
+COL:clin.lab_request.fk_test_org::int4
+COL:clin.lab_request.results_reported_when::timestamptz
+COL:clin.lab_request.fk_requestor::int4
+COL:clin.lab_request.row_version::int4
+COL:clin.lab_request.clin_when::timestamptz
+COL:clin.lab_request.modified_when::timestamptz
+COL:clin.lab_request.pk_item::int4
+COL:clin.lab_request.soap_cat::text
+COL:clin.lab_request.fk_episode::int4
+COL:clin.lab_request.lab_rxd_when::timestamptz
+COL:clin.lab_request.pk::int4
+COL:clin.lab_request.note_test_org::text
+COL:clin.lab_request.pk_audit::int4
+COL:clin.lab_request.modified_by::name
+COL:clin.lab_request.request_id::text
+COL:clin.lab_request.diagnostic_service_section::text
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter)_REFERENCES_clin.encounter(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_requestor)_REFERENCES_dem.identity(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_test_org)_REFERENCES_clin.test_org(pk)::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_episode)_REFERENCES_clin.episode(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:clin.fhx_relation_type
+PK:clin.fhx_relation_type.pk::integer
+COL:clin.fhx_relation_type.is_genetic::bool
+COL:clin.fhx_relation_type.description::text
+COL:clin.fhx_relation_type.row_version::int4
+COL:clin.fhx_relation_type.modified_when::timestamptz
+COL:clin.fhx_relation_type.pk::int4
+COL:clin.fhx_relation_type.pk_audit::int4
+COL:clin.fhx_relation_type.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+TABLE:cfg.cfg_item
+PK:cfg.cfg_item.pk::integer
+COL:cfg.cfg_item.fk_template::int4
+COL:cfg.cfg_item.workplace::text
+COL:cfg.cfg_item.owner::name
+COL:cfg.cfg_item.pk::int4
+COL:cfg.cfg_item.cookie::text
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_template)_REFERENCES_cfg.cfg_template(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:clin.lnk_code2episode
+PK:clin.lnk_code2episode.pk::integer
+COL:clin.lnk_code2episode.fk_generic_code::int4
+COL:clin.lnk_code2episode.fk_item::int4
+COL:clin.lnk_code2episode.pk_lnk_code2item::int4
+COL:clin.lnk_code2episode.code_modifier::text
+COL:clin.lnk_code2episode.row_version::int4
+COL:clin.lnk_code2episode.modified_when::timestamptz
+COL:clin.lnk_code2episode.pk::int4
+COL:clin.lnk_code2episode.pk_audit::int4
+COL:clin.lnk_code2episode.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_item)_REFERENCES_clin.episode(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:ref.form_types
+PK:ref.form_types.pk::integer
+COL:ref.form_types.name::text
+COL:ref.form_types.pk::int4
+TABLE:clin.vaccination_definition
+PK:clin.vaccination_definition.id::integer
+COL:clin.vaccination_definition.fk_course::int4
+COL:clin.vaccination_definition.seq_no::int4
+COL:clin.vaccination_definition.min_interval::interval
+COL:clin.vaccination_definition.comment::text
+COL:clin.vaccination_definition.id::int4
+COL:clin.vaccination_definition.max_age_due::interval
+COL:clin.vaccination_definition.row_version::int4
+COL:clin.vaccination_definition.modified_when::timestamptz
+COL:clin.vaccination_definition.min_age_due::interval
+COL:clin.vaccination_definition.pk_audit::int4
+COL:clin.vaccination_definition.modified_by::name
+COL:clin.vaccination_definition.is_booster::bool
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_course)_REFERENCES_clin.vaccination_course(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:dem.inbox_item_category
+PK:dem.inbox_item_category.pk::integer
+COL:dem.inbox_item_category.description::text
+COL:dem.inbox_item_category.row_version::int4
+COL:dem.inbox_item_category.modified_when::timestamptz
+COL:dem.inbox_item_category.pk::int4
+COL:dem.inbox_item_category.is_user::bool
+COL:dem.inbox_item_category.pk_audit::int4
+COL:dem.inbox_item_category.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+TABLE:dem.lnk_job2person
+PK:dem.lnk_job2person.pk::integer
+COL:dem.lnk_job2person.row_version::int4
+COL:dem.lnk_job2person.fk_occupation::int4
+COL:dem.lnk_job2person.fk_identity::int4
+COL:dem.lnk_job2person.modified_when::timestamptz
+COL:dem.lnk_job2person.pk::int4
+COL:dem.lnk_job2person.activities::text
+COL:dem.lnk_job2person.pk_audit::int4
+COL:dem.lnk_job2person.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_occupation)_REFERENCES_dem.occupation(id)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_identity)_REFERENCES_dem.identity(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:clin.lnk_code2aoe
+PK:clin.lnk_code2aoe.pk::integer
+COL:clin.lnk_code2aoe.fk_generic_code::int4
+COL:clin.lnk_code2aoe.fk_item::int4
+COL:clin.lnk_code2aoe.pk_lnk_code2item::int4
+COL:clin.lnk_code2aoe.code_modifier::text
+COL:clin.lnk_code2aoe.row_version::int4
+COL:clin.lnk_code2aoe.modified_when::timestamptz
+COL:clin.lnk_code2aoe.pk::int4
+COL:clin.lnk_code2aoe.pk_audit::int4
+COL:clin.lnk_code2aoe.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_item)_REFERENCES_clin.encounter(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:dem.country
+PK:dem.country.id::integer
+COL:dem.country.name::text
+COL:dem.country.deprecated::date
+COL:dem.country.id::int4
+COL:dem.country.code::bpchar
+TABLE:clin.lnk_code2narrative
+PK:clin.lnk_code2narrative.pk::integer
+COL:clin.lnk_code2narrative.fk_generic_code::int4
+COL:clin.lnk_code2narrative.fk_item::int4
+COL:clin.lnk_code2narrative.pk_lnk_code2item::int4
+COL:clin.lnk_code2narrative.code_modifier::text
+COL:clin.lnk_code2narrative.row_version::int4
+COL:clin.lnk_code2narrative.modified_when::timestamptz
+COL:clin.lnk_code2narrative.pk::int4
+COL:clin.lnk_code2narrative.pk_audit::int4
+COL:clin.lnk_code2narrative.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_item)_REFERENCES_clin.clin_narrative(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:clin.lnk_vaccine2inds
+PK:clin.lnk_vaccine2inds.id::integer
+COL:clin.lnk_vaccine2inds.id::int4
+COL:clin.lnk_vaccine2inds.fk_vaccine::int4
+COL:clin.lnk_vaccine2inds.fk_indication::int4
+COL:clin.lnk_vaccine2inds.row_version::int4
+COL:clin.lnk_vaccine2inds.modified_when::timestamptz
+COL:clin.lnk_vaccine2inds.pk_audit::int4
+COL:clin.lnk_vaccine2inds.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_vaccine)_REFERENCES_clin.vaccine(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_indication)_REFERENCES_clin.vacc_indication(id)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:bill.lnk_enc_type2billable
+PK:bill.lnk_enc_type2billable.pk::integer
+COL:bill.lnk_enc_type2billable.fk_encounter_type::int4
+COL:bill.lnk_enc_type2billable.fk_billable::int4
+COL:bill.lnk_enc_type2billable.pk::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_billable)_REFERENCES_ref.billable(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter_type)_REFERENCES_clin.encounter_type(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:clin.lnk_code2rfe
+PK:clin.lnk_code2rfe.pk::integer
+COL:clin.lnk_code2rfe.fk_generic_code::int4
+COL:clin.lnk_code2rfe.fk_item::int4
+COL:clin.lnk_code2rfe.pk_lnk_code2item::int4
+COL:clin.lnk_code2rfe.code_modifier::text
+COL:clin.lnk_code2rfe.row_version::int4
+COL:clin.lnk_code2rfe.modified_when::timestamptz
+COL:clin.lnk_code2rfe.pk::int4
+COL:clin.lnk_code2rfe.pk_audit::int4
+COL:clin.lnk_code2rfe.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_item)_REFERENCES_clin.encounter(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:ref.icd10
+PK:ref.icd10.pk::integer
+COL:ref.icd10.pk_coding_system::int4
+COL:ref.icd10.fk_data_source::int4
+COL:ref.icd10.comment::text
+COL:ref.icd10.term::text
+COL:ref.icd10.code::text
+COL:ref.icd10.aux_code::text
+COL:ref.icd10.star_code::text
+COL:ref.icd10.pk::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_data_source)_REFERENCES_ref.data_source(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:clin.hospital_stay
+PK:clin.hospital_stay.pk::integer
+COL:clin.hospital_stay.fk_encounter::int4
+COL:clin.hospital_stay.discharge::timestamptz
+COL:clin.hospital_stay.narrative::text
+COL:clin.hospital_stay.row_version::int4
+COL:clin.hospital_stay.clin_when::timestamptz
+COL:clin.hospital_stay.modified_when::timestamptz
+COL:clin.hospital_stay.pk_item::int4
+COL:clin.hospital_stay.soap_cat::text
+COL:clin.hospital_stay.fk_episode::int4
+COL:clin.hospital_stay.pk::int4
+COL:clin.hospital_stay.pk_audit::int4
+COL:clin.hospital_stay.fk_org_unit::int4
+COL:clin.hospital_stay.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter)_REFERENCES_clin.encounter(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_org_unit)_REFERENCES_dem.org_unit(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_episode)_REFERENCES_clin.episode(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:ref.atc
+PK:ref.atc.pk::integer
+COL:ref.atc.pk_coding_system::int4
+COL:ref.atc.fk_data_source::int4
+COL:ref.atc.comment::text
+COL:ref.atc.term::text
+COL:ref.atc.code::text
+COL:ref.atc.administration_route::text
+COL:ref.atc.pk::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_data_source)_REFERENCES_ref.data_source(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:clin._enum_allergy_type
+PK:clin._enum_allergy_type.pk::integer
+COL:clin._enum_allergy_type.value::text
+COL:clin._enum_allergy_type.pk::int4
+TABLE:clin.clin_narrative
+PK:clin.clin_narrative.pk::integer
+COL:clin.clin_narrative.fk_encounter::int4
+COL:clin.clin_narrative.narrative::text
+COL:clin.clin_narrative.row_version::int4
+COL:clin.clin_narrative.clin_when::timestamptz
+COL:clin.clin_narrative.modified_when::timestamptz
+COL:clin.clin_narrative.pk_item::int4
+COL:clin.clin_narrative.soap_cat::text
+COL:clin.clin_narrative.fk_episode::int4
+COL:clin.clin_narrative.pk::int4
+COL:clin.clin_narrative.pk_audit::int4
+COL:clin.clin_narrative.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter)_REFERENCES_clin.encounter(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_episode)_REFERENCES_clin.episode(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:ref.icpc_thesaurus
+PK:ref.icpc_thesaurus.pk::integer
+COL:ref.icpc_thesaurus.synonym::text
+COL:ref.icpc_thesaurus.fk_code::int4
+COL:ref.icpc_thesaurus.pk::int4
+COL:ref.icpc_thesaurus.pk_thesaurus::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_code)_REFERENCES_ref.icpc(pk_coding_system)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:cfg.cfg_numeric
+PK:cfg.cfg_numeric.pk::integer
+COL:cfg.cfg_numeric.fk_item::int4
+COL:cfg.cfg_numeric.value::numeric
+COL:cfg.cfg_numeric.pk::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_item)_REFERENCES_cfg.cfg_item(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:ref.document_type
+PK:ref.document_type.pk::integer
+COL:ref.document_type.description::text
+COL:ref.document_type.scope::text
+COL:ref.document_type.pk::int4
+TABLE:dem.lnk_person_org_address
+PK:dem.lnk_person_org_address.id::integer
+COL:dem.lnk_person_org_address.id::int4
+COL:dem.lnk_person_org_address.id_type::int4
+COL:dem.lnk_person_org_address.address_source::text
+COL:dem.lnk_person_org_address.id_address::int4
+COL:dem.lnk_person_org_address.id_org::int4
+COL:dem.lnk_person_org_address.id_identity::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(id_identity)_REFERENCES_dem.identity(pk)::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(id_address)_REFERENCES_dem.address(id)::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(id_type)_REFERENCES_dem.address_type(id)::active=true
+TABLE:dem.region
+PK:dem.region.pk::integer
+COL:dem.region.name::text
+COL:dem.region.code::text
+COL:dem.region.row_version::int4
+COL:dem.region.modified_when::timestamptz
+COL:dem.region.pk::int4
+COL:dem.region.pk_audit::int4
+COL:dem.region.country::bpchar
+COL:dem.region.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(country)_REFERENCES_dem.country(code)::active=true
+TABLE:blobs.doc_desc
+PK:blobs.doc_desc.pk::integer
+COL:blobs.doc_desc.row_version::int4
+COL:blobs.doc_desc.modified_when::timestamptz
+COL:blobs.doc_desc.pk::int4
+COL:blobs.doc_desc.fk_doc::int4
+COL:blobs.doc_desc.pk_audit::int4
+COL:blobs.doc_desc.modified_by::name
+COL:blobs.doc_desc.text::text
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_doc)_REFERENCES_blobs.doc_med(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:i18n.translations
+PK:i18n.translations.pk::integer
+COL:i18n.translations.lang::text
+COL:i18n.translations.orig::text
+COL:i18n.translations.trans::text
+COL:i18n.translations.pk::int4
+TABLE:clin.clin_root_item
+PK:clin.clin_root_item.pk_item::integer
+COL:clin.clin_root_item.fk_encounter::int4
+COL:clin.clin_root_item.narrative::text
+COL:clin.clin_root_item.row_version::int4
+COL:clin.clin_root_item.clin_when::timestamptz
+COL:clin.clin_root_item.modified_when::timestamptz
+COL:clin.clin_root_item.pk_item::int4
+COL:clin.clin_root_item.soap_cat::text
+COL:clin.clin_root_item.fk_episode::int4
+COL:clin.clin_root_item.pk_audit::int4
+COL:clin.clin_root_item.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter)_REFERENCES_clin.encounter(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_episode)_REFERENCES_clin.episode(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:dem.relation_types
+PK:dem.relation_types.id::integer
+COL:dem.relation_types.id::int4
+COL:dem.relation_types.description::text
+COL:dem.relation_types.biological::bool
+COL:dem.relation_types.inverse::int4
+COL:dem.relation_types.row_version::int4
+COL:dem.relation_types.modified_when::timestamptz
+COL:dem.relation_types.biol_verified::bool
+COL:dem.relation_types.pk_audit::int4
+COL:dem.relation_types.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(inverse)_REFERENCES_dem.relation_types(id)::active=true
+TABLE:clin.lnk_tst2norm
+PK:clin.lnk_tst2norm.id::integer
+COL:clin.lnk_tst2norm.id_test::int4
+COL:clin.lnk_tst2norm.id::int4
+COL:clin.lnk_tst2norm.row_version::int4
+COL:clin.lnk_tst2norm.modified_when::timestamptz
+COL:clin.lnk_tst2norm.pk_audit::int4
+COL:clin.lnk_tst2norm.modified_by::name
+COL:clin.lnk_tst2norm.id_norm::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(id_test)_REFERENCES_clin.test_type(pk)::active=true
+TABLE:dem.lnk_person2relative
+PK:dem.lnk_person2relative.id::integer
+COL:dem.lnk_person2relative.started::date
+COL:dem.lnk_person2relative.id::int4
+COL:dem.lnk_person2relative.id_relation_type::int4
+COL:dem.lnk_person2relative.id_relative::int4
+COL:dem.lnk_person2relative.row_version::int4
+COL:dem.lnk_person2relative.modified_when::timestamptz
+COL:dem.lnk_person2relative.ended::date
+COL:dem.lnk_person2relative.pk_audit::int4
+COL:dem.lnk_person2relative.modified_by::name
+COL:dem.lnk_person2relative.id_identity::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(id_identity)_REFERENCES_dem.identity(pk)::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(id_relative)_REFERENCES_dem.identity(pk)::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(id_relation_type)_REFERENCES_dem.relation_types(id)::active=true
+TABLE:ref.other_code
+PK:ref.other_code.pk::integer
+COL:ref.other_code.pk_coding_system::int4
+COL:ref.other_code.fk_data_source::int4
+COL:ref.other_code.comment::text
+COL:ref.other_code.term::text
+COL:ref.other_code.code::text
+COL:ref.other_code.pk::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_data_source)_REFERENCES_ref.data_source(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:ref.data_source
+PK:ref.data_source.pk::integer
+COL:ref.data_source.lang::text
+COL:ref.data_source.source::text
+COL:ref.data_source.description::text
+COL:ref.data_source.name_long::text
+COL:ref.data_source.name_short::text
+COL:ref.data_source.row_version::int4
+COL:ref.data_source.modified_when::timestamptz
+COL:ref.data_source.version::text
+COL:ref.data_source.pk::int4
+COL:ref.data_source.pk_audit::int4
+COL:ref.data_source.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+TABLE:ref.paperwork_templates
+PK:ref.paperwork_templates.pk::integer
+COL:ref.paperwork_templates.gnumed_revision::float8
+COL:ref.paperwork_templates.filename::text
+COL:ref.paperwork_templates.instance_type::text
+COL:ref.paperwork_templates.fk_template_type::int4
+COL:ref.paperwork_templates.in_use::bool
+COL:ref.paperwork_templates.name_long::text
+COL:ref.paperwork_templates.data::bytea
+COL:ref.paperwork_templates.name_short::text
+COL:ref.paperwork_templates.row_version::int4
+COL:ref.paperwork_templates.modified_when::timestamptz
+COL:ref.paperwork_templates.edit_after_substitution::bool
+COL:ref.paperwork_templates.pk::int4
+COL:ref.paperwork_templates.external_version::text
+COL:ref.paperwork_templates.pk_audit::int4
+COL:ref.paperwork_templates.engine::text
+COL:ref.paperwork_templates.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_template_type)_REFERENCES_ref.form_types(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:dem.enum_ext_id_types
+PK:dem.enum_ext_id_types.pk::integer
+COL:dem.enum_ext_id_types.name::text
+COL:dem.enum_ext_id_types.issuer::text
+COL:dem.enum_ext_id_types.pk::int4
+TABLE:clin.patient
+PK:clin.patient.pk::integer
+COL:clin.patient.row_version::int4
+COL:clin.patient.edc::date
+COL:clin.patient.fk_identity::int4
+COL:clin.patient.modified_when::timestamptz
+COL:clin.patient.pk::int4
+COL:clin.patient.pk_audit::int4
+COL:clin.patient.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_identity)_REFERENCES_dem.identity(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:clin.test_result
+PK:clin.test_result.pk::integer
+COL:clin.test_result.source_data::text
+COL:clin.test_result.val_grouping::text
+COL:clin.test_result.fk_encounter::int4
+COL:clin.test_result.abnormality_indicator::text
+COL:clin.test_result.val_unit::text
+COL:clin.test_result.norm_ref_group::text
+COL:clin.test_result.val_num::numeric
+COL:clin.test_result.val_target_range::text
+COL:clin.test_result.narrative::text
+COL:clin.test_result.fk_request::int4
+COL:clin.test_result.val_target_min::numeric
+COL:clin.test_result.val_target_max::numeric
+COL:clin.test_result.val_normal_max::numeric
+COL:clin.test_result.row_version::int4
+COL:clin.test_result.clin_when::timestamptz
+COL:clin.test_result.val_alpha::text
+COL:clin.test_result.modified_when::timestamptz
+COL:clin.test_result.pk_item::int4
+COL:clin.test_result.val_normal_min::numeric
+COL:clin.test_result.soap_cat::text
+COL:clin.test_result.fk_episode::int4
+COL:clin.test_result.material_detail::text
+COL:clin.test_result.pk::int4
+COL:clin.test_result.note_test_org::text
+COL:clin.test_result.fk_type::int4
+COL:clin.test_result.val_normal_range::text
+COL:clin.test_result.pk_audit::int4
+COL:clin.test_result.modified_by::name
+COL:clin.test_result.material::text
+COL:clin.test_result.status::text
+COL:clin.test_result.fk_intended_reviewer::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter)_REFERENCES_clin.encounter(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_type)_REFERENCES_clin.test_type(pk)::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_request)_REFERENCES_clin.lab_request(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_intended_reviewer)_REFERENCES_dem.staff(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_episode)_REFERENCES_clin.episode(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:ref.ops
+PK:ref.ops.pk::integer
+COL:ref.ops.pk_coding_system::int4
+COL:ref.ops.requires_laterality::bool
+COL:ref.ops.fk_data_source::int4
+COL:ref.ops.comment::text
+COL:ref.ops.term::text
+COL:ref.ops.code::text
+COL:ref.ops.pk::int4
+COL:ref.ops.second_code::text
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_data_source)_REFERENCES_ref.data_source(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:clin.substance_intake
+PK:clin.substance_intake.pk::integer
+COL:clin.substance_intake.fk_encounter::int4
+COL:clin.substance_intake.duration::interval
+COL:clin.substance_intake.discontinue_reason::text
+COL:clin.substance_intake.is_long_term::bool
+COL:clin.substance_intake.aim::text
+COL:clin.substance_intake.fk_substance::int4
+COL:clin.substance_intake.preparation::text
+COL:clin.substance_intake.harmful_use_type::int4
+COL:clin.substance_intake.discontinued::timestamptz
+COL:clin.substance_intake.narrative::text
+COL:clin.substance_intake.row_version::int4
+COL:clin.substance_intake.clin_when::timestamptz
+COL:clin.substance_intake.modified_when::timestamptz
+COL:clin.substance_intake.pk_item::int4
+COL:clin.substance_intake.soap_cat::text
+COL:clin.substance_intake.fk_episode::int4
+COL:clin.substance_intake.pk::int4
+COL:clin.substance_intake.comment_on_start::text
+COL:clin.substance_intake.pk_audit::int4
+COL:clin.substance_intake.intake_is_approved_of::bool
+COL:clin.substance_intake.modified_by::name
+COL:clin.substance_intake.fk_drug_component::int4
+COL:clin.substance_intake.schedule::text
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter)_REFERENCES_clin.encounter(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_drug_component)_REFERENCES_ref.lnk_substance2brand(pk)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_episode)_REFERENCES_clin.episode(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_substance)_REFERENCES_ref.consumable_substance(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:clin.clin_item_type
+PK:clin.clin_item_type.pk::integer
+COL:clin.clin_item_type.type::text
+COL:clin.clin_item_type.code::text
+COL:clin.clin_item_type.row_version::int4
+COL:clin.clin_item_type.modified_when::timestamptz
+COL:clin.clin_item_type.pk::int4
+COL:clin.clin_item_type.pk_audit::int4
+COL:clin.clin_item_type.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+TABLE:clin.vacc_indication
+PK:clin.vacc_indication.id::integer
+COL:clin.vacc_indication.id::int4
+COL:clin.vacc_indication.description::text
+COL:clin.vacc_indication.atcs_combi_indication::_text
+COL:clin.vacc_indication.atcs_single_indication::_text
+COL:clin.vacc_indication.row_version::int4
+COL:clin.vacc_indication.modified_when::timestamptz
+COL:clin.vacc_indication.pk_audit::int4
+COL:clin.vacc_indication.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+TABLE:clin.suppressed_hint
+PK:clin.suppressed_hint.pk::integer
+COL:clin.suppressed_hint.fk_hint::int4
+COL:clin.suppressed_hint.fk_encounter::int4
+COL:clin.suppressed_hint.md5_sum::text
+COL:clin.suppressed_hint.suppressed_when::timestamptz
+COL:clin.suppressed_hint.row_version::int4
+COL:clin.suppressed_hint.modified_when::timestamptz
+COL:clin.suppressed_hint.rationale::text
+COL:clin.suppressed_hint.pk::int4
+COL:clin.suppressed_hint.pk_audit::int4
+COL:clin.suppressed_hint.modified_by::name
+COL:clin.suppressed_hint.suppressed_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_hint)_REFERENCES_ref.auto_hint(pk)_ON_UPDATE_RESTRICT_ON_DELETE_CASCADE::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_encounter)_REFERENCES_clin.encounter(pk)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT::active=true
+TABLE:dem.urb
+PK:dem.urb.id::integer
+COL:dem.urb.name::text
+COL:dem.urb.id::int4
+COL:dem.urb.lat_lon::point
+COL:dem.urb.fk_region::int4
+COL:dem.urb.row_version::int4
+COL:dem.urb.modified_when::timestamptz
+COL:dem.urb.pk_audit::int4
+COL:dem.urb.modified_by::name
+COL:dem.urb.postcode::text
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_region)_REFERENCES_dem.region(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:clin.lnk_constraint2vacc_course
+PK:clin.lnk_constraint2vacc_course.pk::integer
+COL:clin.lnk_constraint2vacc_course.row_version::int4
+COL:clin.lnk_constraint2vacc_course.modified_when::timestamptz
+COL:clin.lnk_constraint2vacc_course.fk_constraint::int4
+COL:clin.lnk_constraint2vacc_course.pk::int4
+COL:clin.lnk_constraint2vacc_course.fk_vaccination_course::int4
+COL:clin.lnk_constraint2vacc_course.pk_audit::int4
+COL:clin.lnk_constraint2vacc_course.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_vaccination_course)_REFERENCES_clin.vaccination_course(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_constraint)_REFERENCES_clin.vaccination_course_constraint(pk)_ON_UPDATE_CASCADE_ON_DELETE_CASCADE::active=true
+TABLE:ref.billable
+PK:ref.billable.pk::integer
+COL:ref.billable.currency::text
+COL:ref.billable.vat_multiplier::numeric
+COL:ref.billable.pk_coding_system::int4
+COL:ref.billable.active::bool
+COL:ref.billable.amount::numeric
+COL:ref.billable.fk_data_source::int4
+COL:ref.billable.comment::text
+COL:ref.billable.discountable::bool
+COL:ref.billable.term::text
+COL:ref.billable.code::text
+COL:ref.billable.pk::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_data_source)_REFERENCES_ref.data_source(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:cfg.cfg_template
+PK:cfg.cfg_template.pk::integer
+COL:cfg.cfg_template.name::text
+COL:cfg.cfg_template.type::text
+COL:cfg.cfg_template.description::text
+COL:cfg.cfg_template.cfg_group::text
+COL:cfg.cfg_template.pk::int4
+CONSTRAINT:type=f:FOREIGN_KEY_(type)_REFERENCES_cfg.cfg_type_enum(name)::active=true
+TABLE:dem.praxis_branch
+PK:dem.praxis_branch.pk::integer
+COL:dem.praxis_branch.row_version::int4
+COL:dem.praxis_branch.modified_when::timestamptz
+COL:dem.praxis_branch.pk::int4
+COL:dem.praxis_branch.pk_audit::int4
+COL:dem.praxis_branch.fk_org_unit::int4
+COL:dem.praxis_branch.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+TABLE:blobs.lnk_doc_med2episode
+PK:blobs.lnk_doc_med2episode.pk::integer
+COL:blobs.lnk_doc_med2episode.fk_doc_med::int4
+COL:blobs.lnk_doc_med2episode.row_version::int4
+COL:blobs.lnk_doc_med2episode.modified_when::timestamptz
+COL:blobs.lnk_doc_med2episode.fk_episode::int4
+COL:blobs.lnk_doc_med2episode.pk::int4
+COL:blobs.lnk_doc_med2episode.pk_audit::int4
+COL:blobs.lnk_doc_med2episode.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_doc_med)_REFERENCES_blobs.doc_med(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_episode)_REFERENCES_clin.episode(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:ref.lnk_substance2brand
+PK:ref.lnk_substance2brand.pk::integer
+COL:ref.lnk_substance2brand.fk_substance::int4
+COL:ref.lnk_substance2brand.fk_brand::int4
+COL:ref.lnk_substance2brand.row_version::int4
+COL:ref.lnk_substance2brand.modified_when::timestamptz
+COL:ref.lnk_substance2brand.pk::int4
+COL:ref.lnk_substance2brand.pk_audit::int4
+COL:ref.lnk_substance2brand.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_brand)_REFERENCES_ref.branded_drug(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_substance)_REFERENCES_ref.consumable_substance(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:ref.coding_system_root
+PK:ref.coding_system_root.pk_coding_system::integer
+COL:ref.coding_system_root.pk_coding_system::int4
+COL:ref.coding_system_root.fk_data_source::int4
+COL:ref.coding_system_root.comment::text
+COL:ref.coding_system_root.term::text
+COL:ref.coding_system_root.code::text
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_data_source)_REFERENCES_ref.data_source(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:dem.org_unit
+PK:dem.org_unit.pk::integer
+COL:dem.org_unit.fk_category::int4
+COL:dem.org_unit.description::text
+COL:dem.org_unit.fk_org::int4
+COL:dem.org_unit.row_version::int4
+COL:dem.org_unit.modified_when::timestamptz
+COL:dem.org_unit.fk_address::int4
+COL:dem.org_unit.pk::int4
+COL:dem.org_unit.pk_audit::int4
+COL:dem.org_unit.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_address)_REFERENCES_dem.address(id)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_category)_REFERENCES_dem.org_category(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_org)_REFERENCES_dem.org(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:blobs.doc_type
+PK:blobs.doc_type.pk::integer
+COL:blobs.doc_type.name::text
+COL:blobs.doc_type.pk::int4
+TABLE:bill.bill
+PK:bill.bill.pk::integer
+COL:bill.bill.invoice_id::text
+COL:bill.bill.comment::text
+COL:bill.bill.apply_vat::bool
+COL:bill.bill.row_version::int4
+COL:bill.bill.modified_when::timestamptz
+COL:bill.bill.pk::int4
+COL:bill.bill.close_date::timestamptz
+COL:bill.bill.fk_doc::int4
+COL:bill.bill.fk_receiver_address::int4
+COL:bill.bill.pk_audit::int4
+COL:bill.bill.fk_receiver_identity::int4
+COL:bill.bill.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_doc)_REFERENCES_blobs.doc_med(pk)_ON_UPDATE_CASCADE_ON_DELETE_SET_NULL::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_receiver_address)_REFERENCES_dem.lnk_person_org_address(id)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_receiver_identity)_REFERENCES_dem.identity(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:ref.loinc
+PK:ref.loinc.pk::integer
+COL:ref.loinc.grouping_class::text
+COL:ref.loinc.answer_list::text
+COL:ref.loinc.panel_elements::text
+COL:ref.loinc.example_units::text
+COL:ref.loinc.cdisc_common_tests::text
+COL:ref.loinc.inpc_percentage::text
+COL:ref.loinc.units_required::text
+COL:ref.loinc.example_answers::text
+COL:ref.loinc.pk_coding_system::int4
+COL:ref.loinc.system::text
+COL:ref.loinc.reference::text
+COL:ref.loinc.order_obs::text
+COL:ref.loinc.hl7_field_subfield_id::text
+COL:ref.loinc.fk_data_source::int4
+COL:ref.loinc.comment::text
+COL:ref.loinc.base_name::text
+COL:ref.loinc.species::text
+COL:ref.loinc.short_name::text
+COL:ref.loinc.maps_to::text
+COL:ref.loinc.dt_last_change::text
+COL:ref.loinc.long_common_name::text
+COL:ref.loinc.ipcc_units::text
+COL:ref.loinc.term::text
+COL:ref.loinc.code_status::text
+COL:ref.loinc.grouping_class_type::int2
+COL:ref.loinc.naa_ccr_id::text
+COL:ref.loinc.change_type::text
+COL:ref.loinc.scope::text
+COL:ref.loinc.external_copyright_notice::text
+COL:ref.loinc.code::text
+COL:ref.loinc.component::text
+COL:ref.loinc.molar_mass::text
+COL:ref.loinc.formula::text
+COL:ref.loinc.time_aspect::text
+COL:ref.loinc.related_names_2::text
+COL:ref.loinc.method_type::text
+COL:ref.loinc.survey_question_text::text
+COL:ref.loinc.final::text
+COL:ref.loinc.property::text
+COL:ref.loinc.code_table::text
+COL:ref.loinc.loinc_internal_source::text
+COL:ref.loinc.pk::int4
+COL:ref.loinc.submitted_units::text
+COL:ref.loinc.exact_component_synonym::text
+COL:ref.loinc.related_names_1_old::text
+COL:ref.loinc.acs_synonyms::text
+COL:ref.loinc.normal_range::text
+COL:ref.loinc.is_set_root::bool
+COL:ref.loinc.scale_type::text
+COL:ref.loinc.survey_question_source::text
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_data_source)_REFERENCES_ref.data_source(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:ref.coda
+PK:ref.coda.pk::integer
+COL:ref.coda.pk_coding_system::int4
+COL:ref.coda.fk_data_source::int4
+COL:ref.coda.comment::text
+COL:ref.coda.term::text
+COL:ref.coda.code::text
+COL:ref.coda.pk::int4
+COL:ref.coda.icd10_text::text
+CONSTRAINT:type=f:FOREIGN_KEY_(fk_data_source)_REFERENCES_ref.data_source(pk)_ON_UPDATE_CASCADE_ON_DELETE_RESTRICT::active=true
+TABLE:clin.vacc_route
+PK:clin.vacc_route.id::integer
+COL:clin.vacc_route.id::int4
+COL:clin.vacc_route.description::text
+COL:clin.vacc_route.abbreviation::text
+COL:clin.vacc_route.row_version::int4
+COL:clin.vacc_route.modified_when::timestamptz
+COL:clin.vacc_route.pk_audit::int4
+COL:clin.vacc_route.modified_by::name
+CONSTRAINT:type=f:FOREIGN_KEY_(modified_by)_REFERENCES_dem.staff(db_user)_ON_UPDATE_RESTRICT_ON_DELETE_RESTRICT_NOT_VALID::active=false
+TABLE:cfg.db_logon_banner
+COL:cfg.db_logon_banner.singularizer::bool
+COL:cfg.db_logon_banner.message::text
+
diff --git a/server/sql/v20-v21/python/v21-import-form-templates.py b/server/sql/v20-v21/python/v21-import-form-templates.py
new file mode 100644
index 0000000..143f684
--- /dev/null
+++ b/server/sql/v20-v21/python/v21-import-form-templates.py
@@ -0,0 +1,64 @@
+# coding: utf8
+#==============================================================
+# GNUmed database schema change script
+#
+# License: GPL v2 or later
+# Author: karsten.hilbert at gmx.net
+#
+#==============================================================
+import os
+
+from Gnumed.pycommon import gmPG2
+
+#--------------------------------------------------------------
+
+def run(conn=None):
+
+	# AMTS Medikationsplan
+	gmPG2.file2bytea (
+		query = u"""
+			UPDATE ref.paperwork_templates SET
+				data = %(data)s::bytea
+			WHERE
+				name_long = 'Medikationsplan (Deutschland, AMTS)'""",
+		filename = os.path.join('..', 'sql', 'v20-v21', 'data', 'v21-Medikationsplan_AMTS-2.0.tex'),
+		conn = conn
+	)
+
+	# AMTS Medikationsplan (nicht konform)
+	gmPG2.file2bytea (
+		query = u"""
+			UPDATE ref.paperwork_templates SET
+				data = %(data)s::bytea
+			WHERE
+				name_long = 'Medikationsplan (Deutschland, NICHT konform zu AMTS)'""",
+		filename = os.path.join('..', 'sql', 'v20-v21', 'data', 'v21-Medikationsplan_AMTS-2.0-nicht_konform.tex'),
+		conn = conn
+	)
+
+	# German current meds list
+	gmPG2.file2bytea (
+		query = u"""
+			UPDATE ref.paperwork_templates SET
+				data = %(data)s::bytea
+			WHERE
+				name_long = 'Liste aktueller Medikamente (GNUmed)'""",
+		filename = os.path.join('..', 'sql', 'v20-v21', 'data', 'v21-aktuelle-Medikationsliste.tex'),
+		conn = conn
+	)
+
+	# Begleitbrief
+	gmPG2.file2bytea (
+		query = u"""
+			UPDATE ref.paperwork_templates SET
+				data = %(data)s::bytea,
+				external_version = '21.0'
+			WHERE
+				name_long = 'Begleitbrief ohne medizinische Daten [K.Hilbert]'""",
+		filename = os.path.join('..', 'sql', 'v20-v21', 'data', 'v21-Begleitbrief.tex'),
+		conn = conn
+	)
+
+	return True
+
+#==============================================================
diff --git a/server/sql/v20-v21/python/v21-import-plot-scripts.py b/server/sql/v20-v21/python/v21-import-plot-scripts.py
new file mode 100644
index 0000000..b5ffbf1
--- /dev/null
+++ b/server/sql/v20-v21/python/v21-import-plot-scripts.py
@@ -0,0 +1,44 @@
+#==============================================================
+# GNUmed database schema change script
+#
+# License: GPL v2 or later
+# Author: karsten.hilbert at gmx.net
+# 
+#==============================================================
+
+#--------------------------------------------------------------
+import os
+
+from Gnumed.pycommon import gmPG2
+
+#--------------------------------------------------------------
+def run(conn=None):
+
+	gmPG2.file2bytea (
+		query = u"""
+update ref.paperwork_templates
+set
+	data = %(data)s::bytea,
+	external_version = 'v21.0'
+where
+	name_long = '1 test type plot script (GNUmed default)'
+""",
+		filename = os.path.join('..', 'sql', 'v20-v21', 'data', 'v21-gm2gpl-plot_one_test.gpl'),
+		conn = conn
+	)
+
+	gmPG2.file2bytea (
+		query = u"""
+update ref.paperwork_templates
+set
+	data = %(data)s::bytea,
+	external_version = 'v21.0'
+where
+	name_long = '2 test types plot script (GNUmed default)'
+""",
+		filename = os.path.join('..', 'sql', 'v20-v21', 'data', 'v21-gm2gpl-plot_two_tests.gpl'),
+		conn = conn
+	)
+
+	return True
+#==============================================================
diff --git a/server/sql/v20-v21/static/v21-blobs-doc_med-static.sql b/server/sql/v20-v21/static/v21-blobs-doc_med-static.sql
new file mode 100644
index 0000000..6a7a867
--- /dev/null
+++ b/server/sql/v20-v21/static/v21-blobs-doc_med-static.sql
@@ -0,0 +1,19 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+alter table blobs.doc_med
+	add column fk_org_unit integer;
+
+alter table audit.log_doc_med
+	add column fk_org_unit integer;
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-blobs-doc_med-static.sql', '21.0');
diff --git a/server/sql/v20-v21/static/v21-clin-substance_intake-static.sql b/server/sql/v20-v21/static/v21-clin-substance_intake-static.sql
new file mode 100644
index 0000000..b66158f
--- /dev/null
+++ b/server/sql/v20-v21/static/v21-clin-substance_intake-static.sql
@@ -0,0 +1,21 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+
+-- --------------------------------------------------------------
+alter table clin.substance_intake add column comment_on_start text;
+
+alter table audit.log_substance_intake add column comment_on_start text;
+
+-- --------------------------------------------------------------
+alter table clin.substance_intake add column harmful_use_type integer;
+
+alter table audit.log_substance_intake add column harmful_use_type integer;
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-clin-substance_intake-static.sql', '21.0');
diff --git a/server/sql/v20-v21/static/v21-dem-identity-static.sql b/server/sql/v20-v21/static/v21-dem-identity-static.sql
new file mode 100644
index 0000000..34c1a08
--- /dev/null
+++ b/server/sql/v20-v21/static/v21-dem-identity-static.sql
@@ -0,0 +1,30 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+alter table dem.identity
+	drop column pupic cascade;
+
+alter table audit.log_identity
+	drop column pupic;
+
+-- --------------------------------------------------------------
+drop table if exists de_de.behandlungsfall cascade;
+
+drop table if exists audit.log_behandlungsfall cascade;
+
+delete from audit.audited_tables where
+	schema = 'de_de'
+		and
+	table_name = 'behandlungsfall'
+;
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-dem-identity-static.sql', '21.0');
diff --git a/server/sql/v20-v21/static/v21-dem-region-static.sql b/server/sql/v20-v21/static/v21-dem-region-static.sql
new file mode 100644
index 0000000..fbf87b6
--- /dev/null
+++ b/server/sql/v20-v21/static/v21-dem-region-static.sql
@@ -0,0 +1,25 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+alter table dem.state rename to region;
+alter table dem.region rename column id to pk;
+
+
+alter table audit.log_state rename to log_region;
+alter table audit.log_region rename column id to pk;
+
+-- --------------------------------------------------------------
+alter table dem.urb rename column id_state to fk_region;
+
+alter table audit.log_urb rename column id_state to fk_region;
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-dem-region-static.sql', '21.0');
diff --git a/server/sql/v20-v21/static/v21-ref-auto_hint-static.sql b/server/sql/v20-v21/static/v21-ref-auto_hint-static.sql
new file mode 100644
index 0000000..f7b882d
--- /dev/null
+++ b/server/sql/v20-v21/static/v21-ref-auto_hint-static.sql
@@ -0,0 +1,19 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+alter table ref.auto_hint
+	add column recommendation_query text;
+
+alter table audit.log_auto_hint
+	add column recommendation_query text;
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-ref-auto_hint-static.sql', '21.0');
diff --git a/server/sql/v20-v21/superuser/v21-reinstall-pg_trgm.sql b/server/sql/v20-v21/superuser/v21-reinstall-pg_trgm.sql
new file mode 100644
index 0000000..3a08560
--- /dev/null
+++ b/server/sql/v20-v21/superuser/v21-reinstall-pg_trgm.sql
@@ -0,0 +1,20 @@
+-- ==============================================================
+-- GNUmed database schema change script
+--
+-- License: GPL v2 or later
+-- Author: karsten.hilbert at gmx.net
+--
+-- ==============================================================
+\set ON_ERROR_STOP 1
+--set default_transaction_read_only to off;
+
+-- --------------------------------------------------------------
+drop schema if exists pgtrgm cascade;
+create schema pgtrgm;
+grant usage on schema pgtrgm to "gm-dbo";
+
+drop extension if exists pg_trgm cascade;
+create extension pg_trgm with schema pgtrgm;
+
+-- --------------------------------------------------------------
+select gm.log_script_insertion('v21-reinstall-pg_trgm.sql', '21.0');

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/gnumed-server.git



More information about the debian-med-commit mailing list