#############################################
# Project Definition for cds2db ETL process #
#############################################

[general]

###
# VERBOSE LEVELS
###
# VL_00_NOTHING             = 0
# VL_10_MAIN_INFO           = 1
# VL_20_OUTER_SCRIPTS       = 2
# VL_30_INNER_SCRIPTS       = 3
# VL_40_INNER_SCRIPTS_INFOS = 4
# VL_50_TABLES              = 5
# VL_60_ALL_TABLES          = 6
# VL_70_DOWNLOAD            = 7
# VL_80_COI_PROCESSING      = 8
# VL_90_FHIR_RESPONSE       = 9
VERBOSE               = 10 # Retrieval / analysis verbose level

# Set true if every sourcing of the 00_Main file should create result directories in the
# otuputGlobal and otuputLocal directores with a timestamp suffix. If false then every run will
# write in the same subdirectory without a timestamp.
# The default behaviour should write in subdirectories with only the project name (false) or in or
# in a subdirectorywith the project name and the suffix '_timestamp'.
USE_TIMESTAMP_AS_RESULT_DIR_SUFFIX = false

# Maximum of saved cds2db result folders in outputLocal and outputGlobal
MAX_DIR_COUNT = 5


[retrieve]

# Number of minutes to wait between inserting the data into the RAW tables and starting the
# typing process.
# This time must be greater than the time for the cron jobs of the copy functions in the database
# (defined in database init script 30, at the bottom).
# Default is 1 minute.
DELAY_MINUTES_BETWEEN_RAW_INSERT_AND_START_TYPING = 1


[retrieve.fhir_server]

FHIR_SERVER_ENDPOINT = "https://mii-agiop-3p.life.uni-leipzig.de/blaze"
FHIR_SERVER_USER = ""
FHIR_SERVER_PASS = ""

FHIR_TOKEN                  = ""
FHIR_TOKEN_REFRESH_URL      = ""
FHIR_TOKEN_REFRESH_USER     = ""
FHIR_TOKEN_REFRESH_PASSWORD = ""


MAX_CHARACTER_LENGTH_FOR_GET_REQUESTS         = 2083 # max character length for GET-Requests [ehemals MAX_LEN]
MAX_CHARACTER_LENGTH_FOR_GET_REQUESTS_RESERVE = 300  # reserve 300 characters for further parameters, whose length cannot estimated [ehemals RES_LEN]

MIN_PATIENT_AGE                    = 18           # defined Age threshold in POLAR basic population
MIN_BIRTHDAY                       = "1910-01-01" # lowest possible birthday
DEFAULT_EMPTY_BIRTHDAY_PATTERN     = ""           # pattern to identify the default birth date if the real date is missing

MAX_ENCOUNTER_BUNDLES              = inf # maximum number of Encounter bundles that will be loaded from the server ('inf' = all)
COUNT_PER_BUNDLE                   = 100 # as default or use server default ? The number of results that are mapped per FHIR request on a response page [ehemals COUNT]
SORT                               = ""  # some Fhir server require a sort parameter per default
IDS_AT_ONCE                        = 100 # patient / medication ids combined in one request (GET or POST) - specifies the number of ID's, which are summarized in a request (after download of Encounters)

# polar_download_by_ids_and_crack_parallel() and polar_download_and_crack_parallel()
MAX_CORES                          = 0 # paralellization, number of cores used, 0: unlimited
FORCE_DOWNLOAD_AND_CRACK_PARALLEL  = false # if TRUE: force download and crack parallel with basic method, avoid polar_download_by_ids_and_crack_parallel()
NEXT_LINK_ENCODE                   = false # encode special chars in next_link (see polar_download_and_crack_parallel())


[retrieve.debug]

###################
# FOR DEBUG ONLY: #
###################

