# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # #                                                                       # # # #
# # #                            V Q  D B  U T I L S                            # # #
# # # #                                                                       # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#   V Q D B U T I L S  - S C E N A R I O S    #  PS-Script Library  #  01 04 2022   #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# VqDbUtils V1.0.0.265 : 10/01/2022 
# VqDbUtils V1.0.0.284 : 01/04/2022
# VqDbUtils V1.0.0.295 : 19/09/2022
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # #     S C R I P T S     # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 

# Patienten ID's aanpassen naar 30 Char : 
.\VqDbUtils.exe RunScript /scriptfn="scripts\ExpandPatientIDs.pas"

# Patienten ID's aanpassen Toevoegen CPR 'min'-teken (10 > 6-4) (DK/ZW/NO): 
.\VqDbUtils.exe RunScript /scriptfn="scripts\AddCprDash.pas"

# Patienten ID's aanpassen Toevoegen nullen aan PatIds tot 6 Char  (NL) : 
#   PrependWidth=6;    ==>> Line 2 : Aanpassing aantal characters 
.\VqDbUtils.exe RunScript /scriptfn="scripts\AddLeadingZeros_6.pas"

# Patienten ID's aanpassen CPR aanpassen > 6-4  (DK/ZW/NO) : 
.\VqDbUtils.exe RunScript /scriptfn="scripts\FixCprid.pas"

# Patienten ID's aanpassen 'min'-teken verwijderen (6-4 > 10) (DK/ZW/NO): 
.\VqDbUtils.exe RunScript /scriptfn="scripts\RemoveCprDash.pas"

# Patienten ID's aanpassen verwijderen nullen van PatIds (NL) : 
.\VqDbUtils RunScript /scriptfn="scripts\RemoveLeadingZeros.pas"

# Patienten ID's aanpassen verwijderen spaties van PatIds (NL) : 
.\VqDbUtils RunScript /scriptfn="scripts\TrimSpaces.pas"

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# #    End-Of-Block : SCRIPTS   # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# FOR HELPSCREEN SCROL TO THE BOTTOM
#
# == == == Database koppelen # #
#
# MSSQL database koppelen
.\vqdbutils.exe WriteSqlDbCfg /out=sqldb.cfg /server="server\services" /database=database_naam
get-content sql_db.cfg |Out-GridView   # MS-SQL Database configuratie 
#
# paradox database koppelen
.\vqdbutils.exe WriteParadoxDbCfg /out=pdx_db.cfg /dbpath=d:\visidata\shareddata\pdx
get-content pdx_db.cfg |Out-GridView   # PARADOX Database configuratie 
#
# Firebird database koppelen
.\vqdbutils.exe WriteFirebirdDbCfg /out=fb_db.cfg /server="127.0.0.1/30500" /database=D:\VisiData\Firebird\VQ_Test_deleted_patients.FDB
.\vqdbutils.exe WriteFirebirdDbCfg /out=fb_db.cfg /server="127.0.0.1/30500" /database=D:\Citodent\Les\Firebird\VISIQUICK.FDB
.\vqdbutils.exe WriteFirebirdDbCfg /out=fb_db.cfg /server="127.0.0.1/30500" /database=D:\Conversie\current\TEST\CVT#2246_VISIQUICK.FDB
get-content fb_db.cfg    # FIREBIRD Database configuratie 
#
# =============================================================================

# 
# == == == Verwijderde foto's terughalen # #
.\VqDbUtils.exe UndeleteImage /db=fb_db.cfg /clinic=1 /patientlink=509232 /vnum=4

# ==
#

#
# == == == Patientenlijsten maken # #
#
# Maak een renum list INTERNE NUMMERS
.\VqDbUtils.exe patrenumberlist /db=fb_db.cfg /dentid=1 /inc=0 >patrenum.txt
# Lees de informatie uit 
get-content patrenum.txt |Out-GridView   # patientnummers HERNUMMEREN oud-nieuw
# ==
# Exporteer de patientnummers (ZICHTBAAR IN ZOEKLIJST)
.\VqDbutils.exe dumppatientIDlist /db=pdx_db.cfg /out=patientnrlist.txt
.\VqDbutils.exe dumppatientIDlist /db=fb_db.cfg /out=patientnrlist.txt
.\VqDbutils.exe dumppatientIDlist /out=patientnrlist.txt
#
# Lees de informatie uit 
get-content patientnrlist.txt |Out-GridView   # patientnummers HERNUMMEREN oud-nieuw
# ==
#

# Dump Patienten Info
.\VqDbutils.exe dumppatientlist /db=pdx_db.cfg /out=patientdumplist_afterdelete.txt
# Lees de informatie uit 
get-content patientdumplist.txt |Out-GridView   
# ==
#

