# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
# Powershell script : VQ_Conv_Pdx-Fb-Compare
# Vergelijkt patienten paradox database na conversie met Firebird database obv EXTERN pat-ID.
# LET OP - Dit werkt niet met een omnummering.
# 
# = = = = = = = = = = = = = = = = = = = =
#   V 1.1.0   =   01-04-2022    =  AdJ  = connectie data hard-coded in script
#   V 1.2.0   =   01-04-2022    =  AdJ  = Haalt FB_DB, FB_SR, PX_DB uit DestDbCfg.INI van Conversie tool
# = = = = = = = = = = = = = = = = = = = =
# 
Clear-Host
# Defieer de I/O Text files
#
# haal een string uit een INI-file : Firebird database filename
$regex = "DbFilename"
foreach($line in [System.IO.File]::ReadLines(".\SourceDbCfg.ini")) {
    if($line -match $regex){
        $split = $line.IndexOf("=")                                                      # zoek het =-teken
        $fb_db = $line.Substring($split+1)                                               # Haal het path eruit
    }
}
#
# haal een string uit een INI-file : Firebird Server
$regex = "Server"
foreach($line in [System.IO.File]::ReadLines(".\DestDbCfg.ini")) {
    if($line -match $regex){
        $split = $line.IndexOf("=")                                                      # zoek het =-teken
        $fb_sr = $line.Substring($split+1)                                               # Haal het path eruit
    }
}
#
# haal een string uit een INI-file : Paradox database
$regex = "DbPath"
foreach($line in [System.IO.File]::ReadLines(".\SourceDbCfg.ini")) {
    if($line -match $regex){
        $split = $line.IndexOf("=")                                                      # zoek het =-teken
        $px_db = $line.Substring($split+1)                                               # Haal het path eruit
    }
}
# For DEBUG only  :  Remove #-sign = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# Write-Host 'Firebird  DB: ' $fb_db                     # Firebird DB Read from convertion INI DestDbCfg.INI
# Write-Host 'Firebird SVR: ' $fb_sr                     # Firebird Server from convertion INI DestDbCfg.INI
# Write-Host 'Paradox   DB: ' $px_db                     # Paradox DB  Read from convertion INI DestDbCfg.INI
# = = FIXED SETTINGS = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# $px_db = "SharedFolder Paradox"                        # Paradox DB 
# $fb_db = "Firebird FDB"                                # Firebird DB
# $fb_sr = "127.0.0.1/30500"                             # Firebird Server
$PX_pat = "patientdumplist_Paradox.txt"                  # Paradox Pat-list   Fixed name
$FB_pat = "patientdumplist_Firebird.txt"                 # Firebird Pat-list  Fixed name
$view_title = $PX_pat + " < = > " + $FB_pat              # zet de view titel
# = = FIXED SETTINGS = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# Paradox db-file 
Remove-Item pdx_db.cfg                                                                         # remove any paradox db-config file if exist
.\vqdbutils.exe WriteParadoxDbCfg /out=pdx_db.cfg /dbpath=$px_db                               # create paradox db-config file
get-content pdx_db.cfg                                                                         # Read PARADOX Database configuratie 
# Firebird db-file
Remove-Item fb_db.cfg                                                                          # remove any paradox db-config file if exist
.\vqdbutils.exe WriteFirebirdDbCfg /out=fb_db.cfg /server=$fb_sr /database=$fb_db              # create Firebird db-config file
get-content fb_db.cfg                                                                          # Read FIREBIRD Database configuratie 
#
# = = = = = = = = = = 
# Dump Patienten Info
.\VqDbutils.exe dumppatientlist /db=pdx_db.cfg /out=patientdumplist_Paradox.txt
# Dump Patienten Info
.\VqDbutils.exe dumppatientlist /db=fb_db.cfg /out=patientdumplist_Firebird.txt
#
# = = = = = = = = = = 
# Lees de inhoud in
$strReference = Get-Content $PX_pat
$strDifference = Get-Content $FB_pat
#
# = = = = = = = = = = 
# vergelijk de inhoud
Compare-Object $strReference $strDifference |Out-File VQ_Conv_Pdx-Fb_Compate_Patients.txt
Get-content VQ_Conv_Pdx-Fb_Compate_Patients.txt |Out-GridView -Title $view_title

