96. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 4/12/2018 10:18:33 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

96.1 Files compared

# Location File Last Modified
1 MSSRe Build 4.zip\Applications\VACCR_CRS\GetOncology\GetOncology Program.cs Tue Apr 10 19:46:13 2018 UTC
2 MSSRe Build 4.zip\Applications\VACCR_CRS\GetOncology\GetOncology Program.cs Wed Apr 11 18:19:33 2018 UTC

96.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 2038
Changed 1 2
Inserted 0 0
Removed 0 0

96.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

96.4 Active regular expressions

No regular expressions were active.

96.5 Comparison detail

  1   using Syst em;
  2   using Syst em.Collect ions;
  3   using Syst em.Collect ions.Gener ic;
  4   using Syst em.Collect ions.Speci alized;
  5   using Syst em.Linq;
  6   using Syst em.Text;
  7   using Syst em.IO;
  8   using Syst em.Diagnos tics;
  9   using Syst em.Configu ration;
  10   using Syst em.Reflect ion;
  11   using gov. va.medora. mdo;
  12   using gov. va.medora. mdo.api;
  13   using gov. va.medora. mdo.dao;
  14   using gov. va.medora. mdo.dao.vi sta;
  15   using gov. va.medora. mdo.src;
  16   using gov. va.medora. mdo.src.md o;
  17   using gov. va.medora. mdo.utils;
  18  
  19   namespace  GetOncolog y
  20   {
  21       class  Program
  22       {
  23           // constants
  24                    cons t string c onstScript Name = "Da taTransfor mation.vbs ";
  25                    cons t string c onstLogPre fix = "Onc oTraX_Data _Extractio n";
  26                    cons t string c onstReport Prefix = " OncoTraX";
  27  
  28           // enumerator s
  29           pu blic enum  status {Pr esent, Add ed, Remove d};
  30           pu blic enum  type {New  = 1, Updat ed};
  31                    publ ic enum en tryTypes { Blank, Dat a, Info, E rror };
  32           pu blic enum  nameParts{ City, Stat e};
  33  
  34           // variables
  35           pu blic struc t udSite
  36           {
  37                public s tring ID;
  38                public s tring City ;
  39                public s tring Stat e;
  40                public s tring last New;
  41                public s tring last Updated;
  42                public s tatus site Status;
  43                public s tring newC ount;
  44                             public  string up datedCount ;
  45                    }
  46                    publ ic static  string log Folder;
  47                    publ ic static  string dat aFolder;
  48                    publ ic static  string scr iptFolder;
  49           pu blic stati c string e rrMsg;
  50           pu blic stati c string p rocName;
  51                    publ ic static  string log File;
  52                    publ ic static  string rpt File;
  53           pu blic stati c Dictiona ry<string,  udSite> d icSites =  new Dictio nary<strin g, udSite> ();
  54           pu blic stati c SiteTabl e siteTbl;
  55           pu blic stati c string s iteInfoFil e;
  56           pu blic stati c string s iteTableFi le;
  57  
  58                    stat ic string  fnLaunchVB Script(str ing script Name, bool  waitFinis h)
  59                    {
  60                    //** ********** ********** ********** ********** ********** ********** ********** *****
  61                    //Pu prose:       Executes  a VBScrip t file
  62                    //Pa rameters:    scriptNa me      -  VBScript f ile name w ith full p ath
  63                    //                                 wa itFinish       - Flag  whether t he app sho uld wait f or the scr ipt 
  64                    //                                                            to finis h running
  65                    //Re turns:       Empty st ring on su ccess, err or message  on failur e
  66                    //Re vision His tory:
  67                    //08 /23/11  ZP G Original  creation
  68                    //** ********** ********** ********** ********** ********** ********** ********** *****
  69  
  70                             string  ret = "";
  71  
  72                             try
  73                             {
  74                                      Process  scriptProc  = new Pro cess(); 
  75                                      scriptPr oc.StartIn fo.FileNam e = @"wscr ipt";
  76                                      if (File .Exists(sc riptName))
  77                                      {
  78                                               scriptProc .StartInfo .Arguments  = "//B "  + scriptNa me; //Supp ress error  message p op-ups
  79                                               scriptProc .StartInfo .UseShellE xecute = f alse;
  80                                               scriptProc .StartInfo .ErrorDial og = false ;
  81                                               scriptProc .Start();
  82                                               if (waitFi nish)
  83                                               {
  84                                                       sc riptProc.W aitForExit (); //Run  synchronou sly
  85                                               }
  86                                               if (script Proc != nu ll)
  87                                               {
  88                                                       sc riptProc.C lose();
  89                                               }
  90                                      }
  91                                      else
  92                                      {
  93                                               ret = "Scr ipt could  not be fou nd";
  94                                      }
  95                             }
  96                             catch  (Exception  ex)
  97                             {
  98                                      ret = ex .Message;
  99                             }
  100  
  101                             return  ret;
  102  
  103                    }
  104  
  105                    stat ic void fn SaveSiteIn fo()
  106                    {
  107                    //** ********** ********** ********** ********** ********** ********** ********** *****
  108                    //Pu prose:       Saves la test info  about Vist A sites
  109                    //Pa rameters:    None
  110                    //Re turns:       None
  111                    //Re vision His tory:
  112                    //08 /23/11  ZP G Original  creation
  113                    //** ********** ********** ********** ********** ********** ********** ********** *****
  114  
  115                             string  siteText;
  116                             Stream Writer SW;
  117                             FileIn fo FI;
  118                             udSite  udsCurren t;
  119  
  120                             //Ensu re that di rectory wh ere site i nfo file w ill be sto red exists
  121                             FI = n ew FileInf o(siteInfo File);
  122                             if (Di rectory.Ex ists(FI.Di rectoryNam e) == fals e)
  123                             {
  124                                      try
  125                                      {
  126                                               Directory. CreateDire ctory(FI.D irectoryNa me);
  127                                      }
  128                                      catch (E xception e x)
  129                                      {
  130                         errMsg = " Unable to  establish  folder for  site info  file " +  siteInfoFi le + " ("  + ex.Messa ge + ")";
  131                                               fnLogEntry  (logFile,  errMsg, e ntryTypes. Error);
  132                                      }
  133                             }
  134  
  135                             //Crea te a new s ite info f ile
  136                             if (Di rectory.Ex ists(FI.Di rectoryNam e))
  137                             {
  138                                      try
  139                                      {
  140                                               SW = File. CreateText (siteInfoF ile);
  141                                               try
  142                                               {
  143                                                       // Save heade r
  144                             siteTe xt = Strin g.Format(" {0}\t{1}\t {2}\t{3}\t {4}", "Sit e_ID", "La st_New", " Last_Updat ed", "Site _City", "S ite_State" );
  145                                                       SW .WriteLine (siteText) ;
  146  
  147                                                       // Site info  for each s ite
  148                                                       fo reach (Key ValuePair< string, ud Site> reco rd in dicS ites)
  149                                                       {
  150                                                                udsC urrent = r ecord.Valu e;
  151                                                                if ( udsCurrent .siteStatu s != statu s.Removed)
  152                                                                {
  153                                      siteText  = String. Format("{0 }\t{1}\t{2 }\t{3}\t{4 }", udsCur rent.ID, u dsCurrent. lastNew, u dsCurrent. lastUpdate d, udsCurr ent.City,  udsCurrent .State);
  154                                                                         SW.Wri teLine(sit eText);
  155                                                                }
  156                                                       }
  157                                               }
  158                                               catch (Exc eption ex)
  159                                               {
  160                                                       er rMsg = "Un able to sa ve site in fo (" + ex .Message +  ")";
  161                                                       fn LogEntry(l ogFile, er rMsg, entr yTypes.Err or);
  162                                               }
  163                                               finally
  164                                               {
  165                                                       tr y
  166                                                       {
  167                                                                SW.F lush();
  168                                                                SW.C lose();
  169                                                       }
  170                                                       ca tch (Excep tion ex)
  171                                                       {
  172                                                                fnLo gEntry(log File, ex.M essage, en tryTypes.E rror);
  173                                                       }
  174                                               }
  175                                      }
  176                                      catch (E xception e x)
  177                                      {
  178                         errMsg = " Unable to  create new  site info  file " +  siteInfoFi le + " ("  + ex.Messa ge + ")";
  179                                               fnLogEntry  (logFile,  errMsg, e ntryTypes. Error);
  180                                      }
  181                             }
  182                    }
  183  
  184                    stat ic int fnD ayDiff(Dat eTime star tDate, Dat eTime endD ate)
  185           {
  186                             //**** ********** ********** ********** ********** ********** ********** ********** ***
  187                             //Pupr ose:       Calculates  interval  between 2  dates in d ays
  188                             //Para meters:    startDate        - St art date
  189                             //                                 endD ate          - End da te
  190                             //Retu rns:       Number of  days betwe en 2 speci fied dates
  191                             //Revi sion Histo ry:
  192                             //08/2 3/11  ZPG  Original c reation
  193                             //**** ********** ********** ********** ********** ********** ********** ********** ***
  194  
  195                             System .TimeSpan  diffResult  = endDate .Subtract( startDate) ;
  196  
  197                return d iffResult. Days;
  198           }
  199  
  200           st atic strin g fnGetSit eCityOrSta te(string  siteName,  nameParts  namePart)
  201           {
  202                //****** ********** ********** ********** ********** ********** ********** ********** *
  203                //Pupros e:      Ex tracts nam e of the c ity from a  VistA sit e name
  204                //Parame ters:   si teName     - Name of  the site
  205                //               na mePart     - City or  State
  206                //Return s:      Ex tracted na me of the  city 
  207                //Revisi on History :
  208                //09/02/ 11  ZPG Or iginal cre ation
  209                //****** ********** ********** ********** ********** ********** ********** ********** *
  210  
  211                string r et = "";
  212                string[]  l_arrName ;
  213                char[] a rrReserved Chars = {' <'};
  214                
  215                l_arrNam e = siteNa me.Split(' ,');
  216                if (name Part == na meParts.Ci ty)
  217                {
  218                    ret  = l_arrNam e[0].Trim( );
  219                }
  220                else
  221                {
  222                    if ( l_arrName. Count() <  2)
  223                    {
  224                         ret = "";
  225                    }
  226                    else
  227                    {
  228                         ret = l_ar rName[l_ar rName.Coun t() - 1].T rim();
  229                    }
  230                }
  231  
  232                //Replac e all rese rved chara cters with  spaces
  233                if (ret  != "")
  234                {
  235                    for  (int i = 0 ; i < arrR eservedCha rs.Count() ; i++)
  236                    {
  237                         ret = ret. Replace(ar rReservedC hars[i], '  ');
  238                    }
  239                    ret  = ret.Trim ();
  240                }
  241  
  242                return r et;
  243           }
  244  
  245           st atic strin g fnGetApp Config()
  246                    {
  247                             //**** ********** ********** ********** ********** ********** ********** ********** ***
  248                             //Pupr ose:       Retrieves  applicatio n settings  and estab lishes app lication d efaults
  249                             //Para meters:    None
  250                             //Retu rns:       Empty stri ng on succ ess, error  message o n failure
  251                             //Revi sion Histo ry:
  252                             //08/1 8/11  ZPG  Original c reation
  253                             //**** ********** ********** ********** ********** ********** ********** ********** ***
  254  
  255                             string  ret = "";
  256  
  257                             //Defa ult values
  258                             string  logFolder Default =  ".\\Logs\\ ";
  259                             string  dataFolde rDefault =  ".\\OncoT raX_Data\\ ";
  260                             string  scriptFol derDefault  = AppDoma in.Current Domain.Bas eDirectory ;
  261                             if (sc riptFolder Default.En dsWith("\\ ") == fals e)
  262                             {
  263                                      scriptFo lderDefaul t = script FolderDefa ult + "\\" ;
  264                             }
  265  
  266                             try
  267                             {
  268                                      //Get co nfiguratio n file
  269                                      System.C onfigurati on.Configu ration con fig =
  270                                        Config urationMan ager.OpenE xeConfigur ation(
  271                                                       Co nfiguratio nUserLevel .None);
  272                                      //Get th e AppSetti ngs sectio n.
  273                                      NameValu eCollectio n appSetti ngs =
  274                                         Confi gurationMa nager.AppS ettings;
  275  
  276                                      //Get lo g folder l ocation
  277                                      logFolde r = appSet tings.Get( "LogFolder ");
  278                                      if (logF older == n ull || log Folder.Tri m() == "")
  279                                      {
  280                                               //Save def ault locat ion
  281                                               if (logFol der != nul l)
  282                                               {
  283                                                       co nfig.AppSe ttings.Set tings.Remo ve("LogFol der");
  284                                               }
  285                                               config.App Settings.S ettings.Ad d("LogFold er", logFo lderDefaul t);
  286                                               config.Sav e(Configur ationSaveM ode.Modifi ed);
  287  
  288                                               //Use defa ult locati on
  289                                               logFolder  = logFolde rDefault;
  290                                      }
  291                                      else if  (logFolder .EndsWith( "\\") == f alse)
  292                                      {
  293                                               logFolder  = logFolde r + "\\";
  294                                      }
  295  
  296                                      // Get d ata folder  location
  297                                      dataFold er = appSe ttings.Get ("DataFold er");
  298                                      if (data Folder ==  null || da taFolder.T rim() == " ")
  299                                      {
  300                                               //Save def ault locat ion
  301                                               if (dataFo lder != nu ll)
  302                                               {
  303                                                       co nfig.AppSe ttings.Set tings.Remo ve("DataFo lder");
  304                                               }
  305                                               config.App Settings.S ettings.Ad d("DataFol der", data FolderDefa ult);
  306                                               config.Sav e(Configur ationSaveM ode.Modifi ed);
  307  
  308                                               //Use defa ult locati on
  309                                               dataFolder  = dataFol derDefault ;
  310                                      }
  311                                      else if  (dataFolde r.EndsWith ("\\") ==  false)
  312                                      {
  313                                               dataFolder  = dataFol der + "\\" ;
  314                                      }
  315  
  316                                      // Get s cript fold er locatio n
  317                                      scriptFo lder = app Settings.G et("Script Folder");
  318                                      if (scri ptFolder = = null ||  scriptFold er.Trim()  == "")
  319                                      {
  320                                               //Save def ault locat ion
  321                                               if (script Folder !=  null)
  322                                               {
  323                                                       co nfig.AppSe ttings.Set tings.Remo ve("Script Folder");
  324                                               }
  325                                               config.App Settings.S ettings.Ad d("ScriptF older", sc riptFolder Default);
  326                                               config.Sav e(Configur ationSaveM ode.Modifi ed);
  327  
  328                                               //Use defa ult locati on
  329                                               scriptFold er = scrip tFolderDef ault;
  330                                      }
  331                                      else if  (scriptFol der.EndsWi th("\\") = = false)
  332                                      {
  333                                               scriptFold er = scrip tFolder +  "\\";
  334                                      }
  335  
  336                    // G et site in fo file po inter
  337                    site InfoFile =  appSettin gs.Get("Si teInfo");
  338                    if ( siteInfoFi le == null  || siteIn foFile.Tri m() == "")
  339                    {
  340                         ret = "Una ble to fin d SiteInfo  setting i n applicat ion config uration";
  341                    }
  342  
  343                    // G et site ta ble pointe r
  344                    site TableFile  = appSetti ngs.Get("S iteTable") ;
  345                    if ( siteTableF ile == nul l || siteT ableFile.T rim() == " ")
  346                    {
  347                         ret = "Una ble to fin d SiteTabl e setting  in applica tion confi guration";
  348                    }
  349  
  350                             }
  351                             catch  (Configura tionErrors Exception  ex)
  352                             {
  353                                      ret = ex .Message;
  354                             }
  355  
  356                             return  ret;
  357                    }
  358                    
  359                    stat ic bool fn GetSites()
  360           {
  361                //****** ********** ********** ********** ********** ********** ********** ********** *
  362                //Pupros e:      Fi lls global  Dictionar y object d icSites wi th data
  363                //               fr om last sa ved state  of sites a nd current  listof si tes
  364                //Parame ters:   No ne
  365                //Return s:      Tr ue on succ ess, False  on failur e
  366                //Revisi on History :
  367                //08/18/ 11  ZPG Or iginal cre ation
  368                //****** ********** ********** ********** ********** ********** ********** ********** *
  369  
  370                string[]  l_arrSite ;
  371                udSite u dsCurrent;
  372                bool ret ;
  373  
  374                //Assume  success
  375                ret = tr ue;
  376                
  377                //Get cu rrent list  of sites  from VistA
  378                try
  379                {
  380                    site Tbl = new  SiteTable( siteTableF ile);
  381  
  382                    ILis t listVist A = siteTb l.Sites.Ge tKeyList() ;
  383                    if ( listVistA. Count == 0 )
  384                    {
  385                         errMsg = " List of Vi stA sites  is empty";
  386                                               fnLogEntry  (logFile,  errMsg, e ntryTypes. Error);
  387                         Debug.Prin t(errMsg);
  388                         ret = fals e;
  389                    }
  390                    else  //VistA s ite list i s not empt y
  391                    {
  392                         //Get list  of sites  from site  info file 
  393                         if (System .IO.File.E xists(site InfoFile))
  394                         {
  395                             try 
  396                             {
  397                                 Sy stem.IO.St reamReader  siteInfo  = new Syst em.IO.Stre amReader(s iteInfoFil e);
  398                                 wh ile (siteI nfo.EndOfS tream == f alse)
  399                                 {
  400                                      string s iteCurrent  = siteInf o.ReadLine  ();
  401                                      l_arrSit e = siteCu rrent.Spli t('\t');
  402                                      if (l_ar rSite.Coun t() >= 3)
  403                                      {
  404                                          if ( l_arrSite[ 0] == "Sit e_ID")
  405                                          {
  406                                               //header
  407                                          }
  408                                          else
  409                                          {
  410                                             / /Build a d ictionary  of sites
  411                                               if (dicSit es.Contain sKey(l_arr Site[0]) = = false)
  412                                               {
  413                                                   udsCur rent.ID =  l_arrSite[ 0];
  414                                                   if (li stVistA.Co ntains(l_a rrSite[0]) )
  415                                                   {
  416                                                       ud sCurrent.s iteStatus  = status.P resent;
  417                                                       ud sCurrent.C ity = fnGe tSiteCityO rState(sit eTbl.getSi te(l_arrSi te[0]).Nam e, namePar ts.City);
  418                                                       ud sCurrent.S tate = fnG etSiteCity OrState(si teTbl.getS ite(l_arrS ite[0]).Na me, namePa rts.State) ;
  419                                                   }
  420                                                   else
  421                                                   {
  422                                                       ud sCurrent.s iteStatus  = status.R emoved;
  423                                                       ud sCurrent.C ity = "";
  424                                                       ud sCurrent.S tate = "";
  425                                                   }
  426                                                   udsCur rent.lastN ew = l_arr Site[1];
  427                                                   udsCur rent.lastU pdated = l _arrSite[2 ];
  428                                                   udsCur rent.newCo unt = "";
  429                                                                                                   ud sCurrent.u pdatedCoun t = "";
  430                                                   dicSit es.Add(uds Current.ID , udsCurre nt);
  431                                               }
  432  
  433                                               //Add new  sites
  434                                               for (int i  = 0; i <  listVistA. Count; i++ )
  435                                               {
  436                                                   if (di cSites.Con tainsKey(l istVistA[i ].ToString ()) == fal se)
  437                                                   {
  438                                                       ud sCurrent.I D = listVi stA[i].ToS tring();
  439                                                       ud sCurrent.C ity = fnGe tSiteCityO rState(sit eTbl.getSi te(listVis tA[i].ToSt ring()).Na me, namePa rts.City);
  440                                                       ud sCurrent.S tate = fnG etSiteCity OrState(si teTbl.getS ite(listVi stA[i].ToS tring()).N ame, nameP arts.State );
  441                                                       ud sCurrent.s iteStatus  = status.A dded;
  442                                                       ud sCurrent.l astNew = " ";
  443                                                       ud sCurrent.l astUpdated  = "";
  444                                                       ud sCurrent.n ewCount =  "";
  445                                                                                                            udsC urrent.upd atedCount  = "";
  446                                                       if  (dicSites .ContainsK ey(udsCurr ent.ID) ==  false)
  447                                                       {
  448                                                            dicSites .Add(udsCu rrent.ID,  udsCurrent );
  449                                                       }
  450                                                   }
  451                                               }
  452                                          }
  453                                      }
  454                                      else
  455                                      {
  456                                          ret  = false;
  457                                          errM sg = "Malf ormed site  info file  " + siteI nfoFile;
  458                                                                                  fnLogEnt ry(logFile , errMsg,  entryTypes .Error);
  459                                                                                  Debug.Pr int(errMsg );
  460                                      }
  461                                 }
  462                                 si teInfo.Clo se();
  463                             }
  464                             catch  (Exception  e) 
  465                             {
  466                                 re t=false;
  467                                 er rMsg = "Un able to re ad site in fo file "  + siteInfo File + e.T oString();
  468                                                                fnLo gEntry(log File, errM sg, entryT ypes.Error );
  469                                                                Debu g.Print(er rMsg);
  470                             }   
  471                         }
  472                         else //sit e info fil e not foun d
  473                         {
  474                            //Build  a diction ary of sit es
  475                             for (i nt i = 0;  i < listVi stA.Count;  i++)
  476                             {
  477                                 ud sCurrent.I D = listVi stA[i].ToS tring();
  478                                 ud sCurrent.C ity = "";
  479                                 ud sCurrent.S tate = "";
  480                                 ud sCurrent.s iteStatus  = status.A dded;
  481                                 ud sCurrent.l astNew = " ";
  482                                 ud sCurrent.l astUpdated  = "";
  483                                 ud sCurrent.n ewCount =  "";
  484                                                                udsC urrent.upd atedCount  = "";
  485                                 if  (dicSites .ContainsK ey(udsCurr ent.ID) ==  false)
  486                                 {
  487                                      dicSites .Add(udsCu rrent.ID,  udsCurrent );
  488                                 }
  489                             }
  490                         }
  491                    }
  492                }
  493                catch (E xception e x)
  494                {
  495                    ret= false;
  496                    errM sg = "Unab le to read  list of V istA sites  (" + ex.T oString()  + ")";
  497                                      fnLogEnt ry(logFile , errMsg,  entryTypes .Error);
  498                                      Debug.Pr int(errMsg );
  499                }
  500  
  501                return r et;
  502  
  503           }
  504  
  505           st atic bool  fnGetAbstr acts(strin g siteID)
  506           {
  507                //****** ********** ********** ********** ********** ********** ********** ********** *
  508                //Pupros e:      Ex tracts new  and updat ed OncoTra X abstract s for spec ified site
  509                //               Fu nction use s dicSites  global ob ject to de termine da te interva l
  510                //Parame ters:   si teID  - Si te ID
  511                //Return s:      Tr ue on succ ess, False  on failur
  512                //Revisi on History :
  513                //08/19/ 11  ZPG Or iginal cre ation
  514                //****** ********** ********** ********** ********** ********** ********** ********** *
  515  
  516                bool ret ;
  517                udSite u dsCurr;
  518                String s tartDateNe w;
  519                String s tartDateUp dated;
  520                string s trRet;
  521                string n ewCount =  "";
  522                string u pdatedCoun t = "";
  523  
  524                procName  = "fnGetA bstracts";
  525  
  526                //Assume  success
  527                ret = tr ue;
  528  
  529                //Extrac t site inf o from dic Sites glob al object
  530                if (dicS ites.TryGe tValue(sit eID, out u dsCurr))
  531                {
  532                    if ( udsCurr.si teStatus ! = status.R emoved)
  533                    {
  534                         //Set star t and end  dates
  535                         if (udsCur r.siteStat us == stat us.Added)
  536                         {
  537                             //Retr ieve data  for yester day
  538                             startD ateNew = D ateTime.To day.AddDay s(-1).ToSh ortDateStr ing();
  539                             startD ateUpdated  = DateTim e.Today.Ad dDays(-1). ToShortDat eString();
  540                         }
  541                         else //Sta tus - Pres ent
  542                         {
  543                             startD ateNew = u dsCurr.las tNew;
  544                             startD ateUpdated  = udsCurr .lastUpdat ed;
  545                         }
  546                        
  547                         //Extract  new abstra cts
  548                         strRet = f nExtractDa ta(siteID,  udsCurr.C ity, udsCu rr.State,  startDateN ew, type.N ew, out ne wCount);
  549                         if (strRet  == "")
  550                         {
  551                             udsCur r.newCount  = newCoun t;
  552                             udsCur r.lastNew  = DateTime .Today.ToS hortDateSt ring();
  553                             strRet  = fnExtra ctData(sit eID, udsCu rr.City, u dsCurr.Sta te, startD ateUpdated , type.Upd ated, out  updatedCou nt);
  554                             if (st rRet == "" )
  555                             {
  556                                 ud sCurr.upda tedCount =  updatedCo unt;
  557                                 ud sCurr.last Updated =  DateTime.T oday.ToSho rtDateStri ng();
  558                             }
  559                             else
  560                             {
  561                                 re t = false;
  562                                                                fnLo gEntry(log File, strR et, entryT ypes.Error );
  563                                                                Debu g.Print(st rRet);
  564                             }
  565                             dicSit es.Remove( siteID);
  566                             dicSit es.Add(sit eID, udsCu rr);
  567                         }
  568                         else
  569                         {
  570                             ret =  false;
  571                                                       fn LogEntry(l ogFile, st rRet, entr yTypes.Err or);
  572                                                       De bug.Print( strRet);
  573                         }
  574  
  575                    }
  576                }
  577                else
  578                {
  579                    ret  = false;
  580                    errM sg = procN ame + ": R equested s ite ID " +  siteID +  " is not p resent amo ng availab le sites";
  581                                      fnLogEnt ry(logFile , errMsg,  entryTypes .Error);
  582                                      Debug.Pr int(errMsg );
  583                }
  584  
  585                return r et;
  586  
  587           }
  588  
  589                    stat ic string  fnLogEntry (string lo gFile, str ing entryT ext)
  590                    {
  591                             return  fnFileEnt ry(logFile , entryTex t, entryTy pes.Blank,  true);
  592                    }
  593  
  594                    stat ic string  fnLogEntry (string lo gFile, str ing entryT ext, entry Types entr yType)
  595                    {
  596                             return  fnFileEnt ry(logFile , entryTex t, entryTy pe, false) ;
  597                    }
  598  
  599                    stat ic string  fnFileEntr y(string l ogFile, st ring entry Text, entr yTypes ent ryType, bo ol supress DateTime)
  600                    {
  601                             //**** ********** ********** ********** ********** ********** ********** ****
  602                             // Pur pose       :       Cr eates an e ntry in th e specifie d log file
  603                             // Par ameters:   logFile      - The na me of the  log file.  The log wi ll be
  604                             //                             created  if it does n't exist.  However,  this 
  605                             //                             function  will not  create non existent f olders
  606                             //                entryText    - Text t hat should  be logged
  607                             //                entryType        - Ty pe of log  entry that  will be u sed as a 
  608                             //                             error lo g entry ma rker, such  as ERROR  or WARNING
  609                             // Ret urns:              sR esult      - Empty st ring on su ccess, err or message  on failur e.
  610                             //                             
  611                             // Rev ision Hist ory:
  612                             // 08/ 23/11 ZPG  Original c reation 
  613                             //'*** ********** ********** ********** ********** ********** ********** ******
  614  
  615                             string  sResult =  "";
  616                             Stream Writer SW;
  617                             string  strText =  "";
  618  
  619                             SW = n ull;
  620  
  621                             //Open  the log f ile
  622                             if (Fi le.Exists( logFile) = = false)
  623                             {
  624                                      try
  625                                      {
  626                                               SW = File. CreateText (logFile);
  627                                      }
  628                                      catch (E xception e x)
  629                                      {
  630                                               sResult =  ex.Message ;
  631                                      }
  632                             }
  633                             else
  634                             {
  635                                      try
  636                                      {
  637                                               SW = File. AppendText (logFile);
  638                                      }
  639                                      catch (E xception e x)
  640                                      {
  641                                               sResult =  ex.Message ;
  642                                      }
  643                             }
  644  
  645                             if (SW  != null)
  646                             {
  647                                      //Add da te/time st amp
  648                                      if (supr essDateTim e == false )
  649                                      {
  650                                               strText =  DateTime.N ow.ToStrin g();
  651                                      }
  652  
  653                                      //Add en try type i ndicator
  654                                      if (entr yType == e ntryTypes. Blank)
  655                                      {
  656                                               if (strTex t != "")
  657                                               {
  658                                                       st rText = st rText + ":  ";
  659                                               }
  660                                      }
  661                                      else
  662                                      {
  663                                               strText =  strText +  " [" + ent ryType.ToS tring().To Upper() +  "]: ";
  664                                      }
  665  
  666                                      //Output  log entry  to file
  667                                      try
  668                                      {
  669                                               SW.WriteLi ne(strText  + entryTe xt);
  670                                      }
  671                                      catch (E xception e x)
  672                                      {
  673                                               sResult =  ex.Message ;
  674                                      }
  675                                      finally
  676                                      {
  677                                               try
  678                                               {
  679                                                       SW .Flush();
  680                                                       SW .Close();
  681                                               }
  682                                               catch (Exc eption ex)
  683                                               {
  684                                                       sR esult = ex .Message;
  685                                               }
  686                                      }
  687                             }
  688  
  689                             return  sResult;
  690  
  691                    }
  692  
  693           st atic strin g fnExtrac tData(stri ng siteID,  string si teCity, st ring siteS tate, stri ng startDa te, type e xtractType , out stri ng recCoun t)
  694           {
  695           // ********** ********** ********** ********** ********** ********** ********** *******
  696           // Puprose:       Extrac ts OncoTra X abstract s (new or  updated) f or specifi ed site
  697           //                and da te range t o an outpu t file. 
  698           //                Functi on uses si teTbl and  dicSites g lobal obje cts 
  699           // Parameters :   siteID       - Si te ID
  700           //                siteCi ty    - Ci ty where t he site is  located  
  701           //                siteSt ate   - St ate where  the site i s located   
  702           //                startD ate   - St art date ( end date i s always y esterday)
  703           //                extrac tType - Ty pe of abst racts (New  vs. Updat ed)
  704           //                recCou nt    - Re cord count  (output p arameter)
  705           // Returns:       Empty  string on  success, e rror messa ge on fail ure 
  706           // Revision H istory:
  707           // 08/19/11   ZPG Origin al creatio n
  708           // ********** ********** ********** ********** ********** ********** ********** *******
  709  
  710                string r et = "";
  711                string s trType;
  712                int dayD iff;
  713                string e ndDate;
  714                int quer yType;
  715                udSite u dsCurrent;
  716                DateTime  dtStart;
  717                DateTime  dtEnd;
  718                String s aveFile;
  719  
  720                //Initia lize
  721                recCount  = "";
  722  
  723                //Valida te paramet ers
  724                if (extr actType ==  type.New)
  725                {
  726                    strT ype = "NEW ";
  727                }
  728                else
  729                {
  730                    strT ype = "UPD ATED";
  731                }
  732                    //Si te ID
  733                if (dicS ites.TryGe tValue(sit eID, out u dsCurrent)  == false)
  734                {
  735                    ret  = "Request ed site ID  " + siteI D + " is n ot present  among ava ilable sit es";
  736                                      Debug.Pr int(ret);
  737                }
  738  
  739                if (ret  == "")
  740                {
  741                    //St art date
  742                    if ( DateTime.T ryParse(st artDate, o ut dtStart ) == false )
  743                    {
  744                         ret = "Inv alid start  date " +  startDate  + " specif ied for re trieval of  " + strTy pe +
  745                               " ab stracts fr om site ID  " + siteI D;
  746                         Debug.Prin t(ret);
  747                    }
  748                    else
  749                    {
  750                         dayDiff =  fnDayDiff( dtStart, D ateTime.To day);
  751                         if (dayDif f == 0)
  752                         {
  753                             recCou nt = "-1";
  754                         }
  755                         else if (d ayDiff < 0 )
  756                         {
  757                             ret =  "Future da te " + sta rtDate + "  cannot be  used as s tart date  for retrie val of "
  758                                    + strType  + " abstra cts from s ite ID " +  siteID;
  759                             Debug. Print(ret) ;
  760                         }
  761                    }
  762                }
  763  
  764                if ((ret  == "") &&  (DateTime .TryParse( startDate,  out dtSta rt)) && (r ecCount !=  "-1"))
  765                {
  766                    //En d date is  always yes terday
  767                    endD ate = Date Time.Today .AddDays(- 1).ToShort DateString ();
  768                    dtEn d = DateTi me.Today.A ddDays(-1) ;
  769  
  770                    try
  771                    {
  772                         //Use requ ested site  as data s ource
  773                         Site visit Site = (Si te)siteTbl .Sites[sit eID];
  774                         DataSource  src = vis itSite.get DataSource ByModality ("HIS");
  775  
  776                         //Use gene ric user a ccount to  access Vis tA
  777                         User user;
  778                         user = new  User();
  779                         //user.Nam e = new Pe rsonName(" DEPARTMENT  OF DEFENS E,USER");
  780                         user.Name  = new Pers onName("ON COLOGY,RPC  USER");
  781                         //user.Log onSiteId =  new KeyVa luePair<st ring, stri ng>("200",  "DoD");
  782                         user.Logon SiteId = n ew KeyValu ePair<stri ng, string >(siteID,  "OncoTrax" );
  783                         //user.Log onSiteUid  = "31066";
  784                         user.Logon SiteUid =  "98765";
  785                         //user.SSN  = new Soc SecNum("12 3456789");
  786                         user.SSN =  new SocSe cNum("");
  787                         user.Permi ssionStrin g = "ONC R PC BROKER" ;
  788  
  789                         //Establis h VistA co nnection
  790                         Connection Api cxnApi  = new Con nectionApi (src);
  791                         cxnApi.con nect();
  792                         UserApi us erApi = ne w UserApi( );
  793                         //string d uz = userA pi.visit(c xnApi.MdoC onnection,  user, use r.Permissi onString,  true);
  794  
  795                         VistaConne ction cxn;
  796                         cxn = (Vis taConnecti on)cxnApi. MdoConnect ion;
  797                         try
  798                         {
  799                             //                    ACCESS  CODE  VER IFY CODE    "PERMISSI ON"
  800                             // Ori ginal befo re Verify  Change Bel ow                use rApi.login (cxn, "ONC O/456", "O NCO,789",  "ONC RPC B ROKER");
  801                             userAp i.login(cx n, "ONCO/4 56", "TRAX /123", "ON C RPC BROK ER");
  802                         }
  803                         catch (Exc eption e1)
  804                         {
  805                             if (e1 .Message = = "VERIFY  CODE must  be changed  before co ntinued us e.")
  806                                 us erApi.setN ewPassword (cxn, "ONC O,789", "T RAX/123");
  807                               else if (e 1.Message  == "Securi ty Error:  The remote  procedure  ORWU USER INFO is no t register ed to the  option ONC  RPC BROKE R. (This m essage has  come dire ctly from  IP            ).")
  808                             { //No n Fatal Er ror 
  809                             }
  810                             else
  811                             { // f atal error  of some s ort}
  812                                 re t = "Unabl e to extra ct data fr om site ID  " + siteI D + " (" +  e1.Messag e + ")";
  813                                 De bug.Print( ret);
  814                             }
  815                         }
  816  
  817                         if (cxn.Is Connected  == true)
  818                         {
  819                             Regist riesApi ap i = new Re gistriesAp i();
  820                             queryT ype = (int )extractTy pe;
  821                             Oncolo gyExtract  t = api.ge tOncologyE xtract(cxn , startDat e, endDate , queryTyp e.ToString ());
  822                             recCou nt = t.Tex t.Count(). ToString() ;
  823                             if (t. Text.Count () != 0)
  824                             {
  825                                 // Construct  output fil e name
  826                                 sa veFile = d ataFolder  + siteID +  "_";
  827                                 if  (siteCity .Trim() !=  "")
  828                                 {
  829                                      saveFile  = saveFil e + siteCi ty.Trim(). Replace('  ', '_') +  "_";
  830                                 }
  831                                 if  (siteStat e.Trim() ! = "")
  832                                 {
  833                                      saveFile  = saveFil e + siteSt ate.Trim() .Replace('  ', '_') +  "_";
  834                                 }
  835                                 sa veFile = s aveFile +  strType.Su bstring(0,  1) + "_"  + dtStart. ToString(" yyMMdd") +  "_" + dtE nd.ToStrin g("yyMMdd" );
  836  
  837                                 // Write out  retrieved  records
  838                                 St reamWriter  writer =  new Stream Writer(sav eFile);
  839                                 fo r (int cnt  = 0; cnt  < t.Text.C ount(); cn t++)
  840                                 {
  841                                      writer.W riteLine(t .Text[cnt] );
  842                                      Console. WriteLine( t.Text[cnt ].Length);
  843                                 }
  844                                 wr iter.Flush ();
  845                                 wr iter.Close ();
  846                             }
  847                             cxnApi .disconnec t();
  848                         }
  849                         else
  850                         {
  851                             ret =  "Unable to  establish  connectio n to site  " + siteID ;
  852                                                       De bug.Print( ret);
  853                         }
  854                    }
  855                    catc h (Excepti on ex)
  856                    {
  857                         ret = "Una ble to ext ract data  from site  ID " + sit eID + " ("  + ex.Mess age + ")";
  858                                               Debug.Prin t(ret);
  859                    }
  860                }
  861  
  862                return r et;
  863           }
  864  
  865                    stat ic string  fnReportSi te(string  siteID)
  866                    {
  867                    //** ********** ********** ********** ********** ********** ********** ********** *****
  868                    //Pu prose:       Generate s report t ext for sp ecified si te 
  869                    //                Function  uses site Tbl and di cSites glo bal object
  870                    //Pa rameters:    siteID       - site  ID
  871                    //Re turns:       Report t ext  
  872                    //Re vision His tory:
  873                    //08 /23/11  ZP G Original  creation
  874                    //** ********** ********** ********** ********** ********** ********** ********** *****
  875  
  876                             string  retReport ;
  877                udSite u dsCurr;
  878  
  879                //Extrac t site inf o from dic Sites glob al object
  880                retRepor t = "\tSit e " + site ID + ":" +  "\t";
  881                             if (di cSites.Try GetValue(s iteID, out  udsCurr))
  882                             {
  883                                      if (udsC urr.siteSt atus == st atus.Remov ed)
  884                                      {
  885                                               retReport  = retRepor t + "No lo nger avail able";
  886                                      }
  887                                      else
  888                                      {
  889                                               //New abst ract count
  890                                               retReport  = retRepor t + "New -  ";
  891                                               if (udsCur r.newCount  == "")
  892                                               {
  893                                                       re tReport =  retReport  + "Unable  to retriev e on " + D ateTime.To day.ToShor tDateStrin g();
  894                                               }
  895                         else if (u dsCurr.new Count == " -1")
  896                         {
  897                             retRep ort = retR eport + "A lready ret rieved on  " + DateTi me.Today.T oShortDate String();
  898                         }
  899                         else
  900                         {
  901                             retRep ort = retR eport + ud sCurr.newC ount + " e xtracted o n ";
  902                             retRep ort = retR eport + Da teTime.Tod ay.ToShort DateString ();
  903                         }
  904  
  905                                               //Updated  abstract c ount
  906                                               retReport  = retRepor t + "\t" +  "Updated  - ";
  907                                               if (udsCur r.updatedC ount == "" )
  908                                               {
  909                                                       re tReport =  retReport  + "Unable  to retriev e on " + D ateTime.To day.ToShor tDateStrin g();
  910                                               }
  911                         else if (u dsCurr.upd atedCount  == "-1")
  912                         {
  913                             retRep ort = retR eport + "A lready ret rieved on  " + DateTi me.Today.T oShortDate String();
  914                         }
  915                         else
  916                                               {
  917                             retRep ort = retR eport + ud sCurr.upda tedCount +  " extract ed on ";
  918                                                       re tReport =  retReport  + DateTime .Today.ToS hortDateSt ring();
  919                                               }
  920  
  921                         //Add site  location  info
  922                         if (udsCur r.City ==  "")
  923                         {
  924                             retRep ort = retR eport + "\ t(No city  info, ";
  925                         }
  926                         else
  927                         {
  928                             retRep ort = retR eport + "\ t(" + udsC urr.City +  ", ";
  929                         }
  930                         if (udsCur r.State ==  "")
  931                         {
  932                             retRep ort = retR eport + "N o state in fo)";
  933                         }
  934                         else
  935                         {
  936                             retRep ort = retR eport + "\ t(" + udsC urr.City +  ", ";
  937                             retRep ort = retR eport + ud sCurr.Stat e + ")";
  938                         }
  939                    }
  940                             }
  941                             else / /Should ne ver happen
  942                             {
  943                                      retRepor t = retRep ort + "No  site infor mation";
  944                             }
  945  
  946                             return  retReport ;
  947  
  948                    }
  949  
  950           st atic void  Main(strin g[] args)
  951           {
  952                             String  fileEntry ;
  953  
  954                             //Retr ieve appli cation set tings
  955                             errMsg  = fnGetAp pConfig();
  956  
  957                             //Ensu re that lo g folder e xists
  958                             if (Di rectory.Ex ists(logFo lder) == f alse)
  959                             {
  960                                      try 
  961                                      {
  962                                               Directory. CreateDire ctory(logF older);
  963                                      }
  964                                      catch
  965                                      {
  966                                               //If missi ng log fol der couldn 't be esta blished, c reate logs  in the fo lder conta ining curr ent app
  967                                               logFolder  = Path.Get DirectoryN ame(Assemb ly.GetAsse mbly(typeo f(Program) ).CodeBase );
  968                                               if (logFol der.EndsWi th("\\") = = false)
  969                                               {
  970                                                       lo gFolder =  logFolder  + "\\";
  971                                               }
  972                                      }
  973                             }
  974  
  975                             //Cons truct erro r log file  name
  976                             logFil e = logFol der + cons tLogPrefix  + "_" + D ateTime.No w.ToString ("yyMMdd")  + ".log";
  977  
  978                             //Log  configurat ion error  if there w as a probl em with re ading appl ication se ttings
  979                if (errM sg != "")
  980                {
  981                    fnLo gEntry(log File, errM sg, entryT ypes.Error );
  982                }
  983                else
  984                {
  985                                 // Construct  execution  report fil e name
  986                                 rp tFile = lo gFolder +  constRepor tPrefix +  "_" + Date Time.Now.T oString("y yMM") + ". log";
  987  
  988                    if ( fnGetSites ())
  989                    {
  990                         List<strin g> listSit es = new L ist<string >(dicSites .Keys);
  991  
  992                                          //Ex tract abst racts
  993                         foreach (s tring site ID in list Sites)
  994                         {
  995                                                   fnGetA bstracts(s iteID);
  996                         }
  997  
  998                                          //Ge nerate exe cution rep ort
  999                                          fnLo gEntry(rpt File, "",  entryTypes .Info);
  1000                                          fore ach (strin g siteID i n listSite s)
  1001                                          {
  1002                                                   fileEn try = fnRe portSite(s iteID);
  1003                                                   fnLogE ntry(rptFi le, fileEn try);
  1004                                          }
  1005  
  1006                                          //Up date site  info file
  1007                                          fnSa veSiteInfo ();
  1008  
  1009                                          //Ex ecute data  transform ation scri pt
  1010                                          errM sg = fnLau nchVBScrip t(scriptFo lder + con stScriptNa me, false) ;
  1011                                          if ( errMsg !=  "")
  1012                                          {
  1013                                                   errMsg  = "Error  executing  VBScript "  + scriptF older + co nstScriptN ame + " ("  + errMsg  + ")";
  1014                                                   fnLogE ntry(logFi le, errMsg , entryTyp es.Error);
  1015                                          }
  1016                    }
  1017                }
  1018           }
  1019       }
  1020   }