# GNUmed database system bootstrapping config file
#-------------------------------------------------
# license: GPL v2 or later
# author: Karsten Hilbert@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
v21-fixups
$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$
v21-dem-view_grants-fixup.sql
v21-ref-auto_hint-tetanus_STIKO.sql
v21-ref-auto_hint-klug_entscheiden_pulmo.sql
v21-ref-auto_hint-klug_entscheiden_endokrino.sql
v21-CD_DVD-sleeve.sql
v21-AMTS_Medikationsplan-fixup.sql
v21-ref-auto_hint-smoking_status-fixup.sql
v21-ref-GKV_CU-fixup.sql
$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
v21-import-form-template-fixups.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			-- new
names::::select count(1) from dem.names
	select count(1) from dem.names	-- new
v_all_persons::::select count(1) from dem.v_persons
	select count(1) from dem.v_all_persons	-- new
v_active_persons::::select count(1) from dem.v_basic_person
	select count(1) from dem.v_active_persons	-- new
staff::::select count(1) from dem.staff								-- old
	select count(1) from dem.v_staff where not person_is_deleted	-- new
v_staff::::select count(1) from dem.v_staff
	select count(1) from dem.v_staff	-- new
addresses::::select count(1) from dem.address
	select count(1) from dem.address	-- new
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) - 7 from ref.paperwork_templates
automatic hints::::select count(1) + 9 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))
-- ------------------
-- commented out:
--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))))
-- ------------------
-- for debugging:
--skipped check::::select 'skipped in old'		-- old
--	select 'skipped in new'						-- new
--check definition error::select 1				-- old
--	select 1									-- new
--syntax error (old)::::selec 1 				-- old
--	select 1									-- new
--syntax error (new)::::select 1 				-- old
--	selec 1										-- new
--data mismatch error::::select 1 				-- old
--	select 2 -- new
$upgrade plausibility checks$

#----------------------------------
[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$

#----------------------------------
