276. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 12/5/2017 12:06:44 PM Central Standard 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.

276.1 Files compared

# Location File Last Modified
1 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ImagingDicomDCFUtilities\src\java\gov\va\med\imaging\dicom\dcftoolkit\utilities\reconstitution LegacyTextFileParser.java Mon Dec 4 21:35:16 2017 UTC
2 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ImagingDicomDCFUtilities\src\java\gov\va\med\imaging\dicom\dcftoolkit\utilities\reconstitution LegacyTextFileParser.java Mon Dec 4 22:02:44 2017 UTC

276.2 Comparison summary

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

276.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

276.4 Active regular expressions

No regular expressions were active.

276.5 Comparison detail

  1   /**
  2    * 
  3     Package:  MAG - Vis tA Imaging
  4     WARNING:  Per VHA D irective 2 004-038, t his routin e should n ot be modi fied.
  5     Date Cre ated: Sept ember 26,  2006
  6     Site Nam e:  Washin gton OI Fi eld Office , Silver S pring, MD
  7       Developer:          
PETERB
  8     Descript ion: 
  9  
  10           ;;  +-------- ---------- ---------- ---------- ---------- ---------- ---------- +
  11           ;;  Property  of the US  Government .
  12           ;;  No permis sion to co py or redi stribute t his softwa re is give n.
  13           ;;  Use of un released v ersions of  this soft ware requi res the us er
  14           ;;   to execu te a writt en test ag reement wi th the Vis tA Imaging
  15           ;;   Developm ent Office  of the De partment o f Veterans  Affairs,
  16           ;;   telephon e (301) 73 4-0100.
  17           ;;
  18           ;;  The Food  and Drug A dministrat ion classi fies this  software a s
  19           ;;  a Class I I medical  device.  A s such, it  may not b e changed
  20           ;;  in any wa y.  Modifi cations to  this soft ware may r esult in a n
  21           ;;  adulterat ed medical  device un der 21CFR8 20, the us e of which
  22           ;;  is consid ered to be  a violati on of US F ederal Sta tutes.
  23           ;;  +-------- ---------- ---------- ---------- ---------- ---------- ---------- +
  24    */
  25   package go v.va.med.i maging.dic om.dcftool kit.utilit ies.recons titution;
  26  
  27   import gov .va.med.im aging.Size dInputStre am;
  28   import gov .va.med.im aging.dico m.common.i nterfaces. IDicomData Set;
  29   import gov .va.med.im aging.dico m.dcftoolk it.common. impl.Dicom DataSetImp l;
  30   import gov .va.med.im aging.exce ptions.Tex tFileExcep tion;
  31   import gov .va.med.im aging.exce ptions.Tex tFileExtra ctionExcep tion;
  32   import gov .va.med.im aging.exce ptions.Tex tFileNotFo undExcepti on;
  33  
  34   import jav a.io.Buffe redReader;
  35   import jav a.io.FileN otFoundExc eption;
  36   import jav a.io.FileR eader;
  37   import jav a.io.IOExc eption;
  38   import jav a.io.Input StreamRead er;
  39   import jav a.nio.Byte Buffer;
  40   import jav a.nio.Shor tBuffer;
  41   import jav a.util.Arr ayList;
  42   import jav a.util.Has hMap;
  43   import jav a.util.Ite rator;
  44   import jav a.util.reg ex.Pattern ;
  45  
  46   import org .apache.lo gging.log4 j.LogManag er;
  47   import org .apache.lo gging.log4 j.Logger;
  48  
  49   import com .lbs.DCS.A ttributeTa g;
  50   import com .lbs.DCS.D CM;
  51   import com .lbs.DCS.D CSExceptio n;
  52   import com .lbs.DCS.D icomCSElem ent;
  53   import com .lbs.DCS.D icomDataDi ctionary;
  54   import com .lbs.DCS.D icomDataSe t;
  55   import com .lbs.DCS.D icomElemen t;
  56   import com .lbs.DCS.D icomElemen tFactory;
  57   import com .lbs.DCS.D icomFDElem ent;
  58   import com .lbs.DCS.D icomFLElem ent;
  59   import com .lbs.DCS.D icomOBElem ent;
  60   import com .lbs.DCS.D icomOWElem ent;
  61   import com .lbs.DCS.D icomSLElem ent;
  62   import com .lbs.DCS.D icomSQElem ent;
  63   import com .lbs.DCS.D icomSSElem ent;
  64   import com .lbs.DCS.D icomULElem ent;
  65   import com .lbs.DCS.D icomUSElem ent;
  66  
  67   /**
  68    *
  69    * Text Fi le Parser  class. Thi s parser i s specific  to the Vi sta Imagin g Legacy
  70    * environ ment.  The  class wil l parse th e Text fil e passed f rom Archiv ing 
  71    * and bui ld a new D icomDataSe t from the  Text file  informati on.  Then  the class  shall
  72    * wrap th e DicomDat aSet objec t into a g eneric Dic omDataSet  object.  T he wrappin g allows
  73    * the Dic omDataSet  object to  be passed  to the Dic om Generic  Layer.
  74    *
  75    * @author  William P eterson
  76    * extende d by Csaba  Titton
  77    *                        for Vi X streamin
  78    */
  79  
  80   //NOTE 000 8,1032/000 8,0103 and
  81   //               0040 ,0260/0008 ,0103 and
  82   //               0040 ,0275/0040 ,0008/0008 ,0103 has  no value i n output14 .dcm. Inve stigated t he issue.
  83   //      Th is is acce ptable acc ording to  the DICOM  Standard.
  84  
  85   public cla ss LegacyT extFilePar ser {
  86       /*
  87        * Cre ate a Dico mDataSet o bject.  Th is object  is DCF Too lkit speci fic.
  88        */
  89       privat e DicomDat aSet dicom DataSet =  null;
  90       
  91       privat e IDicomDa taSet tool kitDDS = n ull;
  92       
  93       privat e Original PixelDataI nfo origin alPixelDat a = null;
  94       
  95       privat e static L ogger logg er = LogMa nager.getL ogger (Leg acyTextFil eParser.cl ass);
  96       privat e static L ogger test Logger = L ogManager. getLogger( "JUNIT_TES T");
  97  
  98           
  99       /**
  100        * Con structor
  101        */
  102       public  LegacyTex tFileParse r() {
  103           su per();
  104       }
  105       
  106       /**
  107        * Inv oke method  to create  a DicomDa taSet base d on a Tex t file.
  108        * 
  109        * @pa ram textFi lename rep resents th e name (an d path) of  the Text  file.
  110        * @re turn repre sents the  encapsulat ed DicomDa taSet that  is safe f or DicomGe neric Laye r.
  111        * @th rows TextF ileNotFoun dException
  112        * @th rows TextF ileExcepti on
  113        * @th rows TextF ileExtract ionExcepti on
  114        */
  115       public  IDicomDat aSet creat eDicomData Set(String  textFilen ame, Origi nalPixelDa taInfo pix elData)
  116                throws T extFileNot FoundExcep tion, Text FileExcept ion, 
  117                TextFile Extraction Exception{
  118           
  119           lo gger.info( this.getCl ass().getN ame()+": D icom Toolk it Layer:  " +
  120                    "... parsing Te xt file in to DicomDa taSet.");
  121           lo gger.debug ("Text Fil e: "+ text Filename);
  122           th is.origina lPixelData  = pixelDa ta;
  123           Bu fferedRead er buffer  = null;
  124           tr y{
  125                //Get Te xt file.
  126                //JUNIT  Create tes t to verif y how this  fails if  not correc t permissi ons.
  127                buffer =  new Buffe redReader( new FileRe ader(textF ilename));
  128                //Invoke  parser.
  129                this.par seTextFile (buffer, t rue);
  130                //REMIND ER Find ou t why I ha ve the fol lowing lin e.  It doe s not make  sense, bu t
  131                //  I do n't want t o change i t now.  Un sure of ef fects if o mitted.
  132                pixelDat a = this.o riginalPix elData;
  133                //encaps ulate Dico mDataSet o bject.
  134                return ( this.encap sulateDico mDataSet() );
  135           }
  136           ca tch(FileNo tFoundExce ption noFi le){
  137                logger.e rror(noFil e.getMessa ge());
  138                logger.e rror(this. getClass() .getName() +": Dicom  Toolkit la yer: " +
  139                         "Exception  thrown wh ile attemp ting to op en "+textF ilename+". ");
  140                throw ne w TextFile NotFoundEx ception("C ould not f ind or ope n "+textFi lename+"." , noFile);
  141           }
  142           fi nally{
  143                    if(b uffer != n ull){
  144                             try{
  145                                      buffer.c lose();
  146                             }
  147                             catch( Throwable  T){
  148                                      logger.e rror(this. getClass() .getName() +": Dicom  Toolkit la yer: "+
  149                                                       "E xception t hrown whil e closing  Text File  "+textFile name+".");
  150                             }
  151                             System .gc();
  152                    }
  153           }      
  154                    
  155       }
  156       /**
  157        * Inv oke method  to create  a DicomDa taSet base d on a Tex t data str eam.
  158        * 
  159        * @pa ram textSt ream repre sents the  stream of  VistA Imag ing TXT da ta.
  160        * @re turn repre sents the  encapsulat ed DicomDa taSet that  is safe f or DicomGe neric Laye r.
  161        * @th rows TextF ileNotFoun dException
  162        * @th rows TextF ileExcepti on
  163        * @th rows TextF ileExtract ionExcepti on
  164        */
  165       public  IDicomDat aSet creat eDicomData Set(Buffer edReader b uffer, Ori ginalPixel DataInfo p ixelData)
  166                throws   TextFileEx ception, T extFileExt ractionExc eption {
  167           
  168           lo gger.info( "... Dicom  Toolkit L ayer: pars ing Text d ata into D icomDataSe t ...");
  169           lo gger.debug ("... Star t Text Dat a Stream p arsing...  ");
  170           th is.origina lPixelData  = pixelDa ta;
  171  
  172           // Invoke par ser.
  173           th is.parseTe xtFile(buf fer, false );
  174           
  175           pi xelData =  this.origi nalPixelDa ta;
  176           // encapsulat e DicomDat aSet objec t.
  177           re turn (this .encapsula teDicomDat aSet());
  178       }
  179       
  180       /**
  181        * Enc apsulates  the DCF To olkit spec ific Dicom DataSet ob ject.
  182        * 
  183        * @re turn repre sents the  Generic Di comDataSet  object.
  184        */
  185       privat e IDicomDa taSet enca psulateDic omDataSet( ){
  186           
  187           te stLogger.i nfo("... e ncapsulati ng DDS ... ");
  188           tr y{
  189                //toolki tDDS = (ID icomDataSe t)SpringCo ntext.getC ontext().g etBean("Di comDataSet ");
  190                    //to olkitDDS.s etDicomDat aSet(dicom DataSet);
  191                toolkitD DS = new D icomDataSe tImpl(dico mDataSet);
  192           }
  193           ca tch(Except ion e){
  194                logger.e rror("Erro r: " + e.g etMessage( ));
  195                logger.e rror(this. getClass() .getName() +": Dicom  Toolkit la yer: " +
  196                         "Exception  thrown wh ile encaps ulating Di com Datase t.");
  197                e.printS tackTrace( );
  198           }
  199           re turn toolk itDDS;
  200       }
  201       
  202       /**
  203        * Inv oke method  to extrac t HIS upda tes from a n open Tex t data str eam.
  204        * 
  205        * @pa ram buffer  represent s the stre am of Vist A Imaging  TXT data.
  206        * @re turn HashM ap of DICO m tag-valu e pairs to  be update d in DICOM  DataSet.
  207        * @th rows TextF ileExtract ionExcepti on
  208        */
  209       public  HashMap<S tring, Str ing> getHi sUpdates(B ufferedRea der buffer )
  210                throws   TextFileEx ception, T extFileExt ractionExc eption {
  211           
  212           lo gger.info( "... Parsi ng text da ta HIS upd ate sectio n ...");
  213           lo gger.debug ("... Cont inue Text  Data parsi ng for Vis tA updates ... ");
  214  
  215           Ha shMap<Stri ng, String > hisChang es=null;
  216           hi sChanges =  this.pars eHisUpdate s(buffer);
  217           tr y {
  218                    buff er.close() ;
  219           }
  220           ca tch(IOExce ption io){
  221                logger.e rror("Cann ot close T ext Stream  Buffer.") ;
  222                throw ne w TextFile Extraction Exception( );
  223           }
  224           re turn (hisC hanges);
  225       }
  226       
  227       /**
  228        * Inv oke method  to extrac t HIS upda tes from a n open Tex t data str eam.
  229        * 
  230        * @pa ram buffer  represent s the stre am of Vist A Imaging  TXT data.
  231        * @re turn HashM ap of DICO m tag-valu e pairs to  be update d in DICOM  DataSet.
  232        * @th rows TextF ileExtract ionExcepti on
  233        */
  234       public  HashMap<S tring, Str ing> extra ctHisUpdat esfromText Stream(Siz edInputStr eam sizedT extStream)
  235                throws   TextFileEx ception, T extFileExt ractionExc eption {
  236           
  237           lo gger.info( "... Parsi ng text da ta HIS upd ate sectio n ...");
  238           lo gger.debug ("... Star t parsing  VistA upda tes... ");
  239  
  240           Ha shMap<Stri ng, String > hisChang es=null;
  241           Bu fferedRead er buffer  = new Buff eredReader (new Input StreamRead er(sizedTe xtStream.g etInStream ()));
  242  
  243           hi sChanges =  this.pars eHisUpdate s(buffer);
  244           tr y {
  245                    buff er.close() ;
  246           }
  247           ca tch(IOExce ption io){
  248                logger.e rror("Cann ot close T ext Stream  Buffer.") ;
  249                throw ne w TextFile Extraction Exception( );
  250           }
  251           re turn (hisC hanges);
  252       }
  253       
  254       /**
  255        * Par se the Tex t file.  T he Text fi le is made  up of two  sections,  "Data1" a nd 
  256        * "DI COM Data".   Both sec tions are  read and d ecoded.
  257        * 
  258        * @pa ram buffer  represent s the Text  file now  in the for m of a Buf ferReader  object.
  259        * @th rows TextF ileExcepti on
  260        * @th rows TextF ileExtract ionExcepti on
  261        */
  262       privat e void par seTextFile (BufferedR eader buff er, boolea n doClose)  throws Te xtFileExce ption,
  263                TextFile Extraction Exception{
  264           
  265           St ring textL ine = "";
  266           te stLogger.i nfo("... P arsing tex t data top  section . ..");
  267           tr y{
  268                //Loop t hru the li nes until  $$BEGIN DA TA1.
  269                //Ignore  each line  until $$B EGIN DATA1
  270                do{
  271                    text Line = thi s.getNextT extLine(bu ffer);
  272                } while( !(textLine .equals("$ $BEGIN DAT A1")));
  273                
  274                do{
  275                    text Line = thi s.getNextT extLine(bu ffer);
  276                    //Ex tract only  the PATIE NTS_XXX fi elds
  277                    //Re place comm as with ca rats in Pa tient's Na me field
  278                    //10 0507-WFP-R emoving al l IF state ments exce pt DCM_TO_ TGA_PARAME TERS.
  279                    //   Reason is  the applic ation does  not use t his inform ation.  It  serves
  280                    //   no purpose .  But I'm  leaving t he code in  case I'm  wrong.
  281                    /*
  282                    if(t extLine.st artsWith(" PATIENTS_N AME")){
  283                         String pat ientsName  = textLine .substring (textLine. indexOf("= ")+1);
  284                    }
  285                    if(t extLine.st artsWith(" PATIENTS_I D")){
  286                         String pat ientsID =  textLine.s ubstring(t extLine.in dexOf("=") +1);
  287                    }
  288                    if(t extLine.st artsWith(" PATIENTS_B IRTH_DATE" )){
  289                         String pat ientsBirth  = textLin e.substrin g(textLine .indexOf(" =")+1);
  290                    }
  291                    if(t extLine.st artsWith(" PATIENTS_A GE")){
  292                         String pat ientsAge =  textLine. substring( textLine.i ndexOf("=" )+1);
  293                    }
  294                    if(t extLine.st artsWith(" PATIENTS_S EX")){
  295                         String pat ientsSex =  textLine. substring( textLine.i ndexOf("=" )+1);
  296                    }
  297                    if(t extLine.st artsWith(" ACCESSION_ NUMBER")){
  298                         String acc essionNumb er = textL ine.substr ing(textLi ne.indexOf ("=")+1);
  299                    }
  300                    */
  301                    if(t extLine.st artsWith(" DCM_TO_TGA _PARAMETER S")){
  302                         String dcm totgaParam eters = te xtLine.sub string(tex tLine.inde xOf("=")+1 );
  303                         this.origi nalPixelDa ta.setDcmt otgaParame ters(dcmto tgaParamet ers);
  304                    }
  305                    //Pl ace these  PATIENTS_X XX fields  into a tem p DicomDat aSet objec t.
  306                }while(! (textLine. equals("$$ END DATA1" )));
  307                
  308                //Invoke  parseDico mDataSecti on to pars e rest of  file.
  309                this.par seDicomDat aSection(b uffer);
  310                if (doCl ose) 
  311                    buff er.close() ;
  312           }
  313           ca tch(IOExce ption io){
  314                logger.e rror("Cann ot extract  from Text  File.");
  315                logger.e rror("Work ing on Lin e: " + tex tLine);
  316                throw ne w TextFile Extraction Exception( );
  317           }
  318       }
  319       
  320       /**
  321        * Par se the "DI COM Data"  section of  the Text  file.  Thi s is the g runt of th e work
  322        * tha t needs to  be done.
  323        * 
  324        * @pa ram buffer  represent s the Text  file now  in the for m of a Buf feredReade r object.
  325        * @th rows TextF ileExtract ionExcepti on
  326        */
  327       privat e void par seDicomDat aSection(B ufferedRea der buffer )
  328                throws T extFileExt ractionExc eption{
  329           
  330           th is.dicomDa taSet = ne w DicomDat aSet();
  331           St ring textD icomLine =  "";
  332           bo olean sequ enceFlag =  false;
  333           Di comSQEleme nt sequenc eElement =  null;
  334           te stLogger.i nfo("... P arsing tex t data Dic om DataSet  section . ..");
  335           tr y{
  336                //Mark B uffer.
  337                buffer.m ark(255);
  338                //Declar e lineArra y object.
  339                ArrayLis t<String>  lineArray  = new Arra yList<Stri ng>();
  340                //Loop t hru the li nes until  $BEGIN DIC OM DATA.
  341                //Ignore  each line  until $$B EGIN DICOM  DATA. 
  342                do{
  343                    text DicomLine  = this.get NextTextLi ne(buffer) ;
  344                } while( !(textDico mLine.equa ls("$$BEGI N DICOM DA TA")));
  345                
  346                textDico mLine = th is.getNext TextLine(b uffer);
  347   //           testLogg er.debug(" Current Li ne: " + te xtDicomLin e);
  348                //Loop t hru each l ine until  $$END DICO M DATA.
  349                while(!( textDicomL ine.equals ("$$END DI COM DATA") )){
  350                    //Ch eck for Od d Group.
  351                    Stri ng checkGr oup = text DicomLine. substring( 0,4);
  352                    //St ring check Element =  textDicomL ine.substr ing(5,9);
  353                    int  i = Intege r.parseInt (checkGrou p, 16);
  354                    if(t his.isGrou pToBeAdded (i)){
  355                    //If  no Odd gr oup or Gro up 88,
  356                         //Check if  9th chara cter in li ne is a "| ".
  357                         if(!(textD icomLine.s ubstring(9 ,10).equal s("|"))){
  358                         //If no,
  359                             //Add  string to  lineArray  object.
  360                             lineAr ray.add(te xtDicomLin e);
  361                             //Set  Sequence f lag.
  362                             sequen ceFlag = t rue;
  363                         }
  364                         else{
  365                         //If yes, 
  366                             //Chec k if Seque nce flag i s set.
  367                             if(seq uenceFlag) {
  368                             //If y es,
  369                                 // Reset Mark  Buffer.   This allow s to pick  up the ele ment after  the
  370                                 //   sequence  again.
  371                                 bu ffer.reset ();
  372                                 // Invoke ext ractSequen ceData met hod and pa ss lineArr ay.
  373                                 se quenceElem ent = this .extractSe quenceData (lineArray );
  374                                 // Add DicomS QElement o bject to d ds.
  375                                 th is.dicomDa taSet.inse rt(sequenc eElement);
  376                                 // Clean line Array obje ct.
  377                                 li neArray.cl ear();
  378                                 // Unset the  Sequence f lag.
  379                                 se quenceFlag  = false;
  380                             }
  381                             else{
  382                             //If n o,
  383                                 // Invoke ext ractDicomE lement met hod and pa ss the lin e.
  384                                 th is.extract DicomEleme nt(textDic omLine, th is.dicomDa taSet);
  385                             }
  386                         //End If f or "|" del imiter.
  387                         }
  388                    //En d If for O dd Group.
  389                    }
  390                    //Ma rk Buffer.
  391                    buff er.mark(25 5);
  392                    text DicomLine  = this.get NextTextLi ne(buffer) ;
  393   //                 te stLogger.d ebug("Curr ent Line:  " + textDi comLine);
  394  
  395                //End Lo op due to  $$END DICO M DATA or  EOF.
  396                }
  397           }
  398           ca tch(IOExce ption io){
  399                logger.e rror(io.ge tMessage() );
  400                logger.e rror(this. getClass() .getName() +": " +
  401                         "Exception  thrown wh ile readin g Text fil e's Dicom  Data Secti on.");
  402                throw ne w TextFile Extraction Exception( "Failure t o read Dic omData Sec tion.", io );
  403           }
  404           ca tch(Number FormatExce ption numb er){
  405                logger.e rror(numbe r.getMessa ge());
  406                logger.e rror(this. getClass() .getName() +": Workin g on Dicom  Line: " +  textDicom Line);
  407                throw ne w TextFile Extraction Exception( "Failure o n Number F ormat.", n umber);
  408           }
  409           
  410           th is.customT GAElementC leanup();
  411       }
  412       
  413       /**
  414        * Rec ursive met hod to han dle the Se quences an d nested S equences i nside of t he "DICOM
  415        * Dat a" section .
  416        * 
  417        * @pa ram lines  represents  the Array  of Sequen ce lines i n the Text  file.
  418        * @re turn repre sents the  Sequence l ines conve rted into  a single D icom Seque nce Elemen t.
  419        * @th rows TextF ileExtract ionExcepti on
  420        */
  421       privat e DicomSQE lement ext ractSequen ceData(Arr ayList<Str ing> lines )
  422                throws T extFileExt ractionExc eption{
  423           
  424           Di comDataSet  seqDDS =  new DicomD ataSet();
  425           Ar rayList<Di comDataSet > ddsArray List = new  ArrayList <DicomData Set>();
  426           // Create Dic omSQElemen t object.
  427           Di comSQEleme nt sequenc e = null;
  428           
  429           St ring eleme nt = new S tring("");
  430           // Initialize  seqDDS in dex to 0.
  431           in t ddsIndex  = 0;
  432           // Create pre viouseSeqI tem.
  433           St ring previ ousSeqItem  = "";
  434           // Set Sequen ce flag to  false.
  435           bo olean sequ enceFlag =  false;
  436           // Declare se qArray obj ect.
  437           Ar rayList<St ring> seqA rray = new  ArrayList <String>() ;
  438           tr y{
  439           // Loop thru  each line  of lines a rray until  null.  Gr ab line in  Loop.
  440           fo r(int x=0;  x<lines.s ize(); x++ ){
  441                
  442                //Split  line into  two substr ings using  first per iod.
  443                String s eqLine = ( String)lin es.get(x);
  444                String s ubLines[]  = seqLine. split("\\. ",2);
  445                //Assign  first sub string to  Tag.
  446                element  = subLines [0];
  447                //Split  second sub string int o two sub- strings us ing first  carat.
  448                String s ubSubLines [] = subLi nes[1].spl it("\\^",2 );
  449                //Assign  first sub -substring  to seqIte m.
  450                String s eqItem = s ubSubLines [0];
  451                //Assign  second su b-substrin g to seqAr ray object .
  452                String e lementData  = subSubL ines[1];
  453                if(previ ousSeqItem .equals("" )){
  454                //If yes
  455                    //In itialize p reviousSeq Item with  seqItem.
  456                    prev iousSeqIte m = seqIte m;
  457                }
  458                //Check  if first s ub-substri ng matches  seqItem.
  459                if(!(pre viousSeqIt em.equals( seqItem))) {
  460                //If no,
  461                    ddsA rrayList.a dd(seqDDS) ;
  462                    seqD DS = new D icomDataSe t();
  463                    prev iousSeqIte m = seqIte m;
  464                //End If
  465                }
  466                String c heckGroup  = elementD ata.substr ing(0,4);
  467                int g =  Integer.pa rseInt(che ckGroup, 1 6);
  468                if(this. isGroupToB eAdded(g)) {
  469                    //Ch eck if 9th  character  is a "|".   This mea ns another  Sequence.
  470                    //Th is if/else  determine s if the l ine is ano ther seque nce.
  471                    if(! (elementDa ta.substri ng(9,10).e quals("|") )){
  472                         //If no,
  473                         //Add stri ng to seqA rray objec t.
  474                         seqArray.a dd(element Data);
  475                         //Set Sequ ence flag.
  476                         sequenceFl ag = true;
  477                         //If yes,
  478                    }
  479                    else {
  480                         //Check if  Sequence  flag is se t.
  481                         if(sequenc eFlag){
  482                             //If y es,
  483                             //Decr ement line s array in dex.
  484                             x--;
  485                             //Re-i nvoke extr actSequenc eData meth od and pas s lineArra y.
  486                             DicomS QElement s ubSequence  = this.ex tractSeque nceData(se qArray);
  487                             //add  DicomSQEle ment objec t to dds.
  488                             seqDDS .insert(su bSequence) ;
  489                             //Unse t the Sequ ence flag.
  490  
  491                             sequen ceFlag = f alse;
  492                         }
  493                         else{
  494                             //If n o,
  495                             //Invo ke extract DicomEleme nt method  and pass t he second  substring  and
  496                             //  an d temp Dic omDataSet  object.
  497                             this.e xtractDico mElement(e lementData , seqDDS);
  498                             //End  If for Seq uence flag .
  499                         }
  500                         //End If f or "|" del imiter.
  501                    }
  502                    //En d If for G roup Check
  503                }
  504                //Increm ent lines  array inde x.
  505           // Loop thru  lines arra y is compl ete.
  506           }
  507           // Check if S equence fl ag is set.
  508           if (sequenceF lag){
  509           // If yes,
  510                //Re-inv oke extrac tSequenceD ata method  and pass  lineArray.
  511                DicomSQE lement sub Sequence =  this.extr actSequenc eData(seqA rray);
  512                //add Di comSQEleme nt object  to dds.
  513                seqDDS.i nsert(subS equence);
  514                //Unset  the Sequen ce flag.
  515                sequence Flag = fal se;
  516           }
  517           dd sArrayList .add(seqDD S);
  518           dd sIndex = d dsArrayLis t.size();
  519           Di comDataSet  ddsSeqIte ms[] = new  DicomData Set[ddsInd ex];
  520           fo r(int y=0;  y<ddsInde x; y++){
  521               ddsSeqIte ms[y] = dd sArrayList .get(y); 
  522           }
  523           At tributeTag  tag = new  Attribute Tag(elemen t);
  524           se quence = n ew DicomSQ Element(ta g, ddsSeqI tems);
  525           }
  526           ca tch(DCSExc eption dcs ){
  527                logger.e rror(dcs.g etMessage( ));
  528                logger.e rror(this. getClass() .getName() +": " +
  529                         "Exception  thrown wh ile extrac ting Seque nce Data." );
  530                throw ne w TextFile Extraction Exception( "Failure t o extract  Sequence." , dcs);
  531           }
  532           re turn seque nce;
  533       }
  534       
  535       /**
  536        * Ext racts a si ngle parse d line, in dependent  of any seq uences, an d converts  it to a D ICOM 
  537        * Ele ment and s tores the  DICOM Elme nt into th e desired  DCF Toolki t specific  
  538        * Dic omDataSet.
  539        * 
  540        * @pa ram line r epresents  the parsed  line from  the Text  file. 
  541        * @pa ram dds re presents t he DCF Too lkit speci fic DicomD ataSet obj ect.
  542        * @th rows TextF ileExtract ionExcepti on
  543        */
  544       privat e void ext ractDicomE lement(Str ing line,  DicomDataS et dds)
  545                throws T extFileExt ractionExc eption{
  546           // Setup the  ^ parser.
  547           St ring split CaratPatte rn = "\\^" ;
  548           Pa ttern pInf o = Patter n.compile( splitCarat Pattern);
  549           // Setup the  | parser.
  550           St ring split PipePatter n = "\\|";
  551           Pa ttern pFie lds = Patt ern.compil e(splitPip ePattern);
  552           // Setup the  , parser.
  553           St ring split CommaPatte rn = ",";
  554           Pa ttern pTag  = Pattern .compile(s plitCommaP attern);
  555  
  556           St ring field s[] = new  String[4];
  557           fi elds = pFi elds.split (line);
  558           // Parse the  basic data .
  559           // Set the Ta g variable .
  560           St ring tag =  fields[0] ;
  561           
  562           St ring eleme ntInfo = f ields[1];
  563           sh ort elemen tVR = ' ';
  564  
  565           tr y{
  566                Attribut eTag aTag  = new Attr ibuteTag(t ag);
  567                
  568                //Get th e VR.
  569                if(eleme ntInfo.cha rAt(elemen tInfo.leng th()-3) ==  '^'){
  570                    Stri ng subElem entInfo[]  = new Stri ng[2];
  571                    subE lementInfo  = pInfo.s plit(line) ;
  572                    elem entVR = Di comDataDic tionary.ge tVR(subEle mentInfo[1 ]);
  573                    orig inalPixelD ata.setVal ueRepresen tationInTe xtFile(tru e);
  574                }
  575                else{
  576                    elem entVR = Di comDataDic tionary.ge tElementVR (aTag);
  577                    orig inalPixelD ata.setVal ueRepresen tationInTe xtFile(fal se);
  578                }
  579  
  580                String m ultiplicit y;
  581                //This I F makes su re the VM, ML values  exist.
  582                if(field s.length >  2){
  583                    mult iplicity =  fields[2] ;
  584                    //Th is IF make s sure the re is a co mma delimi ter.
  585                    if(m ultiplicit y.indexOf( ",") >= 0) {
  586                         String val ue;
  587                         if(fields. length < 4 ){
  588                             value  = "";
  589                         }
  590                         else{
  591                             value  = fields[3 ];
  592                             if(val ue.equals( "<unknown> ")){
  593                                 va lue = "";
  594                             }
  595                         }
  596                         String mul tiple[] =  multiplici ty.split(" ,");
  597                         //Assign t he VM to a  temp fiel d. |VM,ML|
  598                         int vm = I nteger.par seInt(mult iple[0]);
  599                         //Assign t he ML to a  temp fiel d. |VM,ML|
  600                         int ml = I nteger.par seInt(mult iple[1]);
  601                         //100407-W FP-Discove red DCF do es not han dle VR=OF.   Adding I
  602                         //  statem ent to ign ore any te xt lines w ith this V R value.
  603                         if(element VR == Dico mDataDicti onary.getV R("OF")){
  604                             return ;
  605                         }
  606                         //If VM is  greater t han 1.
  607                         if(vm > 1) {
  608  
  609                             if(ele mentVR ==  DicomDataD ictionary. getVR("OB" )){
  610                                 Di comOBEleme nt element ;
  611                                 by te[] dataA rray = nul l;
  612                                 // If element  already e xist, then  pull the  data and a dd new val ue.
  613                                 if (dds.conta insElement (aTag)){
  614                                      //Extrac t element  from dds.
  615                                      element  = (DicomOB Element)dd s.findElem ent(aTag);
  616                                      //Extrac t the exis ting data  from the e lement
  617                                      ByteBuff er dataBuf fer = elem ent.getBuf fer();
  618                                      dataBuff er.get(dat aArray);
  619                                 }
  620                                 // Assign val ue to nuVa lue.  It u ses Long p rimitive t o make sur e there is  no
  621                                 //   truncati on of data .
  622                                 Lo ng nuValue  = new Lon g(value);
  623                                 // Add nuValu e to exist ing data.
  624                                 by te[] nuArr ay = this. addElement ToByteArra y(dataArra y, nuValue );
  625                                 // You cannot  just add  the nuArra y to the e xisting el ement in t he dds.
  626                                 //   Must cre ate a new  element an d insert i t into the  dds.  Thi s automati cally
  627                                 //   overwrit es the ori ginal elem ent.
  628                                 Di comOBEleme nt updated Element =  new DicomO BElement(a Tag, nuArr ay);
  629                                 dd s.insert(u pdatedElem ent);
  630                             }
  631                             else i f(elementV R == Dicom DataDictio nary.getVR ("US")){
  632                                 Di comUSEleme nt element ;
  633                                 in t[] dataAr ray = null ;
  634                                 // If element  already e xist, then  pull the  data and a dd new val ue.
  635                                 if (dds.conta insElement (aTag)){
  636                                      //Extrac t element  from dds.
  637                                      element  = (DicomUS Element)dd s.findElem ent(aTag);
  638                                      //Extrac t the exis ting data  from the e lement
  639                                      dataArra y = elemen t.getUSDat a();   
  640                                 }
  641                                 // Assign val ue to nuVa lue.  It u ses Long p rimitive t o make sur e there is  no
  642                                 //   truncati on of data .
  643                                 Lo ng nuValue  = new Lon g(value);
  644                                 // Add nuValu e to exist ing data.
  645                                 in t[] nuArra y = this.a ddElementT oIntArray( dataArray,  nuValue);
  646                                 // You cannot  just add  the nuArra y to the e xisting el ement in t he dds.
  647                                 //   Must cre ate a new  element an d insert i t into the  dds.  Thi s automati cally
  648                                 //   overwrit es the ori ginal elem ent.
  649                                 Di comUSEleme nt updated Element =  new DicomU SElement(a Tag, nuArr ay);
  650                                 dd s.insert(u pdatedElem ent);
  651                             }
  652                             else i f(elementV R == Dicom DataDictio nary.getVR ("SL")){
  653                                 Di comSLEleme nt element ;
  654                                 in t[] dataAr ray = null ;
  655                                 // If element  already e xist, then  pull the  data and a dd new val ue.
  656                                 if (dds.conta insElement (aTag)){
  657                                      //Extrac t element  from dds.
  658                                      element  = (DicomSL Element)dd s.findElem ent(aTag);
  659                                      //Extrac t the exis ting data  from the e lement
  660                                      dataArra y = elemen t.getSLDat a();   
  661                                 }
  662                                 // Assign val ue to nuVa lue.  It u ses Long p rimitive t o make sur e there is  no
  663                                 //   truncati on of data .
  664                                 Lo ng nuValue  = new Lon g(value);
  665                                 // Add nuValu e to exist ing data.
  666                                 in t[] nuArra y = this.a ddElementT oIntArray( dataArray,  nuValue);
  667                                 // You cannot  just add  the nuArra y to the e xisting el ement in t he dds.
  668                                 //   Must cre ate a new  element an d insert i t into the  dds.  Thi s automati cally
  669                                 //   overwrit es the ori ginal elem ent.
  670                                 Di comSLEleme nt updated Element =  new DicomS LElement(a Tag, nuArr ay);
  671                                 dd s.insert(u pdatedElem ent);
  672                             }
  673                             else i f(elementV R == Dicom DataDictio nary.getVR ("OW")){
  674                                 Di comOWEleme nt element ;
  675                                 sh ort[] data Array = nu ll;
  676                                 // If element  already e xist, then  pull the  data and a dd new val ue.
  677                                 if (dds.conta insElement (aTag)){
  678                                      //Extrac t element  from dds.
  679                                      element  = (DicomOW Element)dd s.findElem ent(aTag);
  680                                      //Extrac t the exis ting data  from the e lement
  681                                      ShortBuf fer dataBu ffer = (Sh ortBuffer) element.ge tValue();  // 3.2.2c  getShortBu ffer();
  682                                      dataBuff er.get(dat aArray);
  683                                 }
  684                                 // Assign val ue to nuVa lue.  It u ses Long p rimitive t o make sur e there is  no
  685                                 //   truncati on of data .
  686                                 Lo ng nuValue  = new Lon g(value);
  687                                 // Add nuValu e to exist ing data.
  688                                 sh ort[] nuAr ray = this .addElemen tToShortAr ray(dataAr ray, nuVal ue);
  689                                 // You cannot  just add  the nuArra y to the e xisting el ement in t he dds.
  690                                 //   Must cre ate a new  element an d insert i t into the  dds.  Thi s automati cally
  691                                 //   overwrit es the ori ginal elem ent.
  692                                 Di comOWEleme nt updated Element =  new DicomO WElement(a Tag, nuArr ay);
  693                                 dd s.insert(u pdatedElem ent);
  694                             }
  695                             else i f(elementV R == Dicom DataDictio nary.getVR ("SS")){
  696                                 Di comSSEleme nt element ;
  697                                 sh ort[] data Array = nu ll;
  698                                 // If element  already e xist, then  pull the  data and a dd new val ue.
  699                                 if (dds.conta insElement (aTag)){
  700                                      //Extrac t element  from dds.
  701                                      element  = (DicomSS Element)dd s.findElem ent(aTag);
  702                                      //Extrac t the exis ting data  from the e lement
  703                                      dataArra y = elemen t.getSSDat a();   
  704                                 }
  705                                 // Assign val ue to nuVa lue.  It u ses Long p rimitive t o make sur e there is  no
  706                                 //   truncati on of data .
  707                                 Lo ng nuValue  = new Lon g(value);
  708                                 // Add nuValu e to exist ing data.
  709                                 sh ort[] nuAr ray = this .addElemen tToShortAr ray(dataAr ray, nuVal ue);
  710                                 // You cannot  just add  the nuArra y to the e xisting el ement in t he dds.
  711                                 //   Must cre ate a new  element an d insert i t into the  dds.  Thi s automati cally
  712                                 //   overwrit es the ori ginal elem ent.
  713                                 Di comSSEleme nt updated Element =  new DicomS SElement(a Tag, nuArr ay);
  714                                 dd s.insert(u pdatedElem ent);
  715                             }
  716                             else i f(elementV R == Dicom DataDictio nary.getVR ("UL")){
  717                                 Di comULEleme nt element ;
  718                                 in t[] dataAr ray = null ;
  719                                 // If element  already e xist, then  pull the  data and a dd new val ue.
  720                                 if (dds.conta insElement (aTag)){
  721                                      //Extrac t element  from dds.
  722                                      element  = (DicomUL Element)dd s.findElem ent(aTag);
  723                                      //Extrac t the exis ting data  from the e lement
  724                                      dataArra y = elemen t.getULDat a();   
  725                                 }
  726                                 // Assign val ue to nuVa lue.  It u ses Long p rimitive t o make sur e there is  no
  727                                 //   truncati on of data .
  728                                 Lo ng nuValue  = new Lon g(value);
  729                                 // Add nuValu e to exist ing data.
  730                                 in t[] nuArra y = this.a ddElementT oIntArray( dataArray,  nuValue);
  731                                 // You cannot  just add  the nuArra y to the e xisting el ement in t he dds.
  732                                 //   Must cre ate a new  element an d insert i t into the  dds.  Thi s automati cally
  733                                 //   overwrit es the ori ginal elem ent.
  734                                 Di comULEleme nt updated Element =  new DicomU LElement(a Tag, nuArr ay);
  735                                 dd s.insert(u pdatedElem ent);
  736                             }
  737                             else i f(elementV R == Dicom DataDictio nary.getVR ("FL")){
  738                                      DicomFLE lement ele ment;
  739                                 fl oat[] data Array = nu ll;
  740                                 // If element  already e xist, then  pull the  data and a dd new val ue.
  741                                 if (dds.conta insElement (aTag)){
  742                                      //Extrac t element  from dds.
  743                                      element  = (DicomFL Element)dd s.findElem ent(aTag);
  744                                      //Extrac t the exis ting data  from the e lement
  745                                      dataArra y = elemen t.getFLDat a();   
  746                                 }
  747                                 // Assign val ue to nuVa lue.  It u ses Long p rimitive t o make sur e there is  no
  748                                 //   truncati on of data .
  749                                 fl oat nuValu e = new Fl oat(value) ;
  750                                 // Add nuValu e to exist ing data.
  751                                 fl oat[] nuAr ray = this .addElemen tToFloatAr ray(dataAr ray, nuVal ue);
  752                                 // You cannot  just add  the nuArra y to the e xisting el ement in t he dds.
  753                                 //   Must cre ate a new  element an d insert i t into the  dds.  Thi s automati cally
  754                                 //   overwrit es the ori ginal elem ent.
  755                                 Di comFLEleme nt updated Element =  new DicomF LElement(a Tag, nuArr ay);
  756                                 dd s.insert(u pdatedElem ent);
  757                             }
  758                             else i f(elementV R == Dicom DataDictio nary.getVR ("FD")){
  759                                      DicomFDE lement ele ment;
  760                                 do uble[] dat aArray = n ull;
  761                                 // If element  already e xist, then  pull the  data and a dd new val ue.
  762                                 if (dds.conta insElement (aTag)){
  763                                      //Extrac t element  from dds.
  764                                      element  = (DicomFD Element)dd s.findElem ent(aTag);
  765                                      //Extrac t the exis ting data  from the e lement
  766                                      dataArra y = elemen t.getFDDat a();   
  767                                 }
  768                                 // Assign val ue to nuVa lue.  It u ses Long p rimitive t o make sur e there is  no
  769                                 //   truncati on of data .
  770                                 do uble nuVal ue = new D ouble(valu e);
  771                                 // Add nuValu e to exist ing data.
  772                                 do uble[] nuA rray = thi s.addEleme ntToDouble Array(data Array, nuV alue);
  773                                 // You cannot  just add  the nuArra y to the e xisting el ement in t he dds.
  774                                 //   Must cre ate a new  element an d insert i t into the  dds.  Thi s automati cally
  775                                 //   overwrit es the ori ginal elem ent.
  776                                 Di comFDEleme nt updated Element =  new DicomF DElement(a Tag, nuArr ay);
  777                                 dd s.insert(u pdatedElem ent);
  778                             }
  779                             else{ 
  780                                      // at th is point i t is assum ed value V R is of ch ar string,  not binar y!
  781                                 St ring curre ntValue =  "";
  782                                 if (dds.conta insElement (aTag)){
  783                                      // Extra ct element  from dds  -- Must re trieve eac h individu al value t his way
  784                                      // as th e VM is gr eater than  1. -- The n concaten ate togeth er again.
  785                                      DicomEle ment eleme nt = dds.f indElement (aTag);
  786                                      for(int  i=0; i<ele ment.vm();  i++){
  787                                          curr entValue =  currentVa lue.concat (element.g etStringVa lue(i));
  788                                          if(i  < element .vm()-1){
  789                                               currentVal ue = curre ntValue.co ncat("\\") ;
  790                                          }
  791                                      }
  792                                 }
  793                                 el se{
  794                                      currentV alue = nul l;
  795                                 }
  796  
  797                                 // then Appen d a "\\" a nd the Val ue variabl e to this  Tag.
  798                                 Di comElement  updatedEl ement = Di comElement Factory.in stance().c reateEleme nt(aTag,
  799                                          (cur rentValue+ "\\"+value ));
  800                                 dd s.insert(u pdatedElem ent);
  801                             }
  802                         }
  803                         //If ML is  greater t han 1.
  804                         else if(ml  > 1){
  805                             //then  extract t his Tag fr om the dds .
  806                             String  currentVa lue;
  807                             if(dds .containsE lement(aTa g)){
  808                                 cu rrentValue  = dds.get ElementStr ingValue(a Tag);
  809                             }
  810                             else{
  811                                 cu rrentValue  = null;
  812                             }
  813                             //then  Append th e Value va riable to  this Tag.
  814                             if(aTa g.group()  != 0x7FE0) {
  815                                 Di comElement  updatedEl ement = Di comElement Factory.in stance().c reateEleme nt(aTag,
  816                                          (cur rentValue+ value));
  817                                 dd s.insert(u pdatedElem ent);
  818                             }
  819                             if(aTa g.group()  == 0x7FE0) {
  820                                 if (ml == 2){
  821                                      String p arsedValue s[] = valu e.split("= ");
  822                                      String l engthValue  = parsedV alues[1];
  823                                      String p arsedLengt h[] = leng thValue.sp lit(" ");
  824                                      String p ixelDataLe ngth = par sedLength[ 0].trim();
  825                                      Long len gthLong =  new Long(p ixelDataLe ngth);
  826                                      this.ori ginalPixel Data.setOr iginalLeng th(lengthL ong.longVa lue());
  827                                 }
  828                                 if (ml == 3){
  829                                      String p arsedValue s[] = valu e.split("= ");
  830                                      String l engthValue  = parsedV alues[1];
  831                                      String p arsedOffse t[] = leng thValue.sp lit(" ");
  832                                      String p ixelDataOf fset = par sedOffset[ 0].trim();
  833                                      Integer  offsetInt  = new Inte ger(pixelD ataOffset) ;
  834                                      this.ori ginalPixel Data.setOr iginalOffs et(offsetI nt.intValu e());
  835                                 }
  836                             }
  837                         }
  838                         else{
  839                             //FUTU RE The if  sequence w orks.  But  I like to  find a mo re efficie nt way.
  840                             //Attr ibuteTag a Tag = new  AttributeT ag(tag);
  841                             if((aT ag.element () == 0) | | (aTag.el ement() ==  1)){
  842                                 if (aTag.grou p() <= 2){
  843                                      DicomEle ment nuEle ment = Dic omElementF actory.ins tance().cr eateElemen t(aTag,
  844                                               value);
  845                                      dds.inse rt(nuEleme nt);
  846                                 }
  847                             }
  848                             else{
  849                                 if (aTag.grou p() != 0x7 FE0){
  850                                      DicomEle ment nuEle ment = Dic omElementF actory.ins tance().cr eateElemen t(aTag,
  851                                               value);
  852                                      dds.inse rt(nuEleme nt);
  853                                 }
  854                                 if ((aTag.gro up() == 0x 7FE0) && ( aTag.eleme nt() == 0x 0010)) {
  855                                      char isC arat = fie lds[1].cha rAt((field s[1].lengt h())-3);
  856                                      if(isCar at == '^') {
  857                                          Stri ng desc_vr Field = fi elds[1];
  858                                          Stri ng desc_vr [] = desc_ vrField.sp lit("\\^") ;
  859                                          Stri ng textfil eVR = desc _vr[1];
  860                                          orig inalPixelD ata.setOri ginalVR(Di comDataDic tionary.ge tVR(textfi leVR));
  861                                      }
  862                                      else{
  863                                          shor t bitsAllo cated = (s hort)dds.g etElementI ntValue(DC M.E_BITS_A LLOCATED);
  864                                          this .originalP ixelData.s etBitsAllo cated(bits Allocated) ;
  865                                      }
  866                                 }
  867                             }
  868                         }
  869                         //End If f or VM/VL.
  870                    }
  871                }
  872                else if  (fields.le ngth == 2) {
  873                    shor t vr = Dic omDataDict ionary.get ElementVR( aTag);
  874                    if(D icomDataDi ctionary.g etVRString (vr).equal s("SQ")){
  875                         DicomSQEle ment nuEle ment = new  DicomSQEl ement( aTa g, (DicomD ataSet[])n ull );                      
  876                         dds.insert (nuElement );    
  877                    }
  878                }
  879           }
  880           ca tch(DCSExc eption dcs ){
  881                logger.e rror(dcs.g etMessage( ));
  882                logger.e rror(this. getClass() .getName() +": " +
  883                         "Exception  thrown wh ile extrac ting Dicom  Element." );
  884                throw ne w TextFile Extraction Exception( "Failure t o extract  Dicom Elem ent.", dcs );
  885           }
  886       }
  887  
  888       /**
  889        * Par se the Tex t file HIS  Update se ction.  Th e Text fil e is made  up of thre e sections ,
  890        * "Da ta1", "DIC OM Data" a nd  option ally "HIS  UPDATE".   Here only  the HIS UP DATE secti on
  891        * is  read and d ecoded.
  892        * 
  893        * @pa ram buffer  represent s the Text  file now  in the for m of a Buf ferReader  object.
  894        * @th rows TextF ileExtract ionExcepti on
  895        */
  896       //WFP- This does  not appear  to be cor rect.  The re is no s uch sectio n in the . txt file.
  897       //  Wi ll address  later whe n I have t ime.
  898       privat e HashMap< String, St ring> pars eHisUpdate s(Buffered Reader buf fer) 
  899           th rows TextF ileExtract ionExcepti on {
  900           
  901           St ring textL ine = "";
  902           Ha shMap<Stri ng, String > hisUpdat es=null;
  903   //      te stLogger.i nfo("... P arsing tex t data upd ate sectio n ...");
  904           tr y { // par se line fo r initial  "gggg,eeee " or "gggg ,eeee gggg ,eeee" tag s
  905                    do {
  906                       t extLine =  this.getNe xtTextLine (buffer);
  907                    } wh ile(!(text Line.start sWith("$$B EGIN HIS U PDATE")));
  908           }
  909                catch(Te xtFileExtr actionExce ption tfee ) { // cat ch all
  910                    logg er.info("W arning: NO  HIS Updat e section  in text da ta !!!");
  911                    logg er.debug(" Warning: o bsolete TX T format N O VistA up dates !!!  ");
  912                    retu rn hisUpda tes;
  913                }
  914           te xtLine = t his.getNex tTextLine( buffer); / / skip to  first HIS  update lin e
  915           hi sUpdates=n ew HashMap <String, S tring>();
  916               
  917           wh ile(!(text Line.start sWith("$$E ND HIS UPD ATE"))) {
  918               try { //  parse line  for initi al "gggg,e eee" or "g ggg,eeee g ggg,eeee"  tags
  919                       / / and endi ng text va lue 
  920                       S tring spli tPipePatte rn = "\\|" ;
  921                       P attern pFi elds = Pat tern.compi le(splitPi pePattern) ;
  922                       S tring fiel ds[] = new  String[4] ;
  923                       f ields = pF ields.spli t(textLine );
  924                       i f ( ((fiel ds[0].leng th()==9) | | (fields[ 0].length( )==18)) &&
  925                                         (fiel ds[3].leng th()>0)) {
  926                                //  place tag( s)-value p airs to Ha shMap
  927                                his Updates.pu t(fields[0 ], fields[ 3]);
  928                       }
  929               }
  930               catch(Thr owable t)  { // catch  all
  931               }
  932               textLine  = this.get NextTextLi ne(buffer) ;
  933           }  // end wil e
  934           lo gger.debug ("Number o f HIS Upda tes: "+his Updates.si ze());
  935           if  (hisUpdat es.isEmpty ()) 
  936                    retu rn null;
  937           el se 
  938                    retu rn hisUpda tes; 
  939       }
  940  
  941       /**
  942        * Rea ds next li ne from th e Text fil e, which i s now in t he form of  BufferedR eader 
  943        * obj ect.  This  method ch ecks for E OF, nulls,  and blank  lines.  T his is pri marily in
  944        * cas e the Text  file was  not proper ly formatt ed or corr upted.  If  the line  is valid, 
  945        * the  line is r eturned.
  946        * 
  947        * @pa ram in rep resents th e Buffered Reader obj ect.
  948        * @re turn repre sents the  next line  read from  the Buffer edReader o bject.
  949        * @th rows TextF ileExtract ionExcepti on
  950        */
  951       privat e String g etNextText Line(Buffe redReader  in) throws  TextFileE xtractionE xception{
  952           St ring line  = null;
  953           tr y{
  954                do{
  955                    if(( line = in. readLine() ) == null) {
  956                         throw new  TextFileEx tractionEx ception();
  957                    }
  958                }while(l ine.equals (""));
  959           }
  960           ca tch(IOExce ption io){
  961                logger.e rror(io.ge tMessage() );
  962                logger.e rror(this. getClass() .getName() +": " +
  963                         "Exception  thrown wh ile gettin g next lin e from Tex t Line.");
  964                throw ne w TextFile Extraction Exception( "Failure t o get next  line.", i o);
  965           }
  966           re turn line;
  967       }
  968       
  969       privat e boolean  isGroupToB eAdded(int  Group){
  970           bo olean addG roup = tru e;
  971           
  972           // Do not all ow Odd Gro ups
  973           if ((Group %  2) != 0){
  974                addGroup  = false;
  975           }
  976           
  977           // Do not all ow Icon Im age Sequen ces
  978           if (Group ==  0x0088){
  979                addGroup  = false;
  980           }
  981           
  982           // Need to re move Group  0002 elem ents.  Fou nd bug of  sending Gr oup 0002 e lements
  983           //   to CSTor e SCP devi ce.  This  is not val id.  I str ongly beli eve to add  it here.   I do
  984           //   not thin k any code  between h ere and th e sending  uses this  group.  Bu t I could  be 
  985           //   wrong.
  986           if (Group ==  0x0002){
  987                addGroup  = false;
  988           }
  989           
  990           re turn addGr oup;
  991       }
  992       
  993       privat e void cus tomTGAElem entCleanup (){
  994           tr y{
  995                    if(t his.dicomD ataSet.con tainsEleme nt(new Att ributeTag( "0008,0008 "))){
  996                             DicomC SElement o bjectType  = (DicomCS Element)th is.dicomDa taSet.find Element(ne w Attribut eTag("0008 ,0008"));
  997                             String [] values  = objectTy pe.getStri ngData();
  998                             ArrayL ist<String > nuValueA rray = new  ArrayList <String>(v alues.leng th);
  999                             for(in t i=0; i<v alues.leng th; i++){
  1000                                               nuValueArr ay.add(val ues[i]);
  1001                             }
  1002                             while( nuValueArr ay.contain s("")){
  1003                                      nuValueA rray.remov e("");
  1004                             }
  1005                             nuValu eArray.tri mToSize();
  1006                             
  1007                             String [] nuValue s = new St ring[nuVal ueArray.si ze()];
  1008                             Iterat or<String>  iter = nu ValueArray .iterator( );
  1009                             int j  = 0;
  1010                             while( iter.hasNe xt()){
  1011                                      nuValues [j] = iter .next();
  1012                                      j++;
  1013                             }
  1014                             DicomC SElement n uObjectTyp e = new Di comCSEleme nt(new Att ributeTag( "0008,0008 "),
  1015                                                                                                   nu Values);
  1016                             this.d icomDataSe t.insert(n uObjectTyp e);
  1017                    }
  1018           }
  1019           ca tch(DCSExc eption dcs X){
  1020                    //do  nothing
  1021           }
  1022           
  1023       }
  1024       
  1025       privat e byte[] a ddElementT oByteArray (byte[] ol dArray, Lo ng nuValue ){
  1026       
  1027           if (oldArray  == null){
  1028                oldArray  = new byt e[0];
  1029           }
  1030           in t length =  oldArray. length;
  1031           in t index =  length+1;
  1032           by te nuArray [] = new b yte[index] ;
  1033           Sy stem.array copy(oldAr ray, 0, nu Array, 0,  length);
  1034           nu Array[inde x-1] = nuV alue.byteV alue();
  1035           re turn nuArr ay;
  1036       }
  1037       
  1038       privat e short[]  addElement ToShortArr ay(short[]  oldArray,  Long nuVa lue){
  1039           
  1040                int leng th = oldAr ray.length ;
  1041                int inde x = length +1;
  1042                short nu Array[] =  new short[ index];
  1043                System.a rraycopy(o ldArray, 0 , nuArray,  0, length );
  1044                nuArray[ index-1] =  nuValue.s hortValue( );
  1045                return n uArray;
  1046           }
  1047  
  1048       privat e int[] ad dElementTo IntArray(i nt[] oldAr ray, Long  nuValue){
  1049           
  1050                int leng th = oldAr ray.length ;
  1051                int inde x = length +1;
  1052                int nuAr ray[] = ne w int[inde x];
  1053                System.a rraycopy(o ldArray, 0 , nuArray,  0, length );
  1054                nuArray[ index-1] =  nuValue.i ntValue();
  1055                return n uArray;
  1056           }
  1057  
  1058       privat e float[]  addElement ToFloatArr ay(float[]  oldArray,  Float nuV alue){
  1059           
  1060                int leng th = oldAr ray.length ;
  1061                int inde x = length +1;
  1062                float nu Array[] =  new float[ index];
  1063                System.a rraycopy(o ldArray, 0 , nuArray,  0, length );
  1064                nuArray[ index-1] =  nuValue.f loatValue( );
  1065                return n uArray;
  1066           }
  1067  
  1068       privat e double[]  addElemen tToDoubleA rray(doubl e[] oldArr ay, Double  nuValue){
  1069           
  1070                int leng th = oldAr ray.length ;
  1071                int inde x = length +1;
  1072                double n uArray[] =  new doubl e[index];
  1073                System.a rraycopy(o ldArray, 0 , nuArray,  0, length );
  1074                nuArray[ index-1] =  nuValue.d oubleValue ();
  1075                return n uArray;
  1076           }     
  1077   }