# Exporteer de patientnummers (INTERNE PATIENTNUMMERS)
.\VqDbutils.exe dumppatientlist /db=fb_db.cfg /out=patientlist.txt
.\VqDbutils.exe dumppatientlist /db=pdx_db.cfg /out=patientlist.txt
#
# Lees de informatie uit 
get-content patientlist.txt |Out-GridView   # patientnummers HERNUMMEREN oud-nieuw
# ==
# =============================================================================

#
# Hernummer patienten EXTERNE NUMMERS   !!!!!  MOET IN DOS-BOX  
# /fn [/db] [/clinicid] [/newidfirst] [/stripzeros] [/fromdt] [/todt]
# /fn                           filename of translation list (srcid,dstid))
# /db                           Database configuration file of database
# /clinicid                     clinic ID (default 1)
# /newidfirst                   New patient id first in translation list (default false)
# /stripzeros                   Strip leading zeroes of patient id's in translation list (default false)
# /fromdt                       From date/time yyyy-mm-dd hh:nn:ss (default empty)
# /todt                         To date/time yyyy-mm-dd hh:nn:ss(default empty)
# 
# LET OP : kan niet onder powershell # === #
# ====================================================================
# CMD : VQDbUtils MergePatients /Fn=PatRenumList.csv /db=fb_db.cfg
# CMD : VqDbutils.exe MergePatients /db=fb_db.cfg /fn=PatRenumList.lst
# ====================================================================


#
# Zoek alle zwart-wit foto's = Intra X-Ray =
.\VqDbutils.exe FindClinicImages /db=pdx_db.cfg /out=images.txt /gray /pocketindex=xr
#
# Zoek alle zwart-wit foto's = OPG =
.\VqDbutils.exe FindClinicImages /db=pdx_db.cfg /out=images.txt /gray /pocketindex=imp
#
# Zoek alle zwart-wit foto's = Ceph =
.\VqDbutils.exe FindClinicImages /db=fb_db.cfg /out=images.txt /clinic=1 /gray /pocketindex=ceph
.\VqDbutils.exe FindClinicImages /db=pdx_db.cfg /out=images.txt /clinic=1
#
get-content images.txt # |Out-GridView   # OUTPUT : Image manipulation


# Set C.B.G waardes
.\VqDbutils.exe PatchImageProps /db=fb_db.cfg /images=images.txt /brightness=25 /contrast=54 /gamma="-0.5"
#
# Set Filter waardes (0-4, off,A-D)
.\VqDbutils.exe PatchImageProps /images=images.txt /superfilter=1


#
# Verwijder patienten
.\VqDbutils.exe deletepatients /db=fb_db.cfg /patients=patientdellist.txt
.\VqDbutils.exe deletepatients /db=pdx_db.cfg /patients=patientdellist.txt
# Verwijder lege patienten
.\VqDbUtils.exe DeleteEmptyPatients /db=fb_db.cfg /clinicid=1


.\VqDbUtils.exe RemoveDeletedImages /db=fb_db.cfg


#
# Lees de informatie uit 
get-content patientnrlist.txt | Out-GridView    # patientnummers (ZICHTBAAR IN ZOEKLIJST)
get-content patientlist.txt  | Out-GridView     # patientnummers (INTERNE PATIENTNUMMERS)
get-content patientdellist.txt  | Out-GridView  # patientnummers TE VERWIJDEREN

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#                                                                                   #
#                                   P R O C E D U R E S                             #
#                                                                                   #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# => Verwijder (een groep) patienten
#   ============================================================================
#   0) Koppel de database
#   1) run commando : Exporteer de patientnummers (ZICHTBAAR IN ZOEKLIJST)
#   2) pas deze aan zodat je alleen de patienten overhoud die verwijderd moeten worden. 
#   3) Sla op onder een andere naam : patientdellist.txt
#   4) Run commando Verwijder patienten
#   ============================================================================


# => Hernummer (een groep) patienten
#   ============================================================================
#   0) Koppel de database
#   1) run commando : Exporteer de patientnummers (ZICHTBAAR IN ZOEKLIJST)
#   2) kopieer dit bestand naar een CSV-bestand en lees in in EXCEL
#   2) pas deze aan met in de 2e kolom de NIEUWE EXTERNE patientnummers
#   3) Sla op onder een andere naam : PatRenumList.csv
#   4) Run commando Hernummer patienten EXTERNE NUMMERS
#   ============================================================================


