341. EPMO Open Source Coordination Office Redaction File Detail Report

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

341.1 Files compared

# Location File Last Modified
1 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\PathologyVistaImagingDataSourceProvider\main\src\java\gov\va\med\imaging\vistaimagingdatasource\pathology\translator VistaImagingPathologyTranslator.java Mon Dec 4 21:35:24 2017 UTC
2 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\PathologyVistaImagingDataSourceProvider\main\src\java\gov\va\med\imaging\vistaimagingdatasource\pathology\translator VistaImagingPathologyTranslator.java Mon Dec 4 22:05:06 2017 UTC

341.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 3 2288
Changed 2 4
Inserted 0 0
Removed 0 0

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

341.4 Active regular expressions

No regular expressions were active.

341.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: Jun  7, 2012
  6     Site Nam e:  Washin gton OI Fi eld Office , Silver S pring, MD
  7       Developer:          
WERFEJ
  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    */
  26   package go v.va.med.i maging.vis taimagingd atasource. pathology. translator ;
  27  
  28   import gov .va.med.Pa tientIdent ifier;
  29   import gov .va.med.Pa tientIdent ifierType;
  30   import gov .va.med.im aging.core .interface s.exceptio ns.MethodE xception;
  31   import gov .va.med.im aging.exce ptions.URN FormatExce ption;
  32   import gov .va.med.im aging.exch ange.busin ess.Site;
  33   import gov .va.med.im aging.path ology.Abst ractPathol ogySite;
  34   import gov .va.med.im aging.path ology.Path ologyAcqui sitionSite ;
  35   import gov .va.med.im aging.path ology.Path ologyCase;
  36   import gov .va.med.im aging.path ology.Path ologyCaseC onsultatio n;
  37   import gov .va.med.im aging.path ology.Path ologyCaseC onsultatio nURN;
  38   import gov .va.med.im aging.path ology.Path ologyCaseS upplementa lReport;
  39   import gov .va.med.im aging.path ology.Path ologyCaseT emplate;
  40   import gov .va.med.im aging.path ology.Path ologyCaseT emplateFie ld;
  41   import gov .va.med.im aging.path ology.Path ologyCaseU pdateAttri buteResult ;
  42   import gov .va.med.im aging.path ology.Path ologyCaseS pecimen;
  43   import gov .va.med.im aging.path ology.Path ologyCaseU RN;
  44   import gov .va.med.im aging.path ology.Path ologyCptCo de;
  45   import gov .va.med.im aging.path ology.Path ologyCptCo deResult;
  46   import gov .va.med.im aging.path ology.Path ologyField URN;
  47   import gov .va.med.im aging.path ology.Path ologyField Value;
  48   import gov .va.med.im aging.path ology.Path ologyReadi ngSite;
  49   import gov .va.med.im aging.path ology.Path ologySaveC aseReportR esult;
  50   import gov .va.med.im aging.path ology.Path ologySite;
  51   import gov .va.med.im aging.path ology.Path ologySnome dCode;
  52   import gov .va.med.im aging.path ology.enum s.Patholog yCaseReser veResult;
  53   import gov .va.med.im aging.path ology.enum s.Patholog yElectroni cSignature Need;
  54   import gov .va.med.im aging.path ology.enum s.Patholog yElectroni cSignature NeedStatus ;
  55   import gov .va.med.im aging.path ology.enum s.Patholog yField;
  56   import gov .va.med.im aging.path ology.enum s.Patholog yReadingSi teType;
  57   import gov .va.med.im aging.tran sactioncon text.Trans actionCont extFactory ;
  58   import gov .va.med.im aging.url. vista.Stri ngUtils;
  59  
  60   import jav a.text.Par seExceptio n;
  61   import jav a.text.Sim pleDateFor mat;
  62   import jav a.util.Arr ayList;
  63   import jav a.util.Dat e;
  64   import jav a.util.Lis t;
  65  
  66   import org .apache.lo gging.log4 j.LogManag er;
  67   import org .apache.lo gging.log4 j.Logger;
  68  
  69   /**
  70    * @author         
WERFEJ
  71    *
  72    */
  73   public cla ss VistaIm agingPatho logyTransl ator
  74   {
  75           pr ivate fina l static L ogger logg er = LogMa nager.getL ogger(Vist aImagingPa thologyTra nslator.cl ass);
  76           
  77           pu blic stati c String t ranslateCa seNote(Str ing vistaR esult)
  78           th rows Metho dException
  79           {
  80                    if(! vistaResul t.startsWi th("1"))
  81                    {
  82                             throw  new Method Exception( "Error ret rieving ca se note: "  + vistaRe sult);
  83                    }
  84                    Stri ng [] line s = String Utils.Spli t(vistaRes ult, Strin gUtils.NEW _LINE);
  85                    Stri ngBuilder  sb = new S tringBuild er();
  86                    for( int i = 1;  i < lines .length; i ++)
  87                    {
  88                             sb.app end(lines[ i].trim()  + "\n");
  89                             /*
  90                             //can' t do a tri m on the r esult from  VistA bec ause the l ast charac ter of the  line migh t be a spa ce which i s needed 
  91                             // for  the XML ( might sepa rate a fie ld from an  attribute )
  92                             //sb.a ppend(line s[i].trim( ));
  93                             String  line = li nes[i];
  94                             // Vis tA trails  each line  with a car riage retu rn, want t o get rid  of that
  95                             if(lin e.endsWith ("\r"))
  96                             {
  97                                      sb.appen d(line.sub string(0,  line.lengt h() - 1));
  98                             }
  99                             else
  100                             {                         
  101                                      sb.appen d(line);
  102                             }*/
  103                    }
  104                    retu rn sb.toSt ring();
  105           }
  106           
  107           
  108           /* *
  109                    0^3
  110                    0^88 001^Not fo und in #81
  111                    1^88 037^LIMITE D AUTOPSY
  112                    1^Vi sit #: 592
  113            *  @param vi staResult
  114            *  @throws M ethodExcep tion
  115            * /
  116           pu blic stati c List<Pat hologyCptC odeResult>  translate SavingCptC ode(String  vistaResu lt)
  117           th rows Metho dException
  118           {
  119                    // J MW 9/4/201 2 TP - Duc  requested  that the  RPC return  the resul ts of each  CPT code  added.  
  120                    // E ven if one  of them f ailed, oth er CPT cod es might h ave been s et success fully 
  121                    /*
  122                    if(! vistaResul t.startsWi th("1"))
  123                    {
  124                             throw  new Method Exception( "Error sav ing CPT co des: " + v istaResult );
  125                    }*/
  126                    List <Pathology CptCodeRes ult> resul t = new Ar rayList<Pa thologyCpt CodeResult >();
  127                    Stri ng [] line s = String Utils.Spli t(vistaRes ult, Strin gUtils.NEW _LINE);
  128                    for( int i = 1;  i < lines .length; i ++)
  129                    {
  130                             String  [] pieces  = StringU tils.Split (lines[i]. trim(), St ringUtils. CARET);
  131                             boolea n success  = pieces[0 ].equals(" 1");
  132                             if(!pi eces[1].st artsWith(" Visit #"))
  133                             {
  134                                      String c ptCode = p ieces[1];
  135                                      String d escription  = pieces[ 2];
  136                                      result.a dd(new Pat hologyCptC odeResult( cptCode, s uccess, de scription) );
  137                             }
  138                    }
  139                    retu rn result;
  140           }
  141           
  142           pu blic stati c String t ranslateSa vingSnomed Code(Strin g vistaRes ult)
  143           th rows Metho dException
  144           {
  145                    if(! vistaResul t.startsWi th("1"))
  146                    {
  147                             throw  new Method Exception( "Error sav ing snomed  codes: "  + vistaRes ult);
  148                    }
  149                    
  150                    Stri ng [] line s = String Utils.Spli t(vistaRes ult, Strin gUtils.NEW _LINE);
  151                    if(l ines.lengt h != 2)
  152                             throw  new Method Exception( "Result di d not cont ain 2 line s, " + vis taResult);
  153                    Stri ng secondL ine = line s[1].trim( );
  154                    Stri ng [] piec es = Strin gUtils.Spl it(secondL ine, Strin gUtils.CAR ET);
  155                    // p iece 1 is  the ID of  the elemen t added
  156                    retu rn pieces[ 1];
  157           }
  158           
  159           pu blic stati c void tra nslateSavi ngCaseNote (String vi staResult)
  160           th rows Metho dException
  161           {
  162                    chec kSuccessfu lResult(vi staResult,  "Error sa ving case  note");   
  163           }
  164           
  165           pu blic stati c void tra nslateDele tingSnomed Code(Strin g vistaRes ult)
  166           th rows Metho dException
  167           {
  168                    chec kSuccessfu lResult(vi staResult,  "Error de leting sno med code") ;       
  169           }
  170           
  171           pu blic stati c void tra nslateSavi ngUserPref erences(St ring vista Result)
  172           th rows Metho dException
  173           {
  174                    chec kSuccessfu lResult(vi staResult,  "Error sa ving patho logy user  preference s");  
  175           }
  176           
  177           pu blic stati c void tra nslateSavi ngCaseSupp lementalRe port(Strin g vistaRes ult)
  178           th rows Metho dException
  179           {
  180                    chec kSuccessfu lResult(vi staResult,  "Error sa ving patho logy case  supplement al report" );  
  181           }
  182           
  183           pu blic stati c void tra nslateSavi ngLockMinu tes(String  vistaResu lt)
  184           th rows Metho dException
  185           {
  186                    chec kSuccessfu lResult(vi staResult,  "Error sa ving lock  minutes");         
  187           }
  188           
  189           pr ivate stat ic void ch eckSuccess fulResult( String vis taResult,  String err orMessage)
  190           th rows Metho dException
  191           {
  192                    if(! vistaResul t.startsWi th("1"))
  193                    {
  194                             throw  new Method Exception( errorMessa ge + ": "  + vistaRes ult);
  195                    }        
  196           }
  197           
  198           /* *
  199            1 ^0^Case ge nerated^SP  12 3
  200            *  @param vi staResult
  201            *  @param or iginalCase Urn
  202            *  @return
  203            * /
  204           pu blic stati c Patholog yCaseURN t ranslateCo pyCase(Str ing vistaR esult, Sit e site, Pa tientIdent ifier pati entIdentif ier)
  205           th rows Metho dException
  206           {
  207                    if(! vistaResul t.startsWi th("1"))
  208                    {
  209                             throw  new Method Exception( "Error cop ying case:  " + vista Result);
  210                    }
  211                    Stri ng [] piec es = Strin gUtils.Spl it(vistaRe sult, Stri ngUtils.CA RET);
  212                    Stri ng newAcce ssionNumbe r = pieces [3];
  213                    Stri ng [] acce ssionNumbe rPieces =  StringUtil s.Split(ne wAccession Number, St ringUtils. SPACE);
  214                    try
  215                    {
  216                             return  Pathology CaseURN.cr eate(site. getSiteNum ber(), 
  217                                               accessionN umberPiece s[0], acce ssionNumbe rPieces[1] , accessio nNumberPie ces[2], pa tientIdent ifier);
  218                    }
  219                    catc h(URNForma tException  urnfX)
  220                    {
  221                             throw  new Method Exception( urnfX);
  222                    }
  223           }
  224           
  225           pu blic stati c boolean  translateC heckPendin gConsultat ions(Strin g vistaRes ult)
  226           th rows Metho dException
  227           {
  228                    // 1 ^0^0 (No p ending con sultations ) or 1^0^1  (Pending  consultati ons) (Succ ess) or 0^ 0^Error de scription  (Failure)
  229                    if(! vistaResul t.startsWi th("1"))
  230                    {
  231                             throw  new Method Exception( "Error che cking pend ing consul tations: "  + vistaRe sult);
  232                    }
  233                    Stri ng [] piec es = Strin gUtils.Spl it(vistaRe sult, Stri ngUtils.CA RET);
  234                    if(p ieces[2].t rim().equa ls("0"))
  235                             return  false;
  236                    retu rn true;
  237                             
  238           }
  239           
  240           pu blic stati c List<Str ing> trans lateUserKe ys(String  vistaResul t)
  241           {
  242                    List <String> r esult = ne w ArrayLis t<String>( );
  243                    Stri ng [] line s = String Utils.Spli t(vistaRes ult, Strin gUtils.NEW _LINE);
  244                    // s kip first  line, cont ains user  info
  245                    for( int i = 1;  i < lines .length; i ++)
  246                    {
  247                             result .add(lines [i].trim() );
  248                    }
  249                    retu rn result;
  250           }
  251  
  252           /* *
  253            *  
  254           1^ 4^CPT Code ^CPT Descr iption^Mul tiply Fact or^Date/Ti me Entered ^User^Visi t List: 59 4;
  255           37 89^Autopsy  Single Or gan^1^07/1 9/2012 13: 57:52^IMAG PROVIDERON ETWOSIX,ON ETWOSIX
  256           28 4^+SP Spec imen^1^07/ 19/2012 13 :56^IMAGPR OVIDERONET WOSIX,ONET WOSIX
  257           14 51^Surgica l Path Ini t Handling ^1^07/19/2 012 13:56^ IMAGPROVID ERONETWOSI X,ONETWOSI X
  258           14 52^Transcr iption Fil e Search R etrieve^1^ 07/19/2012  13:56^IMA GPROVIDERO NETWOSIX,O NETWOSIX
  259            *  
  260            *  
  261            *  @param vi staResult
  262            *  @return
  263            *  @throws M ethodExcep tion
  264            * /
  265           pu blic stati c List<Pat hologyCptC ode> trans lateCptCod esResults( String vis taResult)
  266           th rows Metho dException
  267           {                 
  268                    if(v istaResult .startsWit h("0"))
  269                    {                         
  270                             throw  new Method Exception( "Error get ting CPT c odes: " +  vistaResul t);                     
  271                    }
  272                    List <Pathology CptCode> r esult = ne w ArrayLis t<Patholog yCptCode>( );
  273                    Stri ng [] line s = String Utils.Spli t(vistaRes ult, Strin gUtils.NEW _LINE);
  274                    for( int i = 1;  i < lines .length; i ++)
  275                    {
  276                             result .add(trans lateCptCod eLine(line s[i].trim( )));
  277                    }
  278                    
  279                    retu rn result;           
  280           }
  281  
  282           pr ivate stat ic Patholo gyCptCode  translateC ptCodeLine (String li ne)
  283           th rows Metho dException
  284           {
  285                    Stri ng [] piec es = Strin gUtils.Spl it(line, S tringUtils .CARET);
  286                    Stri ng cptCode  = pieces[ 0];
  287                    Stri ng descrip tion = pie ces[1];
  288                    Stri ng multipl yFactorStr ing = piec es[2];
  289                    Stri ng dateStr ing = piec es[3];
  290                    Stri ng user =  pieces[4];
  291                    
  292                    Inte ger multip lyFactor =  null;
  293                    
  294                    if(m ultiplyFac torString. length() >  0)
  295                    {
  296                             try
  297                             {
  298                                      multiply Factor = I nteger.par seInt(mult iplyFactor String);
  299                             }
  300                             catch( NumberForm atExceptio n nfX)
  301                             {
  302                                      throw ne w MethodEx ception(nf X);
  303                             }
  304                    }
  305                    
  306                    Date  dateEnter ed = parse DateString (dateStrin g);
  307                    
  308                    retu rn new Pat hologyCptC ode(cptCod e, descrip tion, mult iplyFactor , dateEnte red, user) ;                    
  309           }
  310           
  311           pu blic stati c List<Pat hologySnom edCode> tr anslateSno medResults (String vi staResult)
  312           th rows Metho dException
  313           {
  314                    if(v istaResult .startsWit h("0"))
  315                    {                         
  316                             throw  new Method Exception( "Error get ting CPT c odes: " +  vistaResul t);                     
  317                    }
  318                    Stri ng [] line s = String Utils.Spli t(vistaRes ult, Strin gUtils.NEW _LINE);
  319                    List <Pathology SnomedCode > tissues  = new Arra yList<Path ologySnome dCode>();
  320                    for( int i = 1;  i < lines .length; i ++)
  321                    {
  322                             tissue s.add(tran slateSnome dLine(line s[i].trim( )));
  323                    }
  324                    
  325                    retu rn tissues ;
  326           }
  327           
  328           pr ivate stat ic Patholo gySnomedCo de transla teSnomedLi ne(String  snomedLine )
  329           th rows Metho dException
  330           {
  331                    
  332                    // o ld (no lon ger used)
  333                    // 1 |LIVER^1|M ORPHOLOGY^ HEPATOCELL ULAR CARCI NOMA                 
  334                    // 3 |PROSTATE^ 1|MORPHOLO GY^XANTHOM A, VERRUCI FORM^ETIOL OGY: IODIN E RADIOISO TOPE
  335                    
  336                    // n ew (7/25/2 012)
  337                    // 1 |56^LIVER^ |PROCEDURE ^395^ENDOS COPIC BRUS H BIOPSY
  338                    // 1 |56^LIVER^ 1|MORPHOLO GY^77^HEPA TOCELLULAR  CARCINOMA ^ETIOLOGY^ 1176^RIO B RAVO VIRUS
  339                    // 1 |56^LIVER^ 2|MORPHOLO GY^2238^PL ASMA MEMBR ANE ALTERA TION
  340                    
  341                    // n ewer (8/21 /2012) (EM  00 1)
  342                    // 1 |56000^LIV ER^1|PROCE DURE^1341^ ENDOSCOPIC  BRUSH BIO PSY
  343                    // 1 |56000^LIV ER^1|MORPH OLOGY^8170 3^HEPATOCE LLULAR CAR CINOMA^1|E TIOLOGY^38 78^RIO BRA VO VIRUS
  344                    // 1 |56000^LIV ER^2|MORPH OLOGY^6700 0^PLASMA M EMBRANE AL TERATION
  345                    
  346                    Stri ng [] stic kPieces =  StringUtil s.Split(sn omedLine,  StringUtil s.STICK);
  347                    Stri ng id = st ickPieces[ 0];
  348                    Stri ng [] tiss uePieces =  StringUti ls.Split(s tickPieces [1].trim() , StringUt ils.CARET) ;
  349                    Stri ng tissueC ode = tiss uePieces[0 ];
  350                    Stri ng tissue  = tissuePi eces[1];
  351                    Stri ng snomedI d = null;
  352                    if(t issuePiece s.length > = 3)
  353                             snomed Id = tissu ePieces[2] ;
  354                    Path ologyField  field = n ull;
  355                    Stri ng snomedV alue = nul l;
  356                    Stri ng snomedC ode = null ;
  357                    Stri ng etiolog ySnomedVal ue = null;
  358                    Stri ng etiolog ySnomedCod e = null;
  359                    Stri ng etiolog yId = null ;
  360                    if(s tickPieces .length >=  3)
  361                    {
  362                             String  [] snomed Pieces = S tringUtils .Split(sti ckPieces[2 ].trim(),  StringUtil s.CARET);
  363                             String  fieldType  = snomedP ieces[0];
  364                             field  = Patholog yField.val ueOf(field Type.toLow erCase());
  365                             snomed Code = sno medPieces[ 1];
  366                             snomed Value = sn omedPieces [2];
  367                             if(sno medPieces. length >=  4)
  368                             {
  369                                      etiology Id = snome dPieces[3] ;
  370                             }
  371                    }
  372                    if(s tickPieces .length >=  4)
  373                    {
  374                             // the re is an e tiology va lue
  375                             if(fie ld != Path ologyField .morpholog y)
  376                                      throw ne w MethodEx ception("T issue cont ains etiol ogy but is  not morph ology, " +  snomedLin e);
  377                             String  [] etiolo gyPieces =  StringUti ls.Split(s tickPieces [3].trim() , StringUt ils.CARET) ;
  378                             etiolo gySnomedCo de = etiol ogyPieces[ 1];
  379                             etiolo gySnomedVa lue = etio logyPieces [2]; 
  380                    }
  381                    
  382                    if(s nomedValue  == null)
  383                             return  Pathology SnomedCode .createTis sue(id, ti ssueCode,  tissue);
  384                    if(f ield == Pa thologyFie ld.morphol ogy)
  385                    {
  386                             if(eti ologySnome dValue !=  null)
  387                             {
  388                                      return P athologySn omedCode.c reateMorph ologySnome dCode(id,  tissueCode , tissue, 
  389                                                       sn omedId, sn omedCode,  snomedValu e, etiolog yId, etiol ogySnomedC ode, etiol ogySnomedV alue);
  390                             }
  391                             else
  392                             {
  393                                      return P athologySn omedCode.c reateMorph ologySnome dCode(id,  tissueCode , tissue, 
  394                                                       sn omedId, sn omedCode,  snomedValu e);
  395                             }
  396                    }
  397                    else
  398                    {
  399                             return  Pathology SnomedCode .createSno medCode(id , tissueCo de, tissue , snomedId , field, s nomedCode,  snomedVal ue);
  400                    }
  401           }
  402           
  403           pu blic stati c String t ranslateUs erPreferen ces(String  vistaResu lt)
  404           th rows Metho dException
  405           {
  406                    if(v istaResult .startsWit h("0"))
  407                    {
  408                             throw  new Method Exception( "Error get ting user  preference s: " + vis taResult);
  409                    }
  410                    Stri ng [] line s = String Utils.Spli t(vistaRes ult, Strin gUtils.NEW _LINE);
  411                    Stri ngBuilder  sb = new S tringBuild er();
  412                    for( int i = 1;  i < lines .length; i ++)
  413                    {
  414                             //can' t do a tri m on the r esult from  VistA bec ause the l ast charac ter of the  line migh t be a spa ce which i s needed 
  415                             // for  the XML ( might sepa rate a fie ld from an  attribute )
  416                             //sb.a ppend(line s[i].trim( ));
  417                             String  line = li nes[i];
  418                             // Vis tA trails  each line  with a car riage retu rn, want t o get rid  of that
  419                             if(lin e.endsWith ("\r"))
  420                             {
  421                                      sb.appen d(line.sub string(0,  line.lengt h() - 1));
  422                             }
  423                             else
  424                             {                         
  425                                      sb.appen d(line);
  426                             }
  427                    }
  428                    retu rn sb.toSt ring();
  429           }
  430           
  431           pu blic stati c int tran slateLockM inutes(Str ing vistaR esult)
  432           th rows Metho dException
  433           {
  434                    if(v istaResult .startsWit h("0"))
  435                    {
  436                             throw  new Method Exception( "Error get ting lock  minutes: "  + vistaRe sult);
  437                    }
  438                    Stri ng [] line s = String Utils.Spli t(vistaRes ult, Strin gUtils.NEW _LINE);
  439                    if(l ines.lengt h <= 1)
  440                             throw  new Method Exception( "Error get ting lock  minutes: "  + vistaRe sult);
  441                    try
  442                    {
  443                             return  Integer.p arseInt(li nes[1].tri m());
  444                    }
  445                    catc h(NumberFo rmatExcept ion nfX)
  446                    {
  447                             throw  new Method Exception( nfX);
  448                    }
  449           }
  450           
  451           pu blic stati c List<Pat hologySite > translat eSites(Str ing vistaR esult)
  452           th rows Metho dException
  453           {
  454                    if(v istaResult .startsWit h("0"))
  455                    {
  456                             throw  new Method Exception( "Error get ting patho logy sites : " + vist aResult);
  457                    }
  458                    Stri ng [] line s = String Utils.Spli t(vistaRes ult, Strin gUtils.NEW _LINE);
  459                    List <Pathology Site> site s = new Ar rayList<Pa thologySit e>();
  460                    for( int i = 1;  i < lines .length; i ++)
  461                    {
  462                             sites. add(transl ateSite(li nes[i].tri m()));
  463                    }
  464                    retu rn sites;            
  465           }
  466           
  467           pr ivate stat ic Patholo gySite tra nslateSite (String li ne)
  468           {
  469                    Stri ng [] piec es = Strin gUtils.Spl it(line, S tringUtils .CARET);
  470                    
  471                    retu rn new Pat hologySite (pieces[0] , pieces[1 ], pieces[ 2], pieces [3]);
  472           }
  473           
  474           pu blic stati c List<Pat hologyFiel dValue> tr anslateFie ldValues(S tring vist aResult, S ite site,  PathologyF ield field )
  475           th rows Metho dException
  476           {
  477                    if(v istaResult .startsWit h("1"))
  478                    {
  479                             List<P athologyFi eldValue>  result = n ew ArrayLi st<Patholo gyFieldVal ue>();
  480                             String  [] lines  = StringUt ils.Split( vistaResul t, StringU tils.NEW_L INE);
  481                             for(in t i = 1; i  < lines.l ength; i++ )
  482                             {
  483                                      result.a dd(transla teFieldVal ue(lines[i ].trim(),  site, fiel d));
  484                             }
  485                             return  result;
  486                    }
  487                    else
  488                             throw  new Method Exception( "Error ret rieving fi eld values , " + vist aResult);
  489           }
  490           
  491           pr ivate stat ic Patholo gyFieldVal ue transla teFieldVal ue(String  line,
  492                             Site s ite, Patho logyField  field)
  493           th rows Metho dException
  494           {
  495                    Stri ng [] piec es = Strin gUtils.Spl it(line, S tringUtils .CARET);
  496                    Stri ng ien = p ieces[0];
  497                    Stri ng name =  pieces[1];
  498                    if(p ieces.leng th >= 3)
  499                    {
  500                             String  code = pi eces[2];
  501                             if(cod e != null  && code.le ngth() > 0 )
  502                                      name = n ame + Stri ngUtils.CA RET + code ;
  503                    }
  504                    
  505                    try
  506                    {
  507                             Pathol ogyFieldUR N fieldUrn  = Patholo gyFieldURN .create(si te.getSite Number(),  field, ien );                 
  508                             return  new Patho logyFieldV alue(field Urn, name) ;
  509                    }
  510                    catc h(URNForma tException  urnfX)
  511                    {
  512                             throw  new Method Exception( urnfX);
  513                    }
  514           }
  515           
  516           /*
  517                    0^^E lectronic  Signature  authorized
  518                    -1^^ ERROR: [MU MPS error]
  519                    -2^^ ERROR: Mis sing AP Se ction
  520                    1^^E lectronic  Signature  not enable d
  521                    2^^E lectronic  signature  not author ized: miss ing PROVID ER key
  522                    3^^E lectronic  Signature  not author ized: PROV IDER CLASS  must incl ude PHYSIC IAN, or CY TOTECHNOLO GIST for C Y sections  only, or  DENTIST fo r oral and  maxillofa cial patho logy
  523                    4^^E lectronic  Signature  not author ized: PERS ON CLASS i s inactive  or undefi ned
  524                    5^^E lectronic  Signature  not author ized: PERS ON CLASS h as expired
  525                    6^^E lectronic  Signature  not author ized: inva lid PERSON  CLASS
  526  
  527            * /
  528           pu blic stati c Patholog yElectroni cSignature Need trans lateElectr onicSignat ureNeedRes ult(String  vistaResu lt)
  529           th rows Metho dException
  530           {
  531                    Stri ng [] piec es = Strin gUtils.Spl it(vistaRe sult, Stri ngUtils.CA RET);
  532                    
  533                    Stri ng statusC ode = piec es[0].trim ();
  534                    Stri ng msg = p ieces[2].t rim();
  535                    
  536                    if(s tatusCode. startsWith ("-"))
  537                    {
  538                             throw  new Method Exception( msg);
  539                    }
  540                    
  541                    if(s tatusCode. startsWith ("0"))
  542                             return  new Patho logyElectr onicSignat ureNeed(Pa thologyEle ctronicSig natureNeed Status.aut horized_ne eds_signat ure, msg);
  543                    if(s tatusCode. startsWith ("1"))
  544                             return  new Patho logyElectr onicSignat ureNeed(Pa thologyEle ctronicSig natureNeed Status.not _enabled,  msg);
  545                    else  
  546                             return  new Patho logyElectr onicSignat ureNeed(Pa thologyEle ctronicSig natureNeed Status.not _authorize d, msg);
  547                    
  548           }
  549           
  550           pu blic stati c Patholog yCaseTempl ate transl ateTemplat e(String v istaResult )
  551           th rows Metho dException
  552           {
  553                    if(v istaResult .startsWit h("1"))
  554                    {
  555                             List<P athologyCa seTemplate Field> fie lds = new  ArrayList< PathologyC aseTemplat eField>();
  556                             
  557                             String  [] lines  = StringUt ils.Split( vistaResul t, StringU tils.NEW_L INE);
  558                             for(in t i = 1; i  < lines.l ength; i++ )
  559                             {
  560                                      fields.a dd(transla teFieldLin e(lines[i] .trim()));
  561                             }
  562                             
  563                             return  new Patho logyCaseTe mplate(fie lds);
  564                    }
  565                    else
  566                    {
  567                             throw  new Method Exception( "Error ret rieving su pplemental  reports,  " + vistaR esult);
  568                    }
  569           }
  570           
  571           /* *
  572            . 012^SPECIM EN^Skin|
  573            *  @param li ne
  574            *  @return
  575            * /
  576           pr ivate stat ic Patholo gyCaseTemp lateField  translateF ieldLine(S tring line )
  577           {
  578                    Stri ng [] piec es = Strin gUtils.Spl it(line, S tringUtils .CARET);
  579                    Stri ng fieldNu mber = pie ces[0];
  580                    Stri ng label =  pieces[1] ;
  581                    Stri ng [] valu ePieces =  StringUtil s.Split(pi eces[2].tr im(), Stri ngUtils.ST ICK);
  582                    List <String> v alues = ne w ArrayLis t<String>( );
  583                    for( String val uePiece :  valuePiece s)
  584                    {
  585                             // if  the values  end with  a stick th en the Spl it above w ill includ e the piec e after th e trailing  stick as  a value, c heck for a n empty st ring to ex lcude 
  586                             if(val uePiece !=  null && v aluePiece. length() >  0)
  587                                      values.a dd(valuePi ece);
  588                    }
  589                    retu rn new Pat hologyCase TemplateFi eld(fieldN umber, lab el, values );
  590           }
  591           
  592           pu blic stati c List<Pat hologyCase Supplement alReport>  translateS upplementa lReports(S tring vist aResult)
  593           th rows Metho dException
  594           {
  595                    if(v istaResult .startsWit h("1"))
  596                    {
  597                             List<P athologyCa seSuppleme ntalReport > suppleme ntalReport s = 
  598                                      new Arra yList<Path ologyCaseS upplementa lReport>() ;
  599                             
  600                             String  [] lines  = StringUt ils.Split( vistaResul t, StringU tils.NEW_L INE);
  601                             for(in t i = 1; i  < lines.l ength; i++ )
  602                             {
  603                                      suppleme ntalReport s.add(tran slateSuppl ementalRep ort(lines[ i].trim()) );
  604                             }
  605                             
  606                             return  supplemen talReports ;
  607                    }
  608                    else
  609                    {
  610                             throw  new Method Exception( "Error ret rieving su pplemental  reports,  " + vistaR esult);
  611                    }
  612           }
  613           
  614           pr ivate stat ic Patholo gyCaseSupp lementalRe port trans lateSupple mentalRepo rt(String  line)
  615           {
  616                    Stri ng [] piec es = Strin gUtils.Spl it(line, S tringUtils .CARET);
  617                    Stri ng supplem entalRepor tDateStrin g = pieces [0];
  618                    Stri ng verifie dString =  pieces[1];
  619                    Stri ng verifie dBy = piec es[2];
  620                    Stri ng values  = pieces[3 ];
  621                    Stri ng [] valu ePieces =  StringUtil s.Split(va lues, Stri ngUtils.ST ICK);
  622                    
  623                    Date  supplemen talReportD ate = pars eDateStrin g(suppleme ntalReport DateString );
  624                    
  625                    retu rn new Pat hologyCase Supplement alReport(s upplementa lReportDat e, verifie dString.eq ualsIgnore Case("YES" ), 
  626                                      (verifie dBy.length () > 0 ? v erifiedBy  : null), v aluePieces );
  627                    
  628           }
  629           
  630           pu blic stati c String t ranslatePa thologyRep ort(String  vistaResu lt)
  631           th rows Metho dException
  632           {
  633                    if(v istaResult .startsWit h("1"))
  634                    {
  635                             String  [] lines  = StringUt ils.Split( vistaResul t, StringU tils.NEW_L INE);
  636                             String Builder re sult = new  StringBui lder();
  637                             String  prefix =  "";
  638                             for(in t i = 1; i  < lines.l ength; i++ )
  639                             {
  640                                      result.a ppend(pref ix);
  641                                      result.a ppend(line s[i].trim( ));
  642                                      prefix =  "\n";
  643                             }
  644                             return  result.to String();
  645                    }
  646                    else
  647                    {
  648                             throw  new Method Exception( "Error ret rieving re port, " +  vistaResul t);
  649                    }
  650           }
  651           
  652           pu blic stati c String t ranslateTe mplate(Str ing vistaR esult, Str ing apSect ion)
  653           th rows Metho dException   
  654           {
  655                    if(v istaResult  == null)
  656                             throw  new Method Exception( "Null resp onse from  VistA");
  657                    Stri ng [] line s = String Utils.Spli t(vistaRes ult, Strin gUtils.NEW _LINE);
  658                    if(l ines[0].st artsWith(" 0"))
  659                    {
  660                             String  []pieces  = StringUt ils.Split( lines[0],  StringUtil s.CARET);
  661                             if(pie ces.length  >= 3)
  662                             {
  663                                      throw ne w MethodEx ception("E rror retri eving temp late for ' " + apSect ion + "',  " + pieces [2]);
  664                             }
  665                             else
  666                             {
  667                                      throw ne w MethodEx ception("E rror retri eving temp late for ' " + apSect ion + "'." );
  668                             }
  669                    }
  670                    Stri ngBuilder  result = n ew StringB uilder();
  671                    for( int i = 1;  i < lines .length; i ++)
  672                    {
  673                             result .append(li nes[i].tri m() + "\n" );
  674                    }                 
  675                    retu rn result. toString() ;
  676           }
  677           
  678           pu blic stati c Patholog yCaseUpdat eAttribute Result tra nslatePutC aseResult( String vis taResult)
  679           {
  680                    if(v istaResult .startsWit h("1"))
  681                    {
  682                             // suc cess
  683                             return  Pathology CaseUpdate AttributeR esult.crea teSuccessf ulLockResu lt();
  684                    }
  685                    else
  686                    {
  687                             String  [] pieces  = StringU tils.Split (vistaResu lt, String Utils.CARE T);
  688                             return  Pathology CaseUpdate AttributeR esult.crea teFailedLo ckResult(p ieces[2]);
  689                    }
  690           }
  691                    
  692           /* *
  693            *
  694                    -5^^ Update err or [Filema n error te xt]
  695                    -4^^ One or mor e input pa rameters a re missing
  696                    -3^^ No accessi on code fo r this cas e
  697                    -2^^ File locke d by [user ] since [d ate-time]             <- Duc, ag reed that  this error  code will  remain
  698                    -1^^ ERROR [MUM PS error]
  699                    0^0^ File unloc ked
  700                    0^1^ File locke d
  701  
  702            *  
  703            *  
  704            *  @param vi staResult
  705            *  @return
  706            *  @throws M ethodExcep tion
  707            * /
  708           pu blic stati c Patholog yCaseUpdat eAttribute Result tra nslateCase LockResult (String vi staResult)
  709           th rows Metho dException
  710           {
  711                    if(v istaResult .startsWit h("-2"))
  712                    {
  713                             String  errorMsg  = StringUt ils.MagPie ce(vistaRe sult, Stri ngUtils.CA RET, 3);
  714                             return  Pathology CaseUpdate AttributeR esult.crea teFailedLo ckResult(e rrorMsg);
  715                    }
  716                    else  if(vistaR esult.star tsWith("-" ))
  717                    {
  718                             String  errorMsg  = StringUt ils.MagPie ce(vistaRe sult, Stri ngUtils.CA RET, 3);
  719                             throw  new Method Exception( "Error loc king/unloc king case:  " + error Msg);
  720                    }
  721                    else
  722                    {
  723                             String  lockStatu sCode = St ringUtils. MagPiece(v istaResult , StringUt ils.CARET,  2);
  724                             logger .info("Loc k caseresu lt has sta tus [" + l ockStatusC ode + "]") ;
  725                             Transa ctionConte xtFactory. get().addD ebugInform ation("Loc k case res ult has st atus [" +  lockStatus Code + "]" );
  726                             return  Pathology CaseUpdate AttributeR esult.crea teSuccessf ulLockResu lt();
  727                    }        
  728           }
  729           
  730           /* *
  731            *  
  732            *  
  733                    0^0^ Reservatio n ended
  734                    0^1^ Case reser ved
  735                    -1^^ ERROR: [MU MPS error]
  736                    -2^^ ERROR: AP  subsection  not speci fied
  737                    -3^^ ERROR: Yea r not spec ified
  738                    -4^^ ERROR: Acc ession ind ex not spe cified
  739                    -5^^ ERROR: Inv alid conte xt - ...
  740                    -6^^ ERROR: No  accession  code for t his case
  741                    -7^^ ERROR: Upd ate error  - ...
  742            *  
  743            *  
  744            *  @param vi staResult
  745            *  @return
  746            * /
  747           pu blic stati c Patholog yCaseReser veResult t ranslateCa seReserveR esult(Stri ng vistaRe sult)
  748           th rows Metho dException
  749           {
  750                    Stri ng [] piec es = Strin gUtils.Spl it(vistaRe sult, Stri ngUtils.CA RET);
  751                    Stri ng code =  pieces[0]. trim();
  752                    Stri ng success Code = pie ces[1].tri m();
  753                    Stri ng msg = p ieces[2].t rim();
  754                    if(c ode.starts With("-"))
  755                    {
  756                             throw  new Method Exception( msg);
  757                    }
  758  
  759                    if(" 0".equals( successCod e))
  760                             return  Pathology CaseReserv eResult.re servation_ ended;
  761                    if(" 1".equals( successCod e))
  762                             return  Pathology CaseReserv eResult.ca se_reserve d;
  763                    thro w new Meth odExceptio n("Unknown  code retu rned from  VistA, " +  vistaResu lt);
  764           }
  765           
  766           pu blic stati c List<Abs tractPatho logySite>  translateP athologySi tes(String  vistaResu lt, boolea n reading)
  767           th rows Metho dException
  768           {
  769                    List <AbstractP athologySi te> result  = new Arr ayList<Abs tractPatho logySite>( );
  770                    if(v istaResult  == null)
  771                             return  result;
  772                    Stri ng [] line s = String Utils.Spli t(vistaRes ult, Strin gUtils.NEW _LINE);
  773                    if(l ines.lengt h == 0)
  774                             return  result;
  775                    if(l ines[0].st artsWith(" 1"))
  776                    {
  777                             for(in t i = 1; i  < lines.l ength; i++ )
  778                             {
  779                                      String [ ] pieces =  StringUti ls.Split(l ines[i].tr im(), Stri ngUtils.CA RET);
  780                                      String a ctive = pi eces[0];
  781                                      //String  siteIen =  pieces[1] ;
  782                                      String s iteStation Number = p ieces[2];
  783                                      String s iteAbbr =  pieces[3];
  784                                      String s iteName =  pieces[4];
  785                                      if(readi ng)
  786                                      {
  787                                               String rea dingSiteTy pe = piece s[5];
  788                                               result.add (new Patho logyReadin gSite(site StationNum ber, siteN ame, siteA bbr, 
  789                                                                ("0" .equals(ac tive) ? fa lse : true ),
  790                                                                Path ologyReadi ngSiteType .getFromVa lue(readin gSiteType) ));
  791                                      }
  792                                      else
  793                                      {
  794                                               //String p rimarySite Ien = piec es[5];
  795                                               String pri marySiteSt ationNumbe r = pieces [6];
  796                                               String pri marySiteAb br = piece s[7];
  797                                               String pri marySiteNa me = piece s[8];
  798                                               result.add (new Patho logyAcquis itionSite( siteStatio nNumber, s iteName, s iteAbbr,
  799                                                                ("0" .equals(ac tive) ? fa lse : true ),
  800                                                                prim arySiteSta tionNumber , primaryS iteName, p rimarySite Abbr));
  801                                      }
  802                             }
  803                    }
  804                    else
  805                    {
  806                             throw  new Method Exception( "Exception  retrievin g patholog y sites, "  + lines[0 ]);
  807                    }
  808                    
  809                    retu rn result;
  810           }
  811           /* *
  812            L ine 0: 1^N umber of L ines^IEN^T ype^Reserv ation Date ^Interpret ing Statio n^Parent I nterpretat ion Index^ Status (Su ccess) 0^0 ^Error mes sage (Fail ure)
  813            L ine n: IEN ^Type^Rese rvation Da te^Interpr eting Stat ion^Parent  Interpret ation Inde x^Status
  814            
  815            1 ^2^Consult  IEN^Type^ Reservatio n Date^Int erpreting  Station^Si te Abbrevi ation^Stat us
  816   18^INTERPR ETATION^05 /17/2012 1 0:40:20^66 0^SLC^PEND ING
  817   19^CONSULT ATION^05/1 7/2012 10: 40:20^688^ WAS^PENDIN G
  818            
  819            *  @param vi staResult
  820            *  @return
  821            * /
  822           pu blic stati c List<Pat hologyCase Consultati on> transl ateConsult ations(Pat hologyCase URN pathol ogyCaseUrn ,
  823                             String  vistaResu lt)
  824           th rows Metho dException
  825           {
  826                    List <Pathology CaseConsul tation> re sult = new  ArrayList <Pathology CaseConsul tation>();
  827                    
  828                    Stri ng [] line s = String Utils.Spli t(vistaRes ult, Strin gUtils.NEW _LINE);
  829                    for( int i = 1;  i < lines .length; i ++)
  830                    {
  831                             String  [] pieces  = StringU tils.Split (lines[i]. trim(), St ringUtils. CARET);
  832                             String  ien = pie ces[0];
  833                             String  consultat ionType =  pieces[1];
  834                             String  reservati onDateStri ng = piece s[2];
  835                             String  interpret ingStation  = pieces[ 3];
  836                             String  siteAbbr  = pieces[4 ];
  837                             String  status =  pieces[5];
  838                             
  839                             try
  840                             {
  841                                      Patholog yCaseConsu ltationURN  pathology CaseConsul tationUrn 
  842                                               PathologyC aseConsult ationURN.c reate(ien,  pathology CaseUrn);
  843                                      Date res ervationDa te = parse DateString (reservati onDateStri ng);
  844                                      
  845                                      result.a dd(new Pat hologyCase Consultati on(patholo gyCaseCons ultationUr n, consult ationType,  
  846                                                       re servationD ate, inter pretingSta tion, site Abbr, stat us));
  847                             } 
  848                             catch  (URNFormat Exception  e)
  849                             {
  850                                      throw ne w MethodEx ception(e) ;
  851                             }        
  852                    }
  853                    
  854                    retu rn result;
  855           }
  856           
  857           pu blic stati c List<Pat hologyCase Specimen>  translateS pecimens(S tring vist aResult)
  858           {
  859                    List <Pathology CaseSpecim en> result  = new Arr ayList<Pat hologyCase Specimen>( );
  860                    if(v istaResult  == null)
  861                             return  result;
  862                    Stri ng [] line s = String Utils.Spli t(vistaRes ult, Strin gUtils.NEW _LINE);
  863                    for( int i = 1;  i < lines .length; i ++)
  864                    {
  865                             result .add(trans latePathol ogyCaseSpe cimen(line s[i]));
  866                    }
  867                    retu rn result;
  868           }
  869           
  870           pr ivate stat ic Patholo gyCaseSpec imen trans latePathol ogyCaseSpe cimen(Stri ng line)
  871           {
  872                    Stri ng [] piec es = Strin gUtils.Spl it(line, S tringUtils .CARET);
  873                    Stri ng specime n = pieces [0];
  874                    Stri ng smear =  null;
  875                    Stri ng stainPr ocedure =  null;
  876                    int  numSlides  = 0;
  877                    Stri ng lastSta inDateStri ng = null;
  878                    if(p ieces.leng th > 4)
  879                    {
  880                             smear  = pieces[1 ];
  881                             stainP rocedure =  pieces[2] ;
  882                             if(pie ces[3] !=  null && pi eces[3].le ngth() > 0 )
  883                                      numSlide s = Intege r.parseInt (pieces[3] );
  884                    }
  885                    if ( pieces.len gth >= 5)
  886                    {
  887                             lastSt ainDateStr ing = piec es[4];
  888                    }
  889                    
  890                    Path ologyCaseS pecimen re sult = new  Pathology CaseSpecim en(specime n);
  891                    resu lt.setStai n(stainPro cedure);
  892                    resu lt.setNumS lides(numS lides);
  893                    resu lt.setSmea rPrep(smea r);
  894                    if(l astStainDa teString ! = null &&  lastStainD ateString. length() >  0)
  895                    {
  896                             //03/0 2/2012 12: 13
  897                             Date l astStainDa te = parse DateString (lastStain DateString );
  898                             if(las tStainDate  != null)
  899                                      result.s etLastStai nDate(last StainDate) ;
  900                    }
  901                    
  902                    retu rn result;
  903           }
  904           
  905           /*
  906           pu blic stati c List<Pat hologySlid e> transla teSlidesRe sult(Strin g vistaRes ult)
  907           {                 
  908                    List <Pathology Slide> res ult = new  ArrayList< PathologyS lide>();
  909                    if(v istaResult  == null)
  910                             return  result;
  911                    Stri ng [] line s = String Utils.Spli t(vistaRes ult, Strin gUtils.NEW _LINE);
  912                    for( int i = 1;  i < lines .length; i ++)
  913                    {
  914                             result .add(trans latePathol ogySlide(l ines[i]));
  915                    }
  916                    retu rn result;
  917           }* /
  918           
  919           /* *
  920            *  
  921            *  
  922            *  @param li ne
  923            *  @return
  924            * /
  925           /*
  926           pr ivate stat ic Patholo gySlide tr anslatePat hologySlid e(String l ine)
  927           {
  928                    Stri ng [] piec es = Strin gUtils.Spl it(line, S tringUtils .CARET);
  929                    Stri ng specime n = pieces [0];
  930                    Stri ng stainTy pe = null;
  931                    Stri ng tissueS ampleSite  = null;
  932                    Stri ng slideNu mber = nul l;
  933                    Stri ng studyDa te = null;
  934                    if(p ieces.leng th > 4)
  935                    {
  936                             stainT ype = piec es[1];
  937                             tissue SampleSite  = pieces[ 2];
  938                             slideN umber = pi eces[3];
  939                    }
  940                    if ( pieces.len gth >= 5)
  941                    {
  942                             studyD ate = piec es[4];
  943                    }
  944                    
  945                    Path ologySlide  result =  new Pathol ogySlide() ;
  946                    resu lt.setSpec imen(speci men);
  947                    resu lt.setStai nType(stai nType);
  948                    resu lt.setTiss ueSampleSi te(tissueS ampleSite) ;
  949                    resu lt.setSlid eNumber(sl ideNumber) ;
  950                    resu lt.setStud yDate(stud yDate);
  951                    retu rn result;
  952           }* /
  953           
  954           /* *
  955            *  
  956            *  @param vi staResult
  957            *  @return
  958            * /
  959           
  960           pu blic stati c List<Pat hologyCase > translat eLabCasesR esult(Site  site, Str ing vistaR esult)
  961           th rows Metho dException
  962           {
  963                    List <Pathology Case> case s = new Ar rayList<Pa thologyCas e>();
  964                    if(v istaResult  == null)
  965                             return  cases;
  966                    
  967                    if(v istaResult .startsWit h("-"))
  968                    {
  969                             String  errorMsg  = StringUt ils.MagPie ce(vistaRe sult, Stri ngUtils.CA RET, 3);
  970                             throw  new Method Exception( errorMsg);
  971                    }                 
  972                    
  973                    Stri ng [] line s = String Utils.Spli t(vistaRes ult, Strin gUtils.NEW _LINE);
  974                    for( int i = 1;  i < lines .length; i ++)
  975                    {
  976                             Pathol ogyCase pa thologyCas e = transl ateLabCase (site, lin es[i]);
  977                             if(pat hologyCase  != null)
  978                                      cases.ad d(patholog yCase);
  979                    }
  980                    retu rn cases;            
  981           }
  982           
  983           /* *
  984            
  985            L ine 0: 1^N umber of l ines^Relea sed Report s/Unreleas ed Reports  (Success)  or 0^0^Er ror messag e (Failure )
  986            L ine 1: "Ca se #~~1^Re served Fla g~~2^Reser ved By~~3^ Patient Na me~~4^Pati ent ID #~~ 5^Priority ~~6^Slide  Available~ ~7^Specime n Taken Da te/Time~~8 ^Status~~9 ^Site~~10^ AP Section ~~11^Year~ ~12^Access ion Number ~~13^ICN~~ 14"
  987            
  988            C Y 11 4^0^^ PATIENT,ON EZEROSEVEN TWO^1072^R OUTINE^NO^ 05/10/2011  14:27^In  Progress^W AS^CY^11^4 ^911234567 8V505029
  989            
  990            C Y 12 3^0^^ PATIENT,ON EZEROZEROS IX^1006^RO UTINE^NO^0 8/09/2012  12:00:22^R eleased^WA S^CY^12^3^ 9312457789 V212714^1^ ^P1006
  991  
  992            *  @param la bCaseLine
  993            *  @return
  994            * /
  995           pr ivate stat ic Patholo gyCase tra nslateLabC ase(Site s ite, Strin g labCaseL ine)
  996           th rows Metho dException
  997           {
  998                    Stri ng [] barP ieces = St ringUtils. Split(labC aseLine.tr im(), Stri ngUtils.ST ICK);
  999                    
  1000                    Stri ng [] piec es = Strin gUtils.Spl it(barPiec es[0].trim (), String Utils.CARE T);
  1001                    Stri ng accessi onNumber =  pieces[0] ;
  1002                    int  reserved =  Integer.p arseInt(pi eces[1]);
  1003                    Stri ng reserve dBy = piec es[2];
  1004                    Stri ng patient Name = pie ces[3];
  1005                    Stri ng patient Dfn = piec es[4];
  1006                    Stri ng priorit y = pieces [5];
  1007                    Stri ng slidesA vailableSt ring = pie ces[6];
  1008                    Stri ng specimi nTakenDate String = p ieces[7];
  1009                    Stri ng status  = pieces[8 ];
  1010                    Stri ng siteAbb r = pieces [9];
  1011                    Stri ng apSecti on = piece s[10];
  1012                    Stri ng year =  pieces[11] ;
  1013                    Stri ng number  = pieces[1 2];
  1014                    Stri ng patient Icn = piec es[13];
  1015                    int  speciminCo unt = Inte ger.parseI nt(pieces[ 14]);
  1016                    Stri ng method  = pieces[1 5];
  1017                    Stri ng patient Ssn = piec es[16];
  1018                    Stri ng noteAtt achedStrin g = pieces [17];
  1019                    Stri ng isSensi tive = "0" ;
  1020                    int  numberOfIm ages = 0;
  1021                    if(p ieces.leng th >= 19)
  1022                             isSens itive = pi eces[18];
  1023                    if(p ieces.leng th >= 20)
  1024                    {
  1025                             String  numberOfI magesStrin g = pieces [19];
  1026                             if(num berOfImage sString !=  null && n umberOfIma gesString. length() >  0)
  1027                             {
  1028                                      try
  1029                                      {
  1030                                               numberOfIm ages = Int eger.parse Int(number OfImagesSt ring);
  1031                                      }
  1032                                      catch(Ex ception ex )
  1033                                      {
  1034                                               logger.war n("Error p arsing num ber of ima ges string  [" + numb erOfImages String + " ], " + ex. getMessage ());
  1035                                      }
  1036                             }
  1037                    }
  1038                    
  1039                    Pati entIdentif ier patien tIdentifie r = null;
  1040                    
  1041                    if(p atientIcn  == null ||  patientIc n.startsWi th("-1"))
  1042                    {
  1043                             //logg er.warn("E xcluding P athologyCa se '" + ac cessionNum ber + "' b ecause pat ient does  not have a n ICN.");
  1044                             //Tran sactionCon textFactor y.get().ad dDebugInfo rmation("E xcluding P athologyCa se '" + ac cessionNum ber + "' b ecause pat ient does  not have a n ICN.");                          
  1045                             //retu rn null;
  1046                             patien tIdentifie r = new Pa tientIdent ifier(pati entDfn, Pa tientIdent ifierType. dfn);
  1047                    }
  1048                    else
  1049                    {
  1050                             patien tIdentifie r = new Pa tientIdent ifier(pati entIcn, Pa tientIdent ifierType. icn);
  1051                    }
  1052                    
  1053                    Date  speciminT akenDate =  parseDate String(spe ciminTaken DateString );
  1054                    bool ean slides Available  = "YES".eq uals(slide sAvailable String);
  1055                    bool ean noteAt tached = " YES".equal s(noteAtta chedString );
  1056                                                       
  1057                    try
  1058                    {
  1059                             
  1060                             boolea n patientS ensitive =  "1".equal s(isSensit ive); // s ensitive v alue 1
  1061                             Pathol ogyCaseURN  pathology CaseUrn =  PathologyC aseURN.cre ate(site.g etSiteNumb er(), apSe ction, yea r, number,  patientId entifier);
  1062                             
  1063                             return  new Patho logyCase(p athologyCa seUrn, acc essionNumb er, reserv ed, reserv edBy, pati entName, 
  1064                                               patientIde ntifier, p riority, s lidesAvail able, spec iminTakenD ate, 
  1065                                               status, si teAbbr, sp eciminCoun t, patient Ssn, metho d, noteAtt ached,
  1066                                               patientSen sitive, nu mberOfImag es);
  1067                    }
  1068                    catc h(URNForma tException  urnfX)
  1069                    {
  1070                             throw  new Method Exception( urnfX);
  1071                    }
  1072                    
  1073                    
  1074           }
  1075           
  1076           /* *
  1077            *  Parse a d ate, publi c for unit  testing p urposes
  1078            *  @param da teString
  1079            *  @return
  1080            * /
  1081           pr ivate stat ic Date pa rseDateStr ing(String  dateStrin g)
  1082           {
  1083                    try
  1084                    {
  1085                             if(dat eString.le ngth() ==  10)
  1086                             {
  1087                                      // 03/02 /2012
  1088                                      SimpleDa teFormat s df = new S impleDateF ormat("MM/ dd/yyyy");
  1089                                      return s df.parse(d ateString) ;
  1090                             }
  1091                             else i f(dateStri ng.length( ) == 16)
  1092                             {
  1093                                      //05/10/ 2012 14:18
  1094                                      SimpleDa teFormat s df = new S impleDateF ormat("MM/ dd/yyyy kk :mm");
  1095                                      return s df.parse(d ateString) ;
  1096                             }
  1097                             else i f(dateStri ng.length( ) == 19)
  1098                             {
  1099                                      //08/09/ 2012 12:00 :22
  1100                                      SimpleDa teFormat s df = new S impleDateF ormat("MM/ dd/yyyy kk :mm:ss");
  1101                                      return s df.parse(d ateString) ;
  1102                             }
  1103                             else
  1104                             {
  1105                                      logger.w arn("Canno t parse da te '" + da teString +  "'.");
  1106                             }
  1107                    }
  1108                    catc h(ParseExc eption pX)
  1109                    {
  1110                             logger .error("Er ror parsin g date '"  + dateStri ng + "', "  + pX.getM essage());
  1111                    }
  1112                    retu rn null;
  1113           }
  1114  
  1115           /* *
  1116            
  1117                    -6^^ Study cont ext not fo und
  1118                    -5^^ No Input
  1119                    -4^^ One or mor e input pa rameters a re missing
  1120                    -3^^ [fldnum]:  Invalid Fi eld Number
  1121                    -2^^ [fldnam] –  Updating  Error: [Fi leman erro r descript ion]
  1122                    -1^^ ERROR [MUM PS error]
  1123                    0
  1124                    1^^[ alert mess age text i ff report  was releas ed]  
  1125            
  1126            *  @param vi staResult
  1127            *  @return
  1128            *  @throws M ethodExcep tion
  1129            * /
  1130           pu blic stati c Patholog ySaveCaseR eportResul t translat eSavingCas eReportFie lds(String  vistaResu lt)
  1131           th rows Metho dException
  1132           {
  1133                    if(v istaResult .startsWit h("-"))
  1134                    {
  1135                             String  errorMsg  = StringUt ils.MagPie ce(vistaRe sult, Stri ngUtils.CA RET, 3);
  1136                             throw  new Method Exception( "Error sav ing case r eport fiel ds: " + er rorMsg);
  1137                    }
  1138                    else  if(vistaR esult.star tsWith("1" ))
  1139                    {
  1140                             String  warningMs g = String Utils.MagP iece(vista Result, St ringUtils. CARET, 3);
  1141                             return  Pathology SaveCaseRe portResult .createRel easedResul t(warningM sg);
  1142                    }
  1143                    retu rn Patholo gySaveCase ReportResu lt.createU nreleasedR esult();
  1144           }
  1145           
  1146   }