# If the DEBUG_CURRENT_DATETIME_START parameter is activated, only Encounters whose start date is
# before this date are searched for.
# If it is not activated, the current date is automatically assumed.
# If in addition (!) to DEBUG_CURRENT_DATETIME_START the parameter DEBUG_CURRENT_DATETIME_END is
# also set, then only Encounters whose start date (Encounter.period.start) is after the
# DEBUG_CURRENT_DATETIME_START and before the DEBUG_CURRENT_DATETIME_END are found.
# Since the end date of Encounters cannot be queried without a FHIR Custom Search parameter, all
# queries for the Encounter date always refer to its start date.
#DEBUG_CURRENT_DATETIME_START = "2020-06-30 21:25:00"
#DEBUG_CURRENT_DATETIME_END = "2020-08-30 21:25:00"

# Only encounters with exactly this status are found. If this Debug parameter is not set, the status
# "in-progress" applies.
#DEBUG_ENCOUNTER_STATUS = "finished"

# These parameters can be set to filter the resource table to specific rows for each resource after
# downloading. The valid range for indices is, for example, "1, 3-5, 7", which stands for the
# indices "1, 3, 4, 5, 7"" in the respective resource table. If an empty string, "", is specified,
# then all lines of the respective resource are deleted. The "DEBUG_FILTER_" variables that are
# commented out are not filtered.
# This can be used to pass only certain data of a query in test cases.
#DEBUG_FILTER_CONDITION = "1-10"
#DEBUG_FILTER_CONSENT = ""
#DEBUG_FILTER_DIAGNOSTICREPORT = ""
#DEBUG_FILTER_ENCOUNTER = ""
#DEBUG_FILTER_LOCATION = ""
#DEBUG_FILTER_MEDICATION = ""
#DEBUG_FILTER_MEDICATIONADMINISTRATION = ""
#DEBUG_FILTER_MEDICATIONREQUEST = ""
#DEBUG_FILTER_MEDICATIONSTATEMENT = ""
#DEBUG_FILTER_OBSERVATION = "1-10"
#DEBUG_FILTER_PATIENT = ""
#DEBUG_FILTER_PROCEDURE = ""
#DEBUG_FILTER_SERVICEREQUEST = ""

# This debug parameter restricts the table pids_per_ward by filtering out all patients who have not
# the corresponding string in patient ID.
# This parameter can also be used to allow only certain data of a query to pass in test cases.
#DEBUG_PATIENT_ID_PATTERN = "UKB"

[retrieve.patient_id_filtering]

# Enable the following parameter, if the relevant patient IDs (PID) are provided by an external
# system and they are stored in a text file (1 PID pr line). This deactivates the search for
# relevant PIDs via encounters (see ENCOUNTER_FILTER_PATTERNS).
#PATH_TO_PID_LIST_FILE = "./R-cds2db/source_PIDs.txt"

# Use this defintion to set the filters to identify all Encounters of the relevant wards. This is
# only necessary if the relevant Patient IDs should be derived from this Encounters and are not
# provided in any other way.
# Every entry defines a single condition. An Encounter will be accepted, if at least one condition is
# fulfilled (OR connected). A condition defines which expressions of the Encounter should have which
# value. The values can be defined as grep patterns. Multilpe subconditions can be connected by '+'
# (logcal AND). All Patterns are Case INSENSITIVE!
# A valid patterns variable name must start with 'ENCOUNTER_FILTER_PATTERN'.
ENCOUNTER_FILTER_PATTERN_1 = [
  "ward_name = 'Station 1'",
  "serviceType/coding/code = '1600' + class/code = 'station|IMP|inpatient|emer|ACUTE|NONAC'",
  "serviceType/coding/display = 'Unfallchirurgie' + class/code = 'station|IMP|inpatient|emer|ACUTE|NONAC'"
]

ENCOUNTER_FILTER_PATTERN_2 = [
  "ward_name = 'Station 2'",
  "serviceType/coding/code = '0500' + class/code = 'station|IMP|inpatient|emer|ACUTE|NONAC'"
]

ENCOUNTER_FILTER_PATTERN_3 = [
  "ward_name = 'Station 3'",
  "serviceType/coding/code = '1600' + class/code = 'station|IMP|inpatient|emer|ACUTE|NONAC'",
  "serviceType/coding/display = 'Unfallchirurgie' + class/code = 'station|IMP|inpatient|emer|ACUTE|NONAC'"
]


[database]

PATH_TO_DB_CONFIG_TOML = "./cds_hub_db_config.toml"