# => Vergelijk de patienten tussen een Paradox en een Firebird database na conversie
#   ===========================================================================
#   ## ==>>  Vergelijking op EXTERN ID, na omnummering NIET bruikbaar.  <<== ##
#   ===========================================================================
Clear-Host
# Defieer de I/O Text files
$PX_pat = "patientdumplist_Paradox.txt"                  # Paradox Pat-list
$FB_pat = "patientdumplist_Firebird.txt"                 # Firebird Pat-list
$pdx_db = "d:\visidata\shareddata\pdx"                   # Paradox DB
$fb_db = "D:\VisiData\les\Firebird\visiquick.FDB"        # Firebird DB
$view_title = $PX_pat + " < = > " + $FB_pat              # zet de view titel
#
# Paradox db-file
Remove-Item pdx_db.cfg
.\vqdbutils.exe WriteParadoxDbCfg /out=pdx_db.cfg /dbpath=$pdx_db
get-content pdx_db.cfg    # PARADOX Database configuratie 
# Firebird db-file
Remove-Item fb_db.cfg
.\vqdbutils.exe WriteFirebirdDbCfg /out=fb_db.cfg /server="127.0.0.1/30500" /database=$fb_db
get-content fb_db.cfg    # 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
#   ============================================================================

# => 
#   ===========================================================================
#   ## ==>>                                                             <<== ##
#   ===========================================================================
# Script 
#   1) Omschrijving
#   2) Omschrijving
#   3) Omschrijving
#   4) Omschrijving
#   ============================================================================


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #                      E N D   O F   P R O C E D U R E S                        # #
  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 



# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#                                                                                   #
#                           H E L P S R C E E N   U T I L I T Y                     #
#                                                                                   #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# DO NOT RUN ANY LINE BELOW                                                         #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
VqDbUtils.exe FUNCTIONNAME

AnalysePhotoTable             Analyse photo table (Paradox database only)       
AnalysePhotoTables            Analyse photo tables (Paradox database only)      
CheckPdxFilesHeader           Check directory for Db/Mb file headers            
CompareImageLists             Compare image lists                               
CompareImages                 Compare images (equals or left side orphans)      
ConvertDatToTiff              Convert Remote X-Ray image to Tiff                
CopyVqInfo                    Copy VqInfo Records (Paradox database only)       
DeleteEmptyPatients           Delete empty patients                             
DeleteImage                   Delete image without adding it to deleted image guid list (Paradox database only)                   
DeleteImages                  Delete images                                     
DeletePatients                Delete patients                                   
DoConversion                  Convert VisiQuick database                        
DumpDcmTags                   Dump Dicom file tags                              
DumpImageList                 Dump image list to file (PatientID,PhotoID,CreatedDate)                                             
DumpImgInfo                   Dump image info                                   
DumpInfoFieldsStream          Dump contents of a image info record Ext blob     
DumpPatFieldsStream           Dump contents of a patient record Ext blob        
DumpPatInfo                   Dump patient info                                 
DumpPatientIdList             Dumps patient ID list of a clinic                 
DumpPatientList               Dumps patient list of a clinic                    
DumpRemotePatList             Dump remote patient list                          
DumpTiffTags                  Dump Tiff tags                                    
DumpVqdFile                   Dump contents of a Vqd file                       
ExpandPhotoTables             Expand photo tables (Paradox database only)       
FilterRenumberList            Filter patient renumber list                      
FindClinicImages              Find clinic images and write to file (PatientID,PhotoID) 
GetVqExeFn                    Get VisiQuick exe filename from registry          
InsertedImagesToImageList     InsertedImages to Image list (VqDbConvert)        
MergeImageLists               Merge image lists                                 
MergePatients                 Merge patients (inline)                           
MergeRenumberList             Merge patient renumber list (doubles)             
PatRenumberList               Generate patient renumber list                    
PatchImageProps               Patch image properties                            
PatchPhotoTable               Patch patient photo table number (Paradox database only)                                            
PatchPhotoTables              Patch patients photo table number (Paradox database only)                                           
PatchSavedViews               Patch patient saved views                         
RebalancePhotoTable           Rebalance photo table (Paradox database only)     
RemoveDeletedImages           Remove deleted images                             
RenumberFDB                   Renumber FDB folder                               
ResizeImagesFixed             Resizing images according to resize rules         
RestoreDamagedDb              Copy patient and/or image properties from source to dest DB                                         
RewriteNci3DImages            Rewrite Nci 3D images                             
RunScript                     Run script                                        
SavePvFileToXml               Save persistent values file to XML                
SetImageGuids                 Set image guids when empty                        
TestOpenPatients              Opens a patient or all patients of a clinic       
WriteConversionCfg            Saves DB conversion configuration to file         
WriteFirebirdDbCfg            Save Firebird DB configuration to file            
WriteParadoxDbCfg             Save ParadoxDb configuration to file              
WriteRestoreDamagedDbProfile  Create and initialize profile for RestoreDamagedDB
                               procedure                                        
WriteSqlDbCfg                 Save SqlDb configuration to file                  
WriteXdbCfg                   Save XDB DB configuration to file                 

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #