# GNUmed database system bootstrapping config file
#-------------------------------------------------
# license: GPL v2 or later
# author: Karsten Hilbert@gmx.net

#----------------------------------
[installation]
interactive = yes

keep temp files = no

description = $description$
This will update an existing GNUmed version 16
database to the version 17 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$
v16_fixups-pre_v17
v16-v17-static
v16-v17-dynamic
v17-fixups
$bundles$

#----------------------------------
[bundle v16_fixups-pre_v17]
database alias = gnumed_v17
minimum postgresql version = 8.4
schema base directory = ../sql/v15-v16/fixups/
schema = $schema$
v16-clin-v_narrative4search-fixup.sql
v16-cfg-report_query-fixup.sql
v16-blobs-doc_obj-fixup.sql
v16-blobs-doc_desc-fixup.sql
v16-i18n-fixup.sql
v16-russian_translations.sql
v16-clin-v_waiting_list-fixup.sql
$schema$

#----------------------------------
[bundle v16-v17-static]
database alias = gnumed_v17
minimum postgresql version = 8.4
schema base directory = ../sql/v16-v17/static/
schema = $schema$
v17-gm-log_script_insertion.sql
v17-ref-billable-static.sql
v17-ref-auto_hint-static.sql
v17-dem-identity-static.sql
v17-dem-lnk_identity2comm-static.sql
v17-dem-message_inbox-static.sql
v17-bill-bill-static.sql
v17-bill-bill_item-static.sql
v17-bill-lnk_enc_type2billable-static.sql
$schema$

#----------------------------------
[bundle v16-v17-dynamic]
database alias = gnumed_v17
minimum postgresql version = 8.4
schema base directory = ../sql/v16-v17/dynamic/
schema = $schema$
v17-gm-schema_revision_handling.sql
v17-cfg-cfg_str_array-dynamic.sql
v17-cfg-report_query.sql
v17-i18n-translations-dynamic.sql
v17-dem-identity-dynamic.sql
v17-dem-v_basic_person.sql
v17-dem-names-dynamic.sql
v17-dem-lnk_identity2comm-dynamic.sql
v17-dem-lnk_job2person-dynamic.sql
v17-dem-v_person_comms.sql
v17-dem-v_message_inbox.sql
v17-clin-remove_old_empty_encounters.sql
v17-clin-support_soapU.sql
v17-clin-v_pat_vaccinations.sql
v17-clin-substance_intake-dynamic.sql
v17-clin-v_pat_substance_intake.sql
v17-clin-v_pat_narrative_journal.sql
v17-clin-v_emr_journal.sql
v17-clin-keyword_expansion-data.sql
v17-clin-v_narrative4search.sql
v17-blobs-v_doc_med.sql
v17-blobs-delete_document.sql
v17-blobs-delete_document_part.sql
v17-ref-paperwork_templates.sql
v17-ref-billable-dynamic.sql
v17-ref-auto_hint-dynamic.sql
v17-bill-bill_item-dynamic.sql
v17-bill-bill-dynamic.sql
v17-bill-lnk_enc_type2billable-dynamic.sql
v17-release_notes-dynamic.sql
$schema$

#----------------------------------
[bundle v17-fixups]
database alias = gnumed_v17
minimum postgresql version = 8.4
schema base directory = ../sql/v16-v17/fixups/
schema = $schema$
v17-blobs-doc_obj-fixup.sql
v17-clin-v_waiting_list-fixup.sql
v17-clin-clin_narrative-fixup.sql
v17-clin-soapU_check-fixup.sql
v17-ref-consumable_substance-fixup.sql
v17-ref-billable-fixup.sql
v17-ref-bill_item-fixup.sql
v17-cfg-report_query-fixup.sql
v17-ref-bill-fixup.sql
$schema$

#----------------------------------
[bundle v17-test_data]
database alias = gnumed_v17
minimum postgresql version = 8.4
schema base directory = ../sql/test-data/
schema = $schema$
$schema$

#----------------------------------
[database gnumed_v17]
name = gnumed_v17
drop target database = 1
target version = v17
transfer users = 1
source database = gnumed_v16
source version = v16
audit disable = 0
schema base directory = ../sql/v16-v17/
schema = $schema$
$schema$

superuser schema = $superuser schema$
$superuser schema$

script base directory = ../sql/v16-v17/python/
data import scripts = $data import scripts$
v17-import-form-templates.py
$data import scripts$

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
addresses::::select count(1) from dem.address
	select count(1) from dem.address
episodes::::select count(1) from clin.episode
	select count(1) from clin.episode
denormalized episodes::::select count(1) from clin.v_pat_episodes
	select count(1) from clin.v_pat_episodes
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
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
clinical items::::select count(1) from clin.clin_root_item
	select count(1) from clin.clin_root_item
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
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
organisations::::select count(1) from dem.org
	select count(1) from dem.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) 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
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) + 4 from ref.paperwork_templates
	select count(1) from ref.paperwork_templates
$upgrade plausibility checks$


#data sources::::select count(1) from ref.data_source
#	select count(1) from ref.data_source
#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))))

#----------------------------------
[cluster]
host name = 
port = 5432
maintenance database = template1
schema base directory = ../sql/v16-v17/
schema = $schema$
$schema$

#----------------------------------
# these really shouldn't be changed
#----------------------------------
[GnuMed defaults]

groups = $groups$
$groups$

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