const
  ClinicID=1;
var
  DbCfgFn,IdLstFn,FullRenumFn,RenumFn,Cmd: string;
begin
  {Get VisiQuick database configuration file}
  DbCfgFn:=GetDbCfgFnFromVqWorkDir('');
  {Dump patient ID's to file}
  IdLstFn:=GenerateTempFn;
  Cmd:='DumpPatientIDList /db="'+DbCfgFn+'" /out='+'"'+IdLstFn+'" /dentid='+IntToStr(ClinicID);
  ExecUtilsProc(Cmd);
  {Create renumber list trimming spaces}
  FullRenumFn:=GenerateTempFn;
  Cmd:='FilterRenumberList /renumberfn="'+IdLstFn+'" /FilterMode=trim /out='+'"'+FullRenumFn+'"';
  ExecUtilsProc(Cmd);
  {Delete all ID's from renumber list that don't change}
  RenumFn:=GenerateTempFn;
  Cmd:='FilterRenumberList /renumberfn="'+FullRenumFn+'" /FilterMode=filteroutunchanged /out='+'"'+RenumFn+'"';
  ExecUtilsProc(Cmd);
  {Merge patients with spaces}
  Cmd:=' MergePatients /db="'+DbCfgFn+'" /fn="'+RenumFn+'" /clinicid='+IntToStr(ClinicID);
  ExecUtilsProc(Cmd);
